diff --git a/mapchete/config.py b/mapchete/config.py index 3976530a..68e4ecb7 100644 --- a/mapchete/config.py +++ b/mapchete/config.py @@ -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 @@ -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: @@ -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: @@ -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 @@ -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 @@ -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, @@ -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 diff --git a/mapchete/types.py b/mapchete/types.py index f825d536..26142cb6 100644 --- a/mapchete/types.py +++ b/mapchete/types.py @@ -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 @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 8a17f153..73dd1c57 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/requirements-dev.txt b/requirements-dev.txt index 27e4aa1b..3f83c4cc 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -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 diff --git a/requirements.txt b/requirements.txt index b25e3e85..a3145290 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/test/requirements.txt b/test/requirements.txt index 252360b3..30d43496 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -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 \ No newline at end of file +rio-cogeo>=5.0.0 \ No newline at end of file