Skip to content

Commit

Permalink
Remove black, switch to ruff for formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
BSchilperoort committed Feb 1, 2024
1 parent 2580e40 commit 3b365b5
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 64 deletions.
12 changes: 3 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
]
Expand All @@ -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
Expand Down
30 changes: 16 additions & 14 deletions src/zampy/datasets/cds_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 4 additions & 14 deletions tests/test_cds_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions tests/test_datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 4 additions & 12 deletions tests/test_datasets/test_era5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand Down
18 changes: 4 additions & 14 deletions tests/test_datasets/test_era5_land.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion tests/test_recipes/test_simple_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())},
Expand Down

0 comments on commit 3b365b5

Please sign in to comment.