Skip to content

Commit

Permalink
Merge pull request #24 from pahrohfit/pydantic_2_support
Browse files Browse the repository at this point in the history
Pydantic 2 support
  • Loading branch information
folt authored Jul 13, 2023
2 parents 84c02c2 + 5e66196 commit 8b05b52
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 62 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ Aliaksandr Vaskevich <[email protected]>
Contributors
------------
Jeoffrey Jardin <[email protected]>
Rob Dailey <[email protected]>
37 changes: 17 additions & 20 deletions pydantic_geojson/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,27 @@
from .point import PointModel
from .polygon import PolygonModel

__author__ = 'Aliaksandr Vaskevich'
__author__ = "Aliaksandr Vaskevich"
__maintainer__ = __author__

__email__ = '[email protected]'
__license__ = 'MIT'
__email__ = "[email protected]"
__license__ = "MIT"

__all__ = [
'__author__',
'__email__',
'__license__',
'__maintainer__',

"__author__",
"__email__",
"__license__",
"__maintainer__",
# object type
'GeometryType',

"GeometryType",
# models
'PointModel',
'MultiPointModel',
'LineStringModel',
'MultiLineStringModel',
'PolygonModel',
'MultiPolygonModel',
'GeometryCollectionModel',
'FeatureModel',
'FeatureCollectionModel',

"PointModel",
"MultiPointModel",
"LineStringModel",
"MultiLineStringModel",
"PolygonModel",
"MultiPolygonModel",
"GeometryCollectionModel",
"FeatureModel",
"FeatureCollectionModel",
]
31 changes: 11 additions & 20 deletions pydantic_geojson/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
LonField = Annotated[
Union[float, int],
Field(
title='Coordinate longitude',
title="Coordinate longitude",
ge=-180,
le=180,
),
Expand All @@ -27,64 +27,55 @@
LatField = Annotated[
Union[float, int],
Field(
title='Coordinate latitude',
title="Coordinate latitude",
ge=-90,
le=90,
),
]

PointFieldType = Field(
POINT,
const=True,
title='Point',
title="Point",
)

MultiPointFieldType = Field(
MULTI_POINT,
const=True,
title='Multi Point',
title="Multi Point",
)

LineStringFieldType = Field(
LINE_STRING,
const=True,
title='LineS String',
title="LineS String",
)

MultiLineStringFieldType = Field(
MULTI_LINE_STRING,
const=True,
title='Multi Line String',
title="Multi Line String",
)

PolygonFieldType = Field(
POLYGON,
const=True,
title='Polygon',
title="Polygon",
)

MultiPolygonFieldType = Field(
MULTI_POLYGON,
const=True,
title='Multi Polygon',
title="Multi Polygon",
)

GeometryCollectionFieldType = Field(
GEOMETRY_COLLECTION,
const=True,
title='Geometry Collection',
title="Geometry Collection",
)

FeatureFieldType = Field(
FEATURE,
const=True,
title='Feature',
title="Feature",
)

FeatureCollectionFieldType = Field(
FEATURE_COLLECTION,
const=True,
title='Feature Collection',
title="Feature Collection",
)


Expand Down
4 changes: 1 addition & 3 deletions pydantic_geojson/multi_line_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@

class MultiLineStringModel(BaseModel):
type: str = MultiLineStringFieldType
coordinates: List[
List[Coordinates]
]
coordinates: List[List[Coordinates]]
6 changes: 1 addition & 5 deletions pydantic_geojson/multi_polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,4 @@

class MultiPolygonModel(BaseModel):
type: str = MultiPolygonFieldType
coordinates: List[
List[
List[Coordinates]
]
]
coordinates: List[List[List[Coordinates]]]
19 changes: 10 additions & 9 deletions pydantic_geojson/object_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
https://www.rfc-editor.org/rfc/rfc7946.html#section-1.4
"""

POINT = 'Point'
MULTI_POINT = 'MultiPoint'
LINE_STRING = 'LineString'
MULTI_LINE_STRING = 'MultiLineString'
POLYGON = 'Polygon'
MULTI_POLYGON = 'MultiPolygon'
GEOMETRY_COLLECTION = 'GeometryCollection'
POINT = "Point"
MULTI_POINT = "MultiPoint"
LINE_STRING = "LineString"
MULTI_LINE_STRING = "MultiLineString"
POLYGON = "Polygon"
MULTI_POLYGON = "MultiPolygon"
GEOMETRY_COLLECTION = "GeometryCollection"


class GeometryType(str, Enum):
Expand All @@ -20,6 +20,7 @@ class GeometryType(str, Enum):
"MultiLineString", "Polygon", "MultiPolygon", and
"GeometryCollection".
"""

point = POINT
multi_point = MULTI_POINT
line_string = LINE_STRING
Expand All @@ -29,5 +30,5 @@ class GeometryType(str, Enum):
geometry_collection = GEOMETRY_COLLECTION


FEATURE = 'Feature'
FEATURE_COLLECTION = 'FeatureCollection'
FEATURE = "Feature"
FEATURE_COLLECTION = "FeatureCollection"
4 changes: 1 addition & 3 deletions pydantic_geojson/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@

class PolygonModel(BaseModel):
type: str = PolygonFieldType
coordinates: List[
List[Coordinates]
]
coordinates: List[List[Coordinates]]
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pydantic_geojson"
version = "0.1.0"
version = "0.1.1"
description = "Pydantic validation for GeoJson"
authors = [
"Aliaksandr Vaskevich <[email protected]>",
Expand Down Expand Up @@ -41,13 +41,17 @@ classifiers = [

[tool.poetry.dependencies]
python = "^3.7"
pydantic = "^1.9.0"
pydantic = ">=1.9,<3.0"
mypy = "^1.4.1"

[tool.poetry.dev-dependencies]
isort = "^5.10.1"
pytest = "^7.1.1"
pytest-cov = "^4.0.0"

[tool.poetry.group.dev.dependencies]
bandit = "^1.7.5"

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
Expand Down

0 comments on commit 8b05b52

Please sign in to comment.