Skip to content

Commit 3fe4f65

Browse files
committed
Converted to use uv and hatch over venv and tox
1 parent 6efc60c commit 3fe4f65

File tree

9 files changed

+144
-53
lines changed

9 files changed

+144
-53
lines changed

.devcontainer/devcontainer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@
4141
],
4242
// Mount the parent as /workspaces so we can pip install peers as editable
4343
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind",
44-
// After the container is created, install the python project in editable form
45-
"postCreateCommand": "pip install $([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e '.[dev]' && pre-commit install"
44+
// After the container is created, install the uv env
45+
"postCreateCommand": "uv pip install $([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e '.[dev]' && pre-commit install"
4646
}

.github/actions/install_requirements/action.yml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ inputs:
44
python-version:
55
description: Python version to install, default is from Dockerfile
66
default: "dev"
7-
pip-install:
8-
description: Parameters to pass to pip install
9-
default: "$([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e .[dev]"
107

118
runs:
129
using: composite
@@ -20,15 +17,25 @@ runs:
2017
echo "PYTHON_VERSION=$PYTHON_VERSION" >> "$GITHUB_ENV"
2118
shell: bash
2219

23-
- name: Setup python
24-
uses: actions/setup-python@v5
20+
- name: Install uv and set the python version
21+
uses: astral-sh/setup-uv@v5
2522
with:
2623
python-version: ${{ env.PYTHON_VERSION }}
24+
enable-cache: true
25+
cache-dependency-glob: "uv.lock"
2726

28-
- name: Install packages
29-
run: pip install ${{ inputs.pip-install }}
27+
- name: Install dependencies
28+
run: uv sync
3029
shell: bash
3130

3231
- name: Report what was installed
33-
run: pip freeze
32+
run: uv pip list
33+
shell: bash
34+
35+
- name: Add venv path to Github environment
36+
run: echo "VENV_PATH=.venv" >> $GITHUB_ENV
37+
shell: bash
38+
39+
- name: Add venv path to Github Path
40+
run: echo "${{ env.VENV_PATH }}/bin:$PATH" >> $GITHUB_PATH
3441
shell: bash

.github/workflows/_hatch.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
hatch:
5+
type: string
6+
description: What to run under hatch
7+
required: true
8+
9+
10+
jobs:
11+
run:
12+
runs-on: "ubuntu-latest"
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Install python packages
19+
uses: ./.github/actions/install_requirements
20+
21+
- name: Run hatch
22+
run: |
23+
IFS=',' read -ra SCRIPTS <<< "${{ inputs.hatch }}"
24+
for script in "${SCRIPTS[@]}"; do
25+
echo "Running $script"
26+
hatch run $script
27+
done

.github/workflows/_release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Create GitHub Release
2424
# We pin to the SHA, not the tag, for security reasons.
2525
# https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions
26-
uses: softprops/action-gh-release@7b4da11513bf3f43f9999e90eabced41ab8bb048 # v2.2.0
26+
uses: softprops/action-gh-release@c95fe1489396fe8a9eb87c0abf8aa5b2ef267fda # v2.2.1
2727
with:
2828
prerelease: ${{ contains(github.ref_name, 'a') || contains(github.ref_name, 'b') || contains(github.ref_name, 'rc') }}
2929
files: "*"

.github/workflows/_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
pip-install: ".[dev]"
5252

5353
- name: Run tests
54-
run: tox -e tests
54+
run: hatch run tests
5555

5656
- name: Upload coverage to Codecov
5757
uses: codecov/codecov-action@v5

.github/workflows/ci.yml

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,45 @@ jobs:
1111
lint:
1212
needs: check
1313
if: needs.check.outputs.branch-pr == ''
14-
uses: ./.github/workflows/_tox.yml
14+
uses: ./.github/workflows/_hatch.yml
1515
with:
16-
tox: pre-commit
16+
hatch: precommit,type-check
1717

1818
test:
1919
needs: check
2020
if: needs.check.outputs.branch-pr == ''
21+
strategy:
22+
matrix:
23+
runs-on: ["ubuntu-latest"] # can add windows-latest, macos-latest
24+
python-version: ["3.11"]
25+
include:
26+
# Include one that runs in the dev environment
27+
- runs-on: "ubuntu-latest"
28+
python-version: "dev"
29+
fail-fast: false
2130
uses: ./.github/workflows/_test.yml
2231
with:
23-
python-version: dev
24-
runs-on: ubuntu-latest
32+
runs-on: ${{ matrix.runs-on }}
33+
python-version: ${{ matrix.python-version }}
2534
secrets:
2635
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2736

28-
docs:
37+
container:
2938
needs: check
3039
if: needs.check.outputs.branch-pr == ''
31-
uses: ./.github/workflows/_docs.yml
40+
uses: ./.github/workflows/_container.yml
3241
permissions:
33-
contents: write
42+
contents: read
43+
packages: write
3444

