diff --git a/pyproject.toml b/pyproject.toml index cd3dd07..ed55801 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,8 +74,7 @@ zampy="zampy.cli:run_recipe" dev = [ "bump2version", "hatch", - "ruff", - "black", + "ruff>0.1.2", # Ruff with formatter is required "mypy", "types-requests", # type stubs for request lib "types-urllib3", # type stubs for url lib @@ -100,10 +99,10 @@ features = ["dev"] lint = [ "ruff check src/ tests/", "mypy src/", - "black --check --diff src/ tests/", + "ruff format --check --diff src/ tests/", ] format = [ - "black src/ tests/", + "ruff format src/ tests/", "ruff check src/ tests/ --fix --exit-non-zero-on-fix", "lint", ] @@ -127,11 +126,6 @@ ignore_missing_imports = true disallow_untyped_defs = true python_version = "3.10" -[tool.black] -line-length = 88 -target-version = ['py310', 'py311'] -include = '\.pyi?$' - [tool.ruff] select = [ "E", # pycodestyle diff --git a/src/zampy/datasets/cds_utils.py b/src/zampy/datasets/cds_utils.py index 0f267b9..4eade9e 100644 --- a/src/zampy/datasets/cds_utils.py +++ b/src/zampy/datasets/cds_utils.py @@ -30,6 +30,20 @@ } CONFIG_PATH = Path.home() / ".config" / "zampy" / "zampy_config.yml" +ALL_DAYS = [ + "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", + "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", + "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", + "31", +] # fmt: skip + +ALL_HOURS = [ + "00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", + "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", + "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", + "21:00", "22:00", "23:00", +] # fmt: skip + def cds_request( dataset: str, @@ -223,20 +237,8 @@ def retrieve_era5( "variable": [cds_var_names[variable]], "year": year, "month": month, - # fmt: off - "day": [ - "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", - "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", - "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", - "31", - ], - "time": [ - "00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", - "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", - "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", - "21:00", "22:00", "23:00", - ], - # fmt: on + "day": ALL_DAYS, + "time": ALL_HOURS, "area": [ spatial_bounds.north, spatial_bounds.west, diff --git a/tests/test_cds_utils.py b/tests/test_cds_utils.py index c70f805..2fd5e2c 100644 --- a/tests/test_cds_utils.py +++ b/tests/test_cds_utils.py @@ -5,6 +5,8 @@ import numpy as np import pytest import xarray as xr +from test_datasets import ALL_DAYS +from test_datasets import ALL_HOURS from test_datasets import data_folder from zampy.datasets import cds_utils from zampy.datasets.dataset_protocol import SpatialBounds @@ -54,20 +56,8 @@ def test_cds_request_era5(mock_retrieve, valid_path_config): "variable": ["10m_u_component_of_wind"], "year": "2010", "month": "1", - # fmt: off - "day": [ - "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", - "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", - "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", - "31", - ], - "time": [ - "00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", - "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", - "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", - "21:00", "22:00", "23:00", - ], - # fmt: on + "day": ALL_DAYS, + "time": ALL_HOURS, "area": [ spatial_bounds.north, spatial_bounds.west, diff --git a/tests/test_datasets/__init__.py b/tests/test_datasets/__init__.py index f000199..ccb1f08 100644 --- a/tests/test_datasets/__init__.py +++ b/tests/test_datasets/__init__.py @@ -4,3 +4,18 @@ test_folder = Path(__file__).resolve().parents[1] data_folder = test_folder / "test_data" + + +ALL_DAYS = [ + "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", + "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", + "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", + "31", +] # fmt: skip + +ALL_HOURS = [ + "00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", + "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", + "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", + "21:00", "22:00", "23:00", +] # fmt: skip diff --git a/tests/test_datasets/test_era5.py b/tests/test_datasets/test_era5.py index 3b6cc1c..7e9945e 100644 --- a/tests/test_datasets/test_era5.py +++ b/tests/test_datasets/test_era5.py @@ -9,6 +9,8 @@ from zampy.datasets.catalog import ERA5 from zampy.datasets.dataset_protocol import SpatialBounds from zampy.datasets.dataset_protocol import TimeBounds +from . import ALL_DAYS +from . import ALL_HOURS from . import data_folder @@ -63,18 +65,8 @@ def test_download(self, mock_retrieve, valid_path_config, dummy_dir): "year": "2010", "month": "1", # fmt: off - "day": [ - "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", - "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", - "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", - "31", - ], - "time": [ - "00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", - "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", - "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", - "21:00", "22:00", "23:00", - ], + "day": ALL_DAYS, + "time": ALL_HOURS, # fmt: on "area": [ bbox.north, diff --git a/tests/test_datasets/test_era5_land.py b/tests/test_datasets/test_era5_land.py index 8305697..74376c0 100644 --- a/tests/test_datasets/test_era5_land.py +++ b/tests/test_datasets/test_era5_land.py @@ -9,6 +9,8 @@ from zampy.datasets.catalog import ERA5Land from zampy.datasets.dataset_protocol import SpatialBounds from zampy.datasets.dataset_protocol import TimeBounds +from . import ALL_DAYS +from . import ALL_HOURS from . import data_folder @@ -62,20 +64,8 @@ def test_download(self, mock_retrieve, valid_path_config, dummy_dir): "variable": cds_var_names, "year": "2010", "month": "1", - # fmt: off - "day": [ - "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", - "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", - "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", - "31", - ], - "time": [ - "00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", - "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", - "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", - "21:00", "22:00", "23:00", - ], - # fmt: on + "day": ALL_DAYS, + "time": ALL_HOURS, "area": [ bbox.north, bbox.west, diff --git a/tests/test_recipes/test_simple_recipe.py b/tests/test_recipes/test_simple_recipe.py index 3fb7800..536422f 100644 --- a/tests/test_recipes/test_simple_recipe.py +++ b/tests/test_recipes/test_simple_recipe.py @@ -17,7 +17,9 @@ def test_recipe(tmp_path: Path, mocker): - with (patch.object(DATASETS["era5"], "download"),): + with ( + patch.object(DATASETS["era5"], "download"), + ): mocker.patch( "zampy.recipe.config_loader", return_value={"working_directory": str(tmp_path.absolute())},