Skip to content

Commit

Permalink
ci: use uv in commit-triggered jobs (#171)
Browse files Browse the repository at this point in the history
Use UV in the CI test workflow. Also add a concurrency group constraint to the CI test workflow. Add dependency groups to `pyproject.toml` matching the extras groups. UV already supports dep groups. Eventually it seems like pip will too so at that point we can remove the extras.

Didn't use uv in the release workflow yet, will do that at next release time.
  • Loading branch information
wpbonelli authored Jan 14, 2025
1 parent 52e846b commit 7112a02
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 32 deletions.
71 changes: 43 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:
- '**.md'
- '.github/workflows/release.yml'
- '.gitignore'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
lint:
name: Lint
Expand All @@ -22,24 +25,27 @@ jobs:
- name: Checkout repo
uses: actions/checkout@v4

- name: Setup uv
uses: astral-sh/setup-uv@v5
with:
version: "0.5.18"

- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.x
cache: 'pip'
cache-dependency-path: pyproject.toml
python-version-file: pyproject.toml

- name: Install Python packages
run: pip install ".[lint]"
- name: Install project
run: uv sync --group lint

- name: Run ruff check
run: ruff check
run: uv run ruff check

- name: Run ruff format
run: ruff format --check
run: uv run ruff format --check

- name: Check spelling
run: codespell
run: uv run codespell

build:
name: Build
Expand All @@ -49,24 +55,27 @@ jobs:
- name: Checkout repo
uses: actions/checkout@v3

- name: Setup uv
uses: astral-sh/setup-uv@v5
with:
version: "0.5.18"

- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.x
python-version-file: pyproject.toml

- name: Install Python packages
run: |
pip install --upgrade pip
pip install ".[build]"
- name: Install project
run: uv sync --group build

- name: Print package version
run: python -c "import modflow_devtools; print(modflow_devtools.__version__)"
run: uv run python -c "import modflow_devtools; print(modflow_devtools.__version__)"

- name: Build package
run: python -m build
run: uv run python -m build

- name: Check distribution
run: twine check --strict dist/*
run: uv run twine check --strict dist/*

test:
name: Test
Expand Down Expand Up @@ -126,14 +135,20 @@ jobs:
compiler: gcc
version: ${{ env.GCC_V }}

- name: Setup Python
uses: actions/setup-python@v4
- name: Setup uv
uses: astral-sh/setup-uv@v5
with:
version: "0.5.18"
python-version: ${{ matrix.python }}

- name: Install Python packages
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version-file: modflow-devtools/pyproject.toml

- name: Install project
working-directory: modflow-devtools
run: pip install ".[dev]"
run: uv sync --all-extras

- name: Cache modflow6 examples
id: cache-examples
Expand All @@ -145,23 +160,23 @@ jobs:
- name: Install extra Python packages
working-directory: modflow6-examples/etc
run: |
pip install -r requirements.pip.txt
pip install -r requirements.usgs.txt
uv pip install -r requirements.pip.txt
uv pip install -r requirements.usgs.txt
- name: Update FloPy packages
run: python -m flopy.mf6.utils.generate_classes --ref develop --no-backup
run: uv run python -m flopy.mf6.utils.generate_classes --ref develop --no-backup

- name: Build modflow6 example models
if: steps.cache-examples.outputs.cache-hit != 'true'
working-directory: modflow6-examples/autotest
run: pytest -v -n auto test_scripts.py --init
run: uv run pytest -v -n auto test_scripts.py --init

- name: Run local tests
working-directory: modflow-devtools/autotest
env:
REPOS_PATH: ${{ github.workspace }}
# use --dist loadfile to so tests requiring pytest-virtualenv run on the same worker
run: pytest -v -n auto --dist loadfile --durations 0 --ignore test_download.py
run: uv run pytest -v -n auto --dist loadfile --durations 0 --ignore test_download.py

- name: Run network-dependent tests
# only invoke the GH API on one OS and Python version
Expand All @@ -172,7 +187,7 @@ jobs:
env:
REPOS_PATH: ${{ github.workspace }}
GITHUB_TOKEN: ${{ github.token }}
run: pytest -v -n auto --durations 0 test_download.py
run: uv run pytest -v -n auto --durations 0 test_download.py

rtd:
name: Docs
Expand Down
6 changes: 3 additions & 3 deletions modflow_devtools/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def function_tmpdir(tmpdir_factory, request) -> Generator[Path, None, None]:

@pytest.fixture(scope="class")
def class_tmpdir(tmpdir_factory, request) -> Generator[Path, None, None]:
assert (
request.cls is not None
), "Class-scoped temp dir fixture must be used on class"
assert request.cls is not None, (
"Class-scoped temp dir fixture must be used on class"
)
temp = Path(tmpdir_factory.mktemp(request.cls.__name__))
yield temp

Expand Down
44 changes: 43 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ requires-python = ">=3.9"
dynamic = ["version"]

[project.optional-dependencies]
dev=["modflow-devtools[lint,test,docs,dfn]"]
build = [
"build",
"twine"
Expand Down Expand Up @@ -77,6 +76,49 @@ dfn = [
"boltons",
"tomlkit"
]
dev = ["modflow-devtools[lint,test,docs,dfn]"]

[dependency-groups]
build = [
"build",
"twine"
]
lint = [
"codespell[toml]",
"ruff"
]
test = [
"modflow-devtools[lint]",
"coverage",
"flaky",
"filelock",
"meson!=0.63.0",
"ninja",
"numpy",
"pandas",
"pytest!=8.1.0",
"pytest-cov",
"pytest-dotenv",
"pytest-xdist",
"PyYaml",
"syrupy"
]
docs = [
"sphinx",
"sphinx-rtd-theme",
"myst-parser"
]
dfn = [
"boltons",
"tomlkit"
]
dev = [
{include-group = "build"},
{include-group = "lint"},
{include-group = "test"},
{include-group = "docs"},
{include-group = "dfn"}
]

[project.urls]
"Documentation" = "https://modflow-devtools.readthedocs.io/en/latest/"
Expand Down

0 comments on commit 7112a02

Please sign in to comment.