Skip to content

Commit 538686c

Browse files
committed
update pre-commit configuration and add python 3.12 in CI
1 parent c03272e commit 538686c

File tree

8 files changed

+75
-48
lines changed

8 files changed

+75
-48
lines changed

.github/workflows/cicd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
python-version: ["3.8", "3.9", "3.10", "3.11"]
17+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
1818

1919
steps:
2020
- uses: actions/checkout@v4

.pre-commit-config.yaml

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
4+
- repo: https://github.com/abravalheri/validate-pyproject
5+
rev: v0.16
6+
hooks:
7+
- id: validate-pyproject
8+
49
- repo: https://github.com/pre-commit/pre-commit-hooks
510
rev: v4.5.0
611
hooks:
@@ -10,28 +15,25 @@ repos:
1015
- id: check-added-large-files
1116
args: ["--maxkb=40960"]
1217

13-
- repo: local
18+
- repo: https://github.com/PyCQA/isort
19+
rev: 5.13.2
1420
hooks:
15-
- id: black
16-
name: Black Formatting
17-
language: system
18-
types: [python]
19-
entry: black
20-
2121
- id: isort
22-
name: iSort Import Sorting
23-
language: system
24-
types: [python]
25-
entry: isort
22+
language_version: python
2623

27-
- id: flake8
28-
name: Flake8 Formatting
29-
language: system
30-
types: [python]
31-
entry: flake8 --config=./pyproject.toml
24+
- repo: https://github.com/astral-sh/ruff-pre-commit
25+
rev: v0.3.5
26+
hooks:
27+
- id: ruff
28+
args: ["--fix"]
29+
- id: ruff-format
3230

31+
- repo: https://github.com/pre-commit/mirrors-mypy
32+
rev: v1.9.0
33+
hooks:
3334
- id: mypy
34-
name: MyPy Typecheck
35-
language: system
36-
types: [python]
37-
entry: mypy --config-file=./pyproject.toml
35+
language_version: python
36+
# No reason to run if only tests have changed. They intentionally break typing.
37+
exclude: tests/.*
38+
additional_dependencies:
39+
- types-requests

pyproject.toml

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ keywords=["stac", "pydantic", "validation"]
1919
authors=[{ name = "Arturo Engineering", email = "[email protected]"}]
2020
license= { text = "MIT" }
2121
requires-python=">=3.8"
22-
dependencies = ["click>=8.1.7", "pydantic>=2.4.1", "geojson-pydantic>=1.0.0", "ciso8601~=2.3"]
22+
dependencies = [
23+
"click>=8.1.7",
24+
"pydantic>=2.4.1",
25+
"geojson-pydantic>=1.0.0",
26+
"ciso8601~=2.3",
27+
]
2328
dynamic = ["version", "readme"]
2429

2530
[project.scripts]
@@ -30,16 +35,20 @@ homepage = "https://github.com/stac-utils/stac-pydantic"
3035
repository ="https://github.com/stac-utils/stac-pydantic.git"
3136

