Skip to content

Commit 583e4ea

Browse files
authored
Migrate to uv, prex, ruff, ty, etc (#156)
* [devExp] migrate to uv, prek, ruff, etc * [chore] run ruff on all * [devExp] commit lock for reproducibility * [devExp] migrate justfile to uv * [chore] fix ty on src/cascade * [chore] fix ty on tests/cascade * [ci] fix ci action * [ci] disable downstream ci * [ci] fix ci action
1 parent 79486b1 commit 583e4ea

40 files changed

+2880
-289
lines changed

.github/ci-config.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.github/ci-hpc-config.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 0 additions & 80 deletions
This file was deleted.

.github/workflows/macos-test.yml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
name: macos-test
1+
name: CI # TODO rename the file in a standalone PR
22

33
on:
44
# Trigger the workflow manually
55
workflow_dispatch: ~
66

7-
# Call from other workflows
8-
workflow_call: ~
7+
push:
8+
branches:
9+
- 'main'
10+
- 'develop'
11+
12+
pull_request: ~
913

1014
jobs:
11-
macos-pytest:
15+
ci:
1216
strategy:
1317
fail-fast: true
1418
matrix:
15-
arch_type: [ARM64] # [ARM64, X64]
16-
python_version: ["3.11"] # ["3.10", "3.11", "3.12", "3.13"]
17-
runs-on: [self-hosted, macOS, "${{ matrix.arch_type }}"]
19+
arch_type: ["macos-ARM64", "linux-x86"]
20+
python_version: ["3.10", "3.11", "3.12", "3.13"]
21+
runs-on: "${{ fromJSON('{\"linux-x86\": [\"self-hosted\", \"Linux\", \"platform-builder-Rocky-8.6\"], \"macos-ARM64\": [\"self-hosted\", \"macOS\", \"ARM64\"]}')[matrix.arch_type] }}"
22+
timeout-minutes: 20
1823
steps:
1924
- uses: actions/checkout@v4
2025
- uses: actions/setup-python@v5
@@ -23,7 +28,8 @@ jobs:
2328
- uses: astral-sh/setup-uv@v6
2429
with:
2530
version: 0.7.19
31+
- uses: extractions/setup-just@v3
2632
- run: |
27-
uv venv venv && source venv/bin/activate
28-
uv pip install '.[tests]'
29-
pytest
33+
uv sync --python "${{ matrix.python_version }}"
34+
just fmt
35+
just val

.pre-commit-config.yaml

Lines changed: 16 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,29 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.6.0
3+
rev: v6.0.0
44
hooks:
55
- id: check-yaml # Check YAML files for syntax errors only
66
args: [--unsafe, --allow-multiple-documents]
7-
- id: debug-statements # Check for debugger imports and py37+ breakpoint()
8-
- id: end-of-file-fixer # Ensure files end in a newline
9-
- id: trailing-whitespace # Trailing whitespace checker
10-
- id: no-commit-to-branch # Prevent committing to main / master
11-
- id: check-added-large-files # Check for large files added to git
7+
# - id: no-commit-to-branch # NOTE prevents commit to main/master, but since we run prek on that branch it makes no sense
8+
- id: check-added-large-files
9+
exclude: |
10+
(?x)(
11+
.*uv.lock|
12+
.*pylock.toml
13+
)
1214
- id: check-merge-conflict # Check for files that contain merge conflict
13-
- repo: https://github.com/pre-commit/pygrep-hooks
14-
rev: v1.10.0 # Use the ref you want to point at
15-
hooks:
16-
- id: python-use-type-annotations # Check for missing type annotations
17-
- id: python-check-blanket-noqa # Check for # noqa: all
18-
- id: python-no-log-warn # Check for log.warn
19-
- repo: https://github.com/psf/black-pre-commit-mirror
20-
rev: 25.1.0
21-
hooks:
22-
- id: black
23-
# args: [--line-length=120]
24-
- repo: https://github.com/pycqa/isort
25-
rev: 5.13.2
26-
hooks:
27-
- id: isort
28-
args:
29-
# - -l 120
30-
- --profile black
3115
- repo: https://github.com/astral-sh/ruff-pre-commit
32-
rev: v0.6.5
16+
rev: v0.12.2
3317
hooks:
34-
- id: ruff
35-
# Next line if for documenation cod snippets
36-
exclude: '^[^_].*_\.py$'
18+
- id: ruff # better black/flake/isort
19+
files: ^src/
3720
args:
38-
# - --line-length=120
21+
- --select
22+
- I # isorting
3923
- --fix
4024
- --exit-non-zero-on-fix
41-
- --preview
42-
- repo: https://github.com/sphinx-contrib/sphinx-lint
43-
rev: v1.0.0
44-
hooks:
45-
- id: sphinx-lint
46-
# For now, we use it. But it does not support a lot of sphinx features
47-
- repo: https://github.com/dzhu/rstfmt
48-
rev: v0.0.14
49-
hooks:
50-
- id: rstfmt
51-
exclude: 'cli/.*' # Because we use argparse
52-
- repo: https://github.com/b8raoult/pre-commit-docconvert
53-
rev: "0.1.5"
54-
hooks:
55-
- id: docconvert
56-
args: ["numpy"]
57-
# - repo: https://github.com/tox-dev/pyproject-fmt
58-
# rev: "2.2.3"
59-
# hooks:
60-
# - id: pyproject-fmt
61-
# - repo: https://github.com/jshwi/docsig # Check docstrings against function sig
62-
# rev: v0.60.1
63-
# hooks:
64-
# - id: docsig
65-
# args:
66-
# - --ignore-no-params # Allow docstrings without parameters
67-
# - --check-dunders # Check dunder methods
68-
# - --check-overridden # Check overridden methods
69-
# - --check-protected # Check protected methods
70-
# - --check-class # Check class docstrings
71-
# - --disable=E113 # Disable empty docstrings
72-
# - --summary # Print a summary
25+
- id: ruff-format
26+
files: ^backend/
7327
ci:
7428
autoupdate_schedule: monthly
29+
autoupdate_commit_msg: "chore(deps): pre-commit.ci autoupdate"

.python_version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.11.9
File renamed without changes.

justfile

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@
1010
set dotenv-path := ".env"
1111

1212
val:
13-
mypy src/cascade --ignore-missing-imports
14-
mypy tests --ignore-missing-imports
15-
pytest -n 8 tests
16-
13+
uv run ty check src/cascade
14+
uv run ty check tests/cascade
15+
# TODO eventually broaden type coverage to ekw as well
16+
uv run pytest -n8 tests
1717
fmt:
18-
# TODO replace with pre-commit
19-
isort --profile black .
20-
black .
21-
flake8 .
18+
uv run prek --all-files

pyproject.toml

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# nor does it submit to any jurisdiction.
88

99
[build-system]
10-
requires = ["setuptools>=65", "setuptools_scm[toml]>=6.2"]
10+
requires = ["setuptools>=80", "setuptools_scm[toml]>=6.2", "packaging>=25"]
1111
build-backend = "setuptools.build_meta"
1212

1313
[project]
@@ -39,21 +39,13 @@ dependencies = [
3939
dynamic = ["version"]
4040
readme = "README.md"
4141

42-
[project.optional-dependencies]
43-
tests = ["pytest", "pytest-xdist", "earthkit-data"]
44-
lint = ["black", "isort", "flake8"]
45-
gpu = ["jax[cpu]", "jax[cuda11_pip]", "cupy-cuda11x", "numba"]
46-
examples = ["cftime", "bokeh"]
47-
earthkit = ["earthkit-data"]
48-
all = ["cascade[tests,kubernetes,lint,gpu,examples,earthkit]"]
42+
[dependency-groups]
43+
dev = ["pytest", "pytest-xdist>=3.8", "prek", "ty==0.0.2", "build", "bokeh"]
4944

5045
[tool.setuptools]
5146
include-package-data = true
5247
zip-safe = false
5348

54-
[tool.setuptools.dynamic]
55-
readme = {file = ["readme.md"], content-type = "text/markdown"}
56-
5749
[tool.setuptools_scm]
5850
write_to = "src/earthkit/workflows/_version.py"
5951
write_to_template = '''# Do not change! Do not track in version control!
@@ -65,17 +57,12 @@ local_scheme = "no-local-version"
6557
include = ["earthkit.workflows*", "cascade*"]
6658
where = ["src"]
6759

68-
[tool.isort]
69-
profile = "black"
70-
71-
[tool.mypy]
72-
plugins = "pydantic.mypy"
73-
7460
[tool.pytest.ini_options]
7561
log_cli = true
7662
log_cli_level = "DEBUG"
7763
testpaths = ["tests/"]
7864
addopts = "-n8"
7965

80-
[tool.ruff.lint]
81-
ignore = ["E722", "E731", "E741"]
66+
[tool.ruff]
67+
line-length = 140
68+
lint.ignore = [ "E722", "E731", "E741" ]

src/cascade/benchmarks/anemoi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
def get_graph(lead_time, ensemble_members, CKPT=None, date="2024-12-02T00:00"):
13-
import anemoicascade as ac
13+
import anemoicascade as ac # ty: ignore[unresolved-import]
1414

1515
CKPT = (
1616
CKPT

0 commit comments

Comments
 (0)