Skip to content

Commit dfc8954

Browse files
authored
build(dev): switch to uv (#75)
This basically removes all requirements.txt files since `uv` does not use them. Instead, `uv` keeps a lock file based on dependencies described in the pyproject.toml manifest. Also adds some unpinned dev dependencies (ruff, mypy, pre-commit) to the automatically sync'd `dev` group. Just use `uv sync` for basic dev env setup; add `--group docs` and/or `--group tests` to install deps for the respective groups. Of course, this adjusts the CI (& RTD config) for use of `uv`. And, I enabled dependabot for auto-updating the uv.lock file. Fixed conditional logic in release CI (about deploying to PyPI)
1 parent aeb772e commit dfc8954

File tree

10 files changed

+2102
-49
lines changed

10 files changed

+2102
-49
lines changed

.cspell.config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ words:
7070
- Pluss
7171
- pypa
7272
- pypi
73+
- pyproject
7374
- pytest
7475
- ranksep
7576
- raspberrypi

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,14 @@ updates:
1717
actions:
1818
patterns:
1919
- "*"
20+
- package-ecosystem: "uv"
21+
# directory of `uv.lock` file
22+
directory: "/"
23+
schedule:
24+
interval: "weekly"
25+
cooldown:
26+
default-days: 5
27+
groups:
28+
uv-pip:
29+
patterns:
30+
- "*"

.github/workflows/build.yml

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,27 @@ jobs:
1212
linters:
1313
runs-on: ubuntu-latest
1414
steps:
15+
- uses: actions/checkout@v6
16+
with:
17+
persist-credentials: false
18+
1519
- uses: actions/setup-python@v6
1620
id: python-setup
1721
with:
1822
python-version: "3.x"
1923

20-
- uses: actions/checkout@v6
24+
- uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
2125
with:
22-
persist-credentials: false
26+
python-version: ${{ steps.python-setup.outputs.python-version }}
2327

2428
- name: Cache pre-commit environments
2529
uses: actions/cache@v4
2630
with:
2731
path: '~/.cache/pre-commit'
2832
key: pre-commit-${{ steps.python-setup.outputs.python-version }}-${{ hashFiles('.pre-commit-config.yaml') }}
2933

30-
- name: Install pre-commit and deps
31-
run: pip install pre-commit -r requirements.txt
32-
33-
- name: Pre-commit hooks
34-
run: pre-commit run --all-files --show-diff-on-failure
34+
- name: Run pre-commit hooks
35+
run: uv run pre-commit run --all-files --show-diff-on-failure
3536

3637
test-coverage:
3738
runs-on: ubuntu-latest
@@ -41,17 +42,24 @@ jobs:
4142
persist-credentials: false
4243

4344
- uses: actions/setup-python@v6
45+
id: python-setup
4446
with:
4547
python-version: "3.x"
4648

49+
- uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
50+
with:
51+
python-version: ${{ steps.python-setup.outputs.python-version }}
52+
4753
- name: Install testing tools
48-
run: pip install -r requirements.txt -r tests/requirements.txt
54+
run: uv sync --group tests
4955

5056
- name: Collect coverage
57+
env:
58+
UV_NO_SYNC: 1
5159
run: |
52-
coverage run -m pytest
53-
coverage report
54-
coverage xml
60+
uv run coverage run -m pytest
61+
uv run coverage report
62+
uv run coverage xml
5563
5664
- name: Upload coverage reports to Codecov
5765
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
@@ -70,21 +78,26 @@ jobs:
7078
with:
7179
persist-credentials: false
7280

73-
- name: Set up Python 3.x
74-
uses: actions/setup-python@v6
81+
- uses: actions/setup-python@v6
82+
id: python-setup
7583
with:
7684
python-version: "3.x"
7785

86+
- uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
87+
with:
88+
python-version: ${{ steps.python-setup.outputs.python-version }}
89+
7890
- name: Install deps
7991
run: |-
80-
pip install -r docs/requirements.txt
81-
pip install -e .
92+
uv sync --group docs
8293
sudo apt-get update
8394
sudo apt-get install libgl1-mesa-dev libxkbcommon-x11-0 graphviz
8495
8596
- name: Build docs
8697
working-directory: docs
87-
run: sphinx-build -E -W -b html . _build/html
98+
env:
99+
UV_NO_SYNC: 1
100+
run: uv run sphinx-build -E -W -b html . _build/html
88101

89102
- name: Archive docs
90103
uses: actions/upload-artifact@v5

.github/workflows/release.yml

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,23 @@ jobs:
2020
fetch-depth: 0
2121

2222
- uses: actions/setup-python@v6
23+
id: python-setup
2324
with:
2425
python-version: "3.x"
2526

27+
- uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
28+
with:
29+
python-version: ${{ steps.python-setup.outputs.python-version }}
30+
enable-cache: false # prevent cache poisoning
31+
2632
- name: Build PyPI distributions
27-
run: pipx run build
33+
run: uvx --from build pyproject-build
2834

2935
- name: Check distributions
3036
# this is done automatically when deploying to PyPI.
3137
# We only do this here for non-release builds.
3238
if: ${{ !startsWith(github.ref, 'refs/tags/v') && github.event_name != 'workflow_dispatch' }}
33-
run: pipx run twine check dist/*
39+
run: uvx twine check dist/*
3440

3541
- name: Archive distributions
3642
uses: actions/upload-artifact@v5
@@ -58,17 +64,22 @@ jobs:
5864
echo pkg-name=$(echo "${REPO_NAME}" |
5965
awk '{ print tolower($1) }') >> "${GITHUB_OUTPUT}"
6066
61-
- name: Set up Python 3.x
62-
uses: actions/setup-python@v6
63-
with:
64-
python-version: "3.x"
65-
6667
- name: Checkout Current Repo
6768
uses: actions/checkout@v6
6869
with:
6970
persist-credentials: false
7071
fetch-depth: 0
7172

73+
- uses: actions/setup-python@v6
74+
id: python-setup
75+
with:
76+
python-version: "3.x"
77+
78+
- uses: astral-sh/setup-uv@1e862dfacbd1d6d858c55d9b792c756523627244 # v7.1.4
79+
with:
80+
python-version: ${{ steps.python-setup.outputs.python-version }}
81+
enable-cache: false # prevent cache poisoning
82+
7283
- name: Install CircuitPython Linux deps
7384
run: |-
7485
sudo apt-get update
@@ -80,7 +91,7 @@ jobs:
8091
FILENAME_PREFIX: ${{ steps.repo-name.outputs.repo-name }}
8192
PACKAGE_FOLDER_PREFIX: ${{ steps.pkg-name.outputs.pkg-name }}
8293
run: >-
83-
pipx run --spec circuitpython-build-tools
94+
uvx --from circuitpython-build-tools
8495
circuitpython-build-bundles
8596
--filename_prefix "${FILENAME_PREFIX}"
8697
--package_folder_prefix "${PACKAGE_FOLDER_NAME}"
@@ -113,7 +124,7 @@ jobs:
113124
gh release upload "${TAG}" ${assets}
114125
115126
upload-pypi:
116-
if: (github.ref == 'refs/heads/master' && github.event_name == 'workflow_dispatch') || startsWith(github.ref, 'refs/tags/v')
127+
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
117128
runs-on: ubuntu-latest
118129
needs: [build-pypi-distributions]
119130
permissions:
@@ -124,8 +135,8 @@ jobs:
124135
with:
125136
name: dist
126137

127-
- name: Publish package (to ${{github.event_name == 'workflow_dispatch' && 'Test' || '' }}PyPI)
138+
- name: Publish package (to ${{ !startsWith(github.ref, 'refs/tags/v') && 'Test' || '' }}PyPI)
128139
if: github.repository == 'nRF24/CircuitPython_nRF24L01'
129140
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
130141
with:
131-
repository-url: https://${{github.event_name == 'workflow_dispatch' && 'test' || 'upload' }}.pypi.org/legacy/
142+
repository-url: https://${{ startsWith(github.ref, 'refs/tags/v') && 'upload' || 'test' }}.pypi.org/legacy/

.readthedocs.yml

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,29 @@
88
# Required
99
version: 2
1010

11-
sphinx:
12-
# Path to your Sphinx configuration file.
13-
configuration: docs/conf.py
14-
1511
build:
1612
os: ubuntu-22.04
1713
tools:
18-
python: "3.11"
14+
python: latest
1915
apt_packages:
2016
- libgl1-mesa-dev
2117
- libxkbcommon-x11-0
2218
- graphviz
19+
jobs:
20+
pre_create_environment:
21+
- >-
22+
UV_INSTALL_DIR="${HOME}/.local/bin" &&
23+
curl -LsSf https://astral.sh/uv/install.sh | sh
24+
- ${HOME}/.local/bin/uv sync --group docs
25+
build:
26+
html:
27+
- >-
28+
${HOME}/.local/bin/uv run
29+
sphinx-build docs docs/_build/html
30+
post_build:
31+
- mkdir -p ${READTHEDOCS_OUTPUT}/html/
32+
- mv docs/_build/html/* ${READTHEDOCS_OUTPUT}/html
2333

24-
python:
25-
install:
26-
- method: pip
27-
path: .
28-
- requirements: docs/requirements.txt
34+
sphinx:
35+
# Path to your Sphinx configuration file.
36+
configuration: docs/conf.py

docs/requirements.txt

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

pyproject.toml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ classifiers = [
3535
"Topic :: System :: Hardware",
3636
"Programming Language :: Python :: 3",
3737
]
38-
dynamic = ["version", "dependencies"]
38+
dynamic = ["version"]
39+
dependencies = [
40+
"adafruit-blinka>=8.68.0",
41+
"adafruit-circuitpython-busdevice>=5.2.14",
42+
"spidev>=3.8 ; (platform_machine == 'aarch64' and sys_platform == 'linux') or (platform_machine == 'armv6l' and sys_platform == 'linux') or (platform_machine == 'armv7l' and sys_platform == 'linux')",
43+
"typing-extensions>=4.15.0",
44+
]
3945

4046
[project.urls]
4147
Documentation = "https://circuitpython-nrf24l01.readthedocs.io"
@@ -45,9 +51,6 @@ Tracker = "https://github.com/2bndy5/CircuitPython_nRF24L01/issues"
4551
[tool.setuptools]
4652
packages = ["circuitpython_nrf24l01"]
4753

48-
[tool.setuptools.dynamic]
49-
dependencies = {file = ["requirements.txt"]}
50-
5154
[tool.setuptools_scm]
5255
# It would be nice to include the commit hash in the version, but that
5356
# can't be done in a PEP 440-compatible way.
@@ -87,3 +90,18 @@ exclude_lines = [
8790
"radio hardware not responding",
8891
"elif not after_toggle",
8992
]
93+
94+
[dependency-groups]
95+
dev = [
96+
"mypy>=1.18.2",
97+
"pre-commit>=4.3.0",
98+
"ruff>=0.14.6",
99+
]
100+
docs = [
101+
"sphinx-immaterial[keys]>=0.12.5",
102+
"sphinx-social-cards>=0.5.0",
103+
]
104+
tests = [
105+
"coverage[toml]>=7.10.7",
106+
"pytest>=8.4.2",
107+
]

requirements.txt

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

tests/requirements.txt

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

0 commit comments

Comments
 (0)