3237
[project.optional-dependencies]
33-
dev = ["arrow>=1.2.3",
38+
dev = [
39+
"arrow>=1.2.3",
3440
"pytest>=7.4.2",
3541
"pytest-cov>=4.1.0",
3642
"pytest-icdiff>=0.8",
3743
"requests>=2.31.0",
3844
"shapely>=2.0.1",
3945
"dictdiffer>=0.9.0",
4046
"jsonschema>=4.19.1",
41-
"pyyaml>=6.0.1"]
42-
lint = ["types-requests>=2.31.0.5",
47+
"pyyaml>=6.0.1"
48+
]
49+
50+
lint = [
51+
"types-requests>=2.31.0.5",
4352
"types-jsonschema>=4.19.0.3",
4453
"types-PyYAML>=6.0.12.12",
4554
"black>=23.9.1",
@@ -48,7 +57,8 @@ lint = ["types-requests>=2.31.0.5",
4857
"Flake8-pyproject>=1.2.3",
4958
"mypy>=1.5.1",
5059
"pre-commit>=3.4.0",
51-
"tox>=4.11.3"]
60+
"tox>=4.11.3"
61+
]
5262

5363
[tool.setuptools.dynamic]
5464
version = { attr = "stac_pydantic.version.__version__" }
@@ -64,23 +74,27 @@ exclude = ["tests*"]
6474
[tool.pytest.ini_options]
6575
addopts = "-sv --cov stac_pydantic --cov-report xml --cov-report term-missing --cov-fail-under 95"
6676

67-
[tool.black]
68-
line-length = 88
69-
target-version = ["py311"]
70-
7177
[tool.isort]
7278
profile = "black"
7379
known_first_party = "stac_pydantic"
7480
known_third_party = ["pydantic", "geojson-pydantic", "click"]
7581
default_section = "THIRDPARTY"
7682

7783
[tool.mypy]
78-
plugins = "pydantic.mypy"
7984
ignore_missing_imports = true
8085
exclude = ["tests", ".venv"]
8186

82-
[tool.flake8]
83-
ignore = ["E203", "E501"]
84-
select = ["C","E","F","W","B","B950"]
85-
exclude = ["tests", ".venv"]
86-
max-line-length = 88
87+
[tool.ruff]
88+
line-length = 88
89+
select = [
90+
"C",
91+
"E",
92+
"F",
93+
"W",
94+
"B",
95+
]
96+
ignore = [
97+
"E203", # line too long, handled by black
98+
"E501", # do not perform function calls in argument defaults
99+
"B028", # No explicit `stacklevel` keyword argument found
100+
]

stac_pydantic/api/search.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from typing import Any, Dict, List, Optional, Tuple, Union, cast
33

44
from ciso8601 import parse_rfc3339
5-
from geojson_pydantic.geometries import ( # type: ignore
6-
GeometryCollection,
5+
from geojson_pydantic.geometries import GeometryCollection # type: ignore
6+
from geojson_pydantic.geometries import (
77
LineString,
88
MultiLineString,
99
MultiPoint,
@@ -117,7 +117,9 @@ def validate_datetime(cls, v: str) -> str:
117117
dates.append(parse_rfc3339(value))
118118

119119
if len(values) > 2:
120-
raise ValueError("Invalid datetime range, must match format (begin_date, end_date)")
120+
raise ValueError(
121+
"Invalid datetime range, must match format (begin_date, end_date)"
122+
)
121123

122124
if not {"..", ""}.intersection(set(values)):
123125
if dates[0] > dates[1]:

tests/api/test_search.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import time
2-
from datetime import datetime, timezone, timedelta
2+
from datetime import datetime, timedelta, timezone
33

44
import pytest
55
from pydantic import ValidationError
@@ -97,7 +97,10 @@ def test_invalid_temporal_search():
9797
t2 = t1 + timedelta(seconds=100)
9898
t3 = t2 + timedelta(seconds=100)
9999
with pytest.raises(ValidationError):
100-
Search(collections=["collection1"], datetime=f"{t1.strftime(DATETIME_RFC339)}/{t2.strftime(DATETIME_RFC339)}/{t3.strftime(DATETIME_RFC339)}",)
100+
Search(
101+
collections=["collection1"],
102+
datetime=f"{t1.strftime(DATETIME_RFC339)}/{t2.strftime(DATETIME_RFC339)}/{t3.strftime(DATETIME_RFC339)}",
103+
)
101104

102105
# End date is before start date
103106
start = datetime.utcnow()

tests/conftest.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
from pydantic import BaseModel
1313

1414

15-
def request(url: str, path: List[str] = ["tests", "example_stac"]):
15+
def request(url: str, path: Optional[List[str]] = None):
16+
if path is None:
17+
path = ["tests", "example_stac"]
18+
1619
if url.startswith("http"):
1720
r = requests.get(url)
1821
r.raise_for_status()
@@ -59,8 +62,11 @@ def compare_example(
5962
example_url: str,
6063
model: Type[BaseModel],
6164
fields: Optional[List[str]] = None,
62-
path: List[str] = ["tests", "example_stac"],
65+
path: Optional[List[str]] = None,
6366
) -> None:
67+
if path is None:
68+
path = ["tests", "example_stac"]
69+
6470
example = request(example_url, path)
6571
model_dict = json.loads(model(**example).model_dump_json())
6672

tests/test_models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ def test_sar_extensions() -> None:
6565
def test_proj_extension() -> None:
6666
# The example item uses an invalid band name
6767
test_item = request(PROJ_EXTENSION)
68-
test_item["stac_extensions"][
69-
1
70-
] = "https://github.com/raw/stac-extensions/projection/v1.0.0/json-schema/schema.json"
68+
test_item["stac_extensions"][1] = (
69+
"https://github.com/raw/stac-extensions/projection/v1.0.0/json-schema/schema.json"
70+
)
7171
test_item["assets"]["B8"]["eo:bands"][0]["common_name"] = "pan"
7272

7373
valid_item = Item.model_validate(test_item).model_dump()
@@ -149,7 +149,7 @@ def test_asset_extras() -> None:
149149
test_item["assets"][asset]["foo"] = "bar"
150150

151151
item = Item(**test_item)
152-
for asset_name, asset in item.assets.items():
152+
for _, asset in item.assets.items():
153153
assert asset.foo == "bar"
154154

155155

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ commands = python -m pytest
88
[testenv:lint]
99
extras = lint
1010
description = run linters
11-
commands = SKIP=mypy pre-commit run --all-files
11+
commands = SKIP=mypy pre-commit run --all-files
1212

1313
[testenv:type]
1414
extras = lint

0 commit comments

Comments
 (0)