Skip to content

Commit

Permalink
Merge pull request #591 from ungarj/pydantic2_scarto
Browse files Browse the repository at this point in the history
pydantic 2.3.0
  • Loading branch information
ungarj authored Sep 19, 2023
2 parents 2c316c7 + 2e9c7e9 commit ffdc8d2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
36 changes: 18 additions & 18 deletions mapchete/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import fsspec
import oyaml as yaml
from pydantic import BaseModel, NonNegativeInt, validator
from pydantic import BaseModel, NonNegativeInt, field_validator
from shapely import wkt
from shapely.geometry import Point, box, shape
from shapely.geometry.base import BaseGeometry
Expand Down Expand Up @@ -57,7 +57,7 @@ class OutputConfigBase(BaseModel):
metatiling: Union[int, None] = 1
pixelbuffer: Union[NonNegativeInt, None] = 0

@validator("metatiling", always=True)
@field_validator("metatiling", mode='before')
def _metatiling(cls, value: int) -> int: # pragma: no cover
_metatiling_opts = [2**x for x in range(10)]
if value not in _metatiling_opts:
Expand All @@ -70,7 +70,7 @@ class PyramidConfig(BaseModel):
metatiling: Union[int, None] = 1
pixelbuffer: Union[NonNegativeInt, None] = 0

@validator("metatiling", always=True)
@field_validator("metatiling", mode='before')
def _metatiling(cls, value: int) -> int: # pragma: no cover
_metatiling_opts = [2**x for x in range(10)]
if value not in _metatiling_opts:
Expand All @@ -81,20 +81,20 @@ def _metatiling(cls, value: int) -> int: # pragma: no cover
class ProcessConfig(BaseModel, arbitrary_types_allowed=True):
pyramid: PyramidConfig
output: dict
zoom_levels: Union[dict, int, list]
process: Union[str, MPath, List[str], None]
baselevels: Union[dict, None]
input: Union[dict, None]
config_dir: Union[str, MPath, None]
area: Union[str, MPath, BaseGeometry, None]
area_crs: Union[dict, str, None]
bounds: Union[Tuple[float, float, float, float], None]
bounds_crs: Union[dict, str, None]
process_parameters: Union[dict, None]
mapchete_file: Union[str, MPath, None]
zoom_levels: Union[ZoomLevels, dict, list, int]
process: Union[str, MPath, List[str], None] = None
baselevels: Union[dict, None] = None
input: Union[dict, None] = None
config_dir: Union[str, MPath, None] = None
area: Union[str, MPath, BaseGeometry, None] = None
area_crs: Union[dict, str, None] = None
bounds: Union[Bounds, Tuple[float, float, float, float], None] = None
bounds_crs: Union[dict, str, None] = None
process_parameters: Union[dict, None] = None
mapchete_file: Union[str, MPath, None] = None


_RESERVED_PARAMETERS = tuple(ProcessConfig.__fields__.keys())
_RESERVED_PARAMETERS = tuple(ProcessConfig.model_fields.keys())

# TODO remove these
# parameters for output configuration
Expand Down Expand Up @@ -287,7 +287,7 @@ def __init__(
logger.debug(f"parsing {input_config}")
try:
self.parsed_config = parse_config(input_config, strict=stric_parsing)
self.parsed_config.dict()
self.parsed_config.model_dump()
except Exception as exc:
raise MapcheteConfigError(exc)
self._init_zoom_levels = zoom
Expand Down Expand Up @@ -334,7 +334,7 @@ def __init__(
# these two BufferedTilePyramid instances will help us with all
# the tile geometries etc.
self.process_pyramid = BufferedTilePyramid(
**self.parsed_config.pyramid.dict()
**dict(self.parsed_config.pyramid)
)
self.output_pyramid = BufferedTilePyramid(
self.parsed_config.pyramid.grid,
Expand Down Expand Up @@ -1231,7 +1231,7 @@ def _raw_at_zoom(config, zooms):
params_per_zoom = OrderedDict()
for zoom in zooms:
params = OrderedDict()
for name, element in config.dict().items():
for name, element in config.model_dump().items():
out_element = _element_at_zoom(name, element, zoom)
if out_element is not None:
params[name] = out_element
Expand Down
4 changes: 2 additions & 2 deletions mapchete/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __geo_interface__(self):

def _set_attributes(self, left, bottom, right, top):
"""This method is important when Bounds instances are passed on to the ProcessConfig schema."""
if hasattr(left, "__iter__"):
if hasattr(left, "__iter__"): # pragma: no cover
self.left, self.bottom, self.right, self.top = [i for i in left]
else:
self.left, self.bottom, self.right, self.top = left, bottom, right, top
Expand Down Expand Up @@ -194,7 +194,7 @@ def __contains__(self, value):

def _set_attributes(self, minlevel, maxlevel):
"""This method is important when ZoomLevel instances are passed on to the ProcessConfig schema."""
if hasattr(minlevel, "__iter__"):
if hasattr(minlevel, "__iter__"): # pragma: no cover
zoom_list = [i for i in minlevel]
self.min = min(zoom_list)
self.max = max(zoom_list)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies = [
"importlib-resources",
"numpy>=1.16",
"oyaml",
"pydantic<2.0.0",
"pydantic>=2.3.0",
"pyproj",
"python-dateutil",
"rasterio>1.2.10",
Expand Down
4 changes: 2 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ black
coveralls
flake8
minio
morecantile<5.0.0
morecantile>=5.0.0
pre-commit
pytest
pytest-cov
pytest-flask
pytest-lazy-fixture
rio-cogeo
rio-cogeo>=5.0.0
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ matplotlib>=3.2.1
numpy>=1.16
oyaml>=0.9
pyproj
pydantic<2.0.0
pydantic>=2.3.0
retry>=0.9.2
rasterio>1.2.10
s3fs<2023.9.0
Expand Down
4 changes: 2 additions & 2 deletions test/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ coverage>=5.1
coveralls>=2.2.0
flake8>=3.8.4
minio
morecantile<5.0.0
morecantile>=5.0.0
pystac
pytest>=5.4.1
pytest-cov>=2.8.1
pytest-env
pytest-flask>=1.0.0
pytest-lazy-fixture>=0.6.3
rio-cogeo>=1.1.10
rio-cogeo>=5.0.0

0 comments on commit ffdc8d2

Please sign in to comment.