Skip to content

Commit

Permalink
update pre-commit configuration and add python 3.12 in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed Apr 4, 2024
1 parent c03272e commit 3c19368
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand Down
43 changes: 25 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.16
hooks:
- id: validate-pyproject

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand All @@ -10,28 +15,30 @@ repos:
- id: check-added-large-files
args: ["--maxkb=40960"]

- repo: local
- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
- id: black
name: Black Formatting
language: system
types: [python]
entry: black
language_version: python

- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
name: iSort Import Sorting
language: system
types: [python]
entry: isort
language_version: python

- id: flake8
name: Flake8 Formatting
language: system
types: [python]
entry: flake8 --config=./pyproject.toml
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.5
hooks:
- id: ruff
args: ["--fix"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
hooks:
- id: mypy
name: MyPy Typecheck
language: system
types: [python]
entry: mypy --config-file=./pyproject.toml
language_version: python
# No reason to run if only tests have changed. They intentionally break typing.
exclude: tests/.*
additional_dependencies:
- types-requests
43 changes: 28 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ keywords=["stac", "pydantic", "validation"]
authors=[{ name = "Arturo Engineering", email = "engineering@arturo.ai"}]
license= { text = "MIT" }
requires-python=">=3.8"
dependencies = ["click>=8.1.7", "pydantic>=2.4.1", "geojson-pydantic>=1.0.0", "ciso8601~=2.3"]
dependencies = [
"click>=8.1.7",
"pydantic>=2.4.1",
"geojson-pydantic>=1.0.0",
"ciso8601~=2.3",
]
dynamic = ["version", "readme"]

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

[project.optional-dependencies]
dev = ["arrow>=1.2.3",
dev = [
"arrow>=1.2.3",
"pytest>=7.4.2",
"pytest-cov>=4.1.0",
"pytest-icdiff>=0.8",
"requests>=2.31.0",
"shapely>=2.0.1",
"dictdiffer>=0.9.0",
"jsonschema>=4.19.1",
"pyyaml>=6.0.1"]
lint = ["types-requests>=2.31.0.5",
"pyyaml>=6.0.1"
]

lint = [
"types-requests>=2.31.0.5",
"types-jsonschema>=4.19.0.3",
"types-PyYAML>=6.0.12.12",
"black>=23.9.1",
Expand All @@ -48,7 +57,8 @@ lint = ["types-requests>=2.31.0.5",
"Flake8-pyproject>=1.2.3",
"mypy>=1.5.1",
"pre-commit>=3.4.0",
"tox>=4.11.3"]
"tox>=4.11.3"
]

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

[tool.black]
line-length = 88
target-version = ["py311"]

[tool.isort]
profile = "black"
known_first_party = "stac_pydantic"
known_third_party = ["pydantic", "geojson-pydantic", "click"]
default_section = "THIRDPARTY"

[tool.mypy]
plugins = "pydantic.mypy"
ignore_missing_imports = true
exclude = ["tests", ".venv"]

[tool.flake8]
ignore = ["E203", "E501"]
select = ["C","E","F","W","B","B950"]
exclude = ["tests", ".venv"]
max-line-length = 88
[tool.ruff]
select = [
"C",
"E",
"F",
"W",
"B",
]
ignore = [
"E203", # line too long, handled by black
"E501", # do not perform function calls in argument defaults
"B028", # No explicit `stacklevel` keyword argument found
]
4 changes: 3 additions & 1 deletion stac_pydantic/api/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def validate_datetime(cls, v: str) -> str:
dates.append(parse_rfc3339(value))

if len(values) > 2:
raise ValueError("Invalid datetime range, must match format (begin_date, end_date)")
raise ValueError(
"Invalid datetime range, must match format (begin_date, end_date)"
)

if not {"..", ""}.intersection(set(values)):
if dates[0] > dates[1]:
Expand Down
7 changes: 5 additions & 2 deletions tests/api/test_search.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
from datetime import datetime, timezone, timedelta
from datetime import datetime, timedelta, timezone

import pytest
from pydantic import ValidationError
Expand Down Expand Up @@ -97,7 +97,10 @@ def test_invalid_temporal_search():
t2 = t1 + timedelta(seconds=100)
t3 = t2 + timedelta(seconds=100)
with pytest.raises(ValidationError):
Search(collections=["collection1"], datetime=f"{t1.strftime(DATETIME_RFC339)}/{t2.strftime(DATETIME_RFC339)}/{t3.strftime(DATETIME_RFC339)}",)
Search(
collections=["collection1"],
datetime=f"{t1.strftime(DATETIME_RFC339)}/{t2.strftime(DATETIME_RFC339)}/{t3.strftime(DATETIME_RFC339)}",
)

# End date is before start date
start = datetime.utcnow()
Expand Down
10 changes: 8 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
from pydantic import BaseModel


def request(url: str, path: List[str] = ["tests", "example_stac"]):
def request(url: str, path: Optional[List[str]] = None):
if path is None:
path = ["tests", "example_stac"]

if url.startswith("http"):
r = requests.get(url)
r.raise_for_status()
Expand Down Expand Up @@ -59,8 +62,11 @@ def compare_example(
example_url: str,
model: Type[BaseModel],
fields: Optional[List[str]] = None,
path: List[str] = ["tests", "example_stac"],
path: Optional[List[str]] = None,
) -> None:
if path is None:
path = ["tests", "example_stac"]

example = request(example_url, path)
model_dict = json.loads(model(**example).model_dump_json())

Expand Down
2 changes: 1 addition & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_asset_extras() -> None:
test_item["assets"][asset]["foo"] = "bar"

item = Item(**test_item)
for asset_name, asset in item.assets.items():
for _, asset in item.assets.items():
assert asset.foo == "bar"


Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ commands = python -m pytest
[testenv:lint]
extras = lint
description = run linters
commands = SKIP=mypy pre-commit run --all-files
commands = SKIP=mypy pre-commit run --all-files

[testenv:type]
extras = lint
Expand Down

0 comments on commit 3c19368

Please sign in to comment.