From 4c52f6d65283e45e7ef43acdf8d7498cc0ed2f75 Mon Sep 17 00:00:00 2001 From: Francis Charette Migneault Date: Thu, 25 Apr 2024 12:40:31 -0400 Subject: [PATCH] fix linting --- Makefile | 9 +++++++++ pyproject.toml | 4 ++++ stac_model/base.py | 2 +- tests/conftest.py | 4 ++-- tests/test_schema.py | 18 +++++++++--------- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 3dd26e5..4710486 100644 --- a/Makefile +++ b/Makefile @@ -49,10 +49,19 @@ format: codestyle test: PYTHONPATH=$(PYTHONPATH) poetry run pytest -c pyproject.toml --cov-report=html --cov=stac_model tests/ +.PHONY: check +check: check-examples check-markdown check-lint check-mypy check-safety + +.PHONY: check-all +check-all: check + .PHONY: mypy mypy: poetry run mypy --config-file pyproject.toml ./ +.PHONY: check-mypy +check-mypy: mypy + .PHONY: check-safety check-safety: poetry check diff --git a/pyproject.toml b/pyproject.toml index 6e11424..071ff10 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -178,6 +178,10 @@ select = [ "I", ] +[tool.ruff.lint.isort] +known-local-folder = ["tests", "conftest"] +known-first-party = ["stac_model"] + [tool.mypy] # https://github.com/python/mypy # https://mypy.readthedocs.io/en/latest/config_file.html#using-a-pyproject-toml-file diff --git a/stac_model/base.py b/stac_model/base.py index 96c1d0f..4e8cc6b 100644 --- a/stac_model/base.py +++ b/stac_model/base.py @@ -1,6 +1,6 @@ from dataclasses import dataclass from enum import Enum -from typing import Any, Dict, List, Literal, TypeAlias, TypedDict, Union +from typing import Any, Dict, List, Literal, TypeAlias, Union from pydantic import BaseModel, ConfigDict, model_serializer diff --git a/tests/conftest.py b/tests/conftest.py index 3951a31..75c81b5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -57,10 +57,10 @@ def mlm_validator( @pytest.fixture -def mlm_example(request: "SubRequest") -> JSON: +def mlm_example(request: "SubRequest") -> Dict[str, JSON]: with open(os.path.join(EXAMPLES_DIR, request.param)) as example_file: data = json.load(example_file) - return cast(JSON, data) + return cast(Dict[str, JSON], data) @pytest.fixture(name="eurosat_resnet") diff --git a/tests/test_schema.py b/tests/test_schema.py index 5408378..3b26a3f 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -19,7 +19,7 @@ ) def test_mlm_schema( mlm_validator: STACValidator, - mlm_example: JSON, + mlm_example: Dict[str, JSON], ) -> None: mlm_item = pystac.Item.from_dict(cast(Dict[str, Any], mlm_example)) validated = pystac.validation.validate(mlm_item, validator=mlm_validator) @@ -34,13 +34,13 @@ def test_mlm_schema( ) def test_mlm_eo_bands_invalid_only_in_item_properties( mlm_validator: STACValidator, - mlm_example: JSON, + mlm_example: Dict[str, JSON], ) -> None: mlm_item = pystac.Item.from_dict(mlm_example) pystac.validation.validate(mlm_item, validator=mlm_validator) # ensure original is valid - mlm_eo_bands_bad_data: Dict[str, JSON] = copy.deepcopy(mlm_example) - mlm_eo_bands_bad_data["assets"]["weights"].pop("eo:bands") + mlm_eo_bands_bad_data = copy.deepcopy(mlm_example) + mlm_eo_bands_bad_data["assets"]["weights"].pop("eo:bands") # type: ignore with pytest.raises(pystac.errors.STACValidationError): mlm_eo_bands_bad_item = pystac.Item.from_dict(mlm_eo_bands_bad_data) pystac.validation.validate(mlm_eo_bands_bad_item, validator=mlm_validator) @@ -53,15 +53,15 @@ def test_mlm_eo_bands_invalid_only_in_item_properties( ) def test_mlm_no_input_allowed_but_explicit_empty_array_required( mlm_validator: STACValidator, - mlm_example: JSON, + mlm_example: Dict[str, JSON], ) -> None: mlm_data = copy.deepcopy(mlm_example) - mlm_data["properties"]["mlm:input"] = [] + mlm_data["properties"]["mlm:input"] = [] # type: ignore mlm_item = pystac.Item.from_dict(mlm_data) pystac.validation.validate(mlm_item, validator=mlm_validator) with pytest.raises(pystac.errors.STACValidationError): - mlm_data["properties"].pop("mlm:input") + mlm_data["properties"].pop("mlm:input") # type: ignore mlm_item = pystac.Item.from_dict(mlm_data) pystac.validation.validate(mlm_item, validator=mlm_validator) @@ -85,11 +85,11 @@ def test_validate_model_against_schema(eurosat_resnet, mlm_validator): ["collection.json"], indirect=True, ) -def test_collection_include_all_items(mlm_example: JSON): +def test_collection_include_all_items(mlm_example): """ This is only for self-validation, to make sure all examples are contained in the example STAC collection. """ - col_links: List[JSON] = mlm_example["links"] + col_links: List[Dict[str, str]] = mlm_example["links"] col_items = {os.path.basename(link["href"]) for link in col_links if link["rel"] == "item"} all_items = {os.path.basename(path) for path in get_all_stac_item_examples()} assert all_items == col_items, "Missing STAC Item examples in the example STAC Collection links."