35-
example:
36-
needs: test
37-
if: github.ref_name == 'main'
38-
uses: ./.github/workflows/_example.yml
39-
secrets:
40-
EXAMPLE_DEPLOY_KEY: ${{ secrets.EXAMPLE_DEPLOY_KEY }}
45+
dist:
46+
needs: check
47+
if: needs.check.outputs.branch-pr == ''
48+
uses: ./.github/workflows/_dist.yml
4149

4250
release:
4351
if: github.ref_type == 'tag'
44-
needs: docs
52+
needs: [dist]
4553
uses: ./.github/workflows/_release.yml
4654
permissions:
4755
contents: write

.pre-commit-config.yaml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.5.0
3+
rev: v5.0.0
44
hooks:
55
- id: check-added-large-files
66
- id: check-yaml
77
- id: check-merge-conflict
88
- id: end-of-file-fixer
99

10-
- repo: local
10+
- repo: https://github.com/astral-sh/uv-pre-commit
11+
# uv version.
12+
rev: 0.6.3
1113
hooks:
14+
- id: uv-lock
15+
16+
- repo: https://github.com/astral-sh/ruff-pre-commit
17+
# Ruff version.
18+
rev: v0.9.6
19+
hooks:
20+
# Run the linter.
1221
- id: ruff
1322
name: lint with ruff
1423
language: system
15-
entry: ruff check --force-exclude --fix
24+
entry: ruff check --force-exclude
1625
types: [python]
1726
require_serial: true
1827

28+
# Run the formatter.
1929
- id: ruff-format
2030
name: format with ruff
2131
language: system

Dockerfile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ FROM python:${PYTHON_VERSION} AS developer
55

66
# Add any system dependencies for the developer/build environment here
77
RUN apt-get update && apt-get install -y --no-install-recommends \
8-
graphviz \
8+
graphviz vim \
99
&& rm -rf /var/lib/apt/lists/*
10+
# Install uv using the official installer script
11+
RUN curl -LsSf https://astral.sh/uv/install.sh | \
12+
env UV_INSTALL_DIR="/usr/local/bin" sh
1013

11-
# Set up a virtual environment and put it in PATH
12-
RUN python -m venv /venv
13-
ENV PATH=/venv/bin:$PATH
14+
# Configure environment
15+
ENV UV_CHECK_UPDATE=false
16+
# Configure UV to use system Python
17+
# ENV UV_SYSTEM_PYTHON=1
18+
19+
# Creates virtual environment
20+
RUN uv venv --seed venv
21+
ENV VIRTUAL_ENV=/venv
22+
ENV PATH=$VIRTUAL_ENV/bin:$PATH

pyproject.toml

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ dev = [
1919
"sphinx-copybutton",
2020
"sphinx-design",
2121
"tox",
22-
"tox-direct",
2322
]
2423

24+
# # Without this, setuptools apparently try to scan the whole image's filesystem while working in /
25+
# [tool.setuptools.packages.find]
26+
# where = []
27+
2528
[tool.setuptools_scm]
2629

2730
[tool.pytest.ini_options]
@@ -32,27 +35,54 @@ addopts = """
3235
# Doctest python code in docs, python code in src docstrings, test functions in tests
3336
testpaths = "tests"
3437

35-
# tox must currently be configured via an embedded ini string
36-
# See: https://github.com/tox-dev/tox/issues/999
38+
3739
[tool.tox]
38-
legacy_tox_ini = """
39-
[tox]
40-
skipsdist=True
40+
skipsdist = true
41+
42+
[tool.tox.env.pre-commit]
43+
description = "Run pre-commit"
44+
direct = true
45+
allowlist_externals = ["pre-commit"]
46+
commands = [
47+
[
48+
"pre-commit",
49+
"run",
50+
#"--all-files",
51+
"--show-diff-on-failure",
52+
"{posargs}",
53+
],
54+
]
4155

42-
[testenv:{pre-commit,tests,docs}]
43-
# Don't create a virtualenv for the command, requires tox-direct plugin
44-
direct = True
45-
passenv = *
46-
allowlist_externals =
47-
pre-commit
48-
pytest
49-
sphinx-build
50-
sphinx-autobuild
51-
commands =
52-
pre-commit: pre-commit run --all-files --show-diff-on-failure {posargs}
53-
tests: pytest {posargs}
54-
docs: sphinx-{posargs:build -EW --keep-going} -T docs build/html
55-
"""
56+
[tool.tox.env.tests]
57+
description = "Run tests"
58+
direct = true
59+
allowlist_externals = ["pytest"]
60+
commands = [
61+
[
62+
"pytest",
63+
"--cov=phoebus_guibuilder",
64+
"--cov-report",
65+
"term",
66+
"--cov-report",
67+
"xml:cov.xml",
68+
"{posargs}",
69+
],
70+
]
71+
72+
[tool.tox.env.docs]
73+
description = "Run docs"
74+
direct = true
75+
allowlist_externals = ["sphinx-build", "sphinx-autobuild"]
76+
commands = [
77+
[
78+
"sphinx-{posargs:build}",
79+
"-EW",
80+
"--keep-going",
81+
"-T",
82+
"docs",
83+
"build/html",
84+
],
85+
]
5686

5787
[tool.ruff]
5888
src = ["src", "tests"]

0 commit comments

Comments
 (0)