Skip to content

Commit 7b9b9e8

Browse files
samuelcolvinclaude
andauthored
Adopt uv ruff basedpyright (#171)
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 5022f1f commit 7b9b9e8

37 files changed

Lines changed: 2858 additions & 786 deletions

‎.codecov.yml‎

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

‎.github/workflows/ci.yml‎

Lines changed: 98 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,49 @@ on:
88
- '**'
99
pull_request: {}
1010

11+
# no permissions by default, the release job grants itself what it needs
12+
permissions: {}
13+
1114
env:
1215
COLUMNS: 150
16+
UV_FROZEN: '1'
1317

1418
jobs:
1519
lint:
1620
runs-on: ubuntu-latest
1721

1822
steps:
19-
- uses: actions/checkout@v3
20-
21-
- uses: actions/setup-python@v4
23+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
2224
with:
23-
python-version: '3.10'
25+
persist-credentials: false
2426

25-
- run: pip install -r requirements/linting.txt -r requirements/pyproject.txt
27+
- uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
28+
with:
29+
python-version: '3.12'
30+
enable-cache: true # zizmor: ignore[cache-poisoning] -- Job does not produce release artifacts and does not have sensitive permissions
2631

27-
- run: mypy devtools
32+
- run: uv sync --group dev
2833

29-
- uses: pre-commit/action@v3.0.0
30-
with:
31-
extra_args: --all-files --verbose
34+
- run: make lint
3235

3336
docs-build:
3437
runs-on: ubuntu-latest
3538
steps:
36-
- uses: actions/checkout@v3
39+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
40+
with:
41+
persist-credentials: false
3742

38-
- uses: actions/setup-python@v4
43+
- uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
3944
with:
40-
python-version: '3.10'
45+
python-version: '3.12'
46+
enable-cache: false
4147

42-
- run: pip install -r requirements/docs.txt -r requirements/pyproject.txt
43-
- run: pip install .
48+
- run: uv sync --group docs
4449

4550
- run: make docs
4651

4752
- name: Store docs site
48-
uses: actions/upload-artifact@v3
53+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
4954
with:
5055
name: docs
5156
path: site
@@ -56,114 +61,134 @@ jobs:
5661
fail-fast: false
5762
matrix:
5863
os: [ubuntu-latest, macos-latest, windows-latest]
59-
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
60-
exclude:
61-
- os: macos-latest
62-
python-version: '3.7'
63-
include:
64-
- os: macos-13
65-
python-version: '3.7'
66-
67-
env:
68-
PYTHON: ${{ matrix.python-version }}
69-
OS: ${{ matrix.os }}
70-
EXTRAS: yes
64+
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
7165

7266
runs-on: ${{ matrix.os }}
7367

7468
steps:
75-
- uses: actions/checkout@v3
69+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
70+
with:
71+
persist-credentials: false
7672

77-
- name: set up python
78-
uses: actions/setup-python@v4
73+
- uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
7974
with:
8075
python-version: ${{ matrix.python-version }}
76+
enable-cache: true # zizmor: ignore[cache-poisoning] -- Job does not produce release artifacts and does not have sensitive permissions
77+
78+
- run: uv sync --group dev
8179

82-
- run: pip install -r requirements/testing.txt -r requirements/pyproject.txt
80+
- run: uv pip freeze
8381

84-
- run: pip freeze
82+
- run: mkdir coverage
8583

8684
- name: test with extras
87-
run: make test
85+
run: uv run coverage run -m pytest
86+
env:
87+
COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-with-extras
88+
CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }}-with-extras
8889

89-
- run: coverage xml
90+
- name: uninstall extras
91+
run: uv pip uninstall multidict numpy pydantic asyncpg sqlalchemy
9092

91-
- uses: codecov/codecov-action@v3
93+
- name: test without extras
94+
run: uv run coverage run -m pytest
95+
env:
96+
COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-without-extras
97+
CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }}-without-extras
98+
99+
- name: Store coverage files
100+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
92101
with:
93-
file: ./coverage.xml
94-
env_vars: EXTRAS,PYTHON,OS
102+
name: coverage-${{ matrix.os }}-${{ matrix.python-version }}
103+
path: coverage
104+
include-hidden-files: true
95105

96-
- name: uninstall extras
97-
run: pip uninstall -y multidict numpy pydantic asyncpg sqlalchemy
106+
coverage-combine:
107+
needs: [test]
108+
runs-on: ubuntu-latest
98109

99-
- name: test without extras
100-
run: make test
110+
steps:
111+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
112+
with:
113+
persist-credentials: false
101114

102-
- run: coverage xml
115+
- uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
116+
with:
117+
python-version: '3.12'
118+
enable-cache: false
103119

104-
- uses: codecov/codecov-action@v3
105-
with:
106-
file: ./coverage.xml
107-
env_vars: EXTRAS,PYTHON,OS
108-
env:
109-
EXTRAS: no
120+
- name: Get coverage files
121+
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
122+
with:
123+
merge-multiple: true
124+
pattern: coverage-*
125+
path: coverage
126+
127+
- run: uv sync --group dev
128+
129+
- run: ls -la coverage
130+
- run: uv run coverage combine coverage
131+
- run: uv run coverage report
132+
- run: uv run coverage html --show-contexts --title "devtools coverage for ${{ github.sha }}"
133+
134+
- name: Store coverage HTML
135+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
136+
with:
137+
name: coverage-html
138+
path: htmlcov
110139

111140
# https://github.com/marketplace/actions/alls-green#why used for branch protection checks
112141
check:
113142
if: always()
114-
needs: [test, lint, docs-build]
143+
needs: [test, lint, docs-build, coverage-combine]
115144
runs-on: ubuntu-latest
116145
steps:
117146
- name: Decide whether the needed jobs succeeded or failed
118-
uses: re-actors/alls-green@release/v1
147+
uses: re-actors/alls-green@b5b5b37504aa4183270bd3d855c52a67f212be35 # release/v1
119148
with:
120149
jobs: ${{ toJSON(needs) }}
121150

122-
deploy:
151+
release:
123152
needs:
124153
- check
125154
if: "success() && startsWith(github.ref, 'refs/tags/')"
126155
runs-on: ubuntu-latest
156+
environment: release
157+
permissions:
158+
# for trusted publishing to PyPI
159+
id-token: write
127160

128161
steps:
129-
- uses: actions/checkout@v3
162+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
163+
with:
164+
persist-credentials: false
130165

131-
- name: set up python
132-
uses: actions/setup-python@v4
166+
- uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 # v10.3.0
133167
with:
134-
python-version: '3.10'
168+
python-version: '3.12'
169+
enable-cache: false
135170

136171
- name: get docs
137-
uses: actions/download-artifact@v3
172+
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
138173
with:
139174
name: docs
140175
path: site
141176

142177
- name: check GITHUB_REF matches package version
143178
id: check-tag
144-
uses: samuelcolvin/check-python-version@v4.1
179+
uses: samuelcolvin/check-python-version@17d859ba0a6af9ffcaac5c70608fed36ed33e32a # v5.1
145180
with:
146-
version_file_path: devtools/version.py
147-
148-
- name: install
149-
run: pip install build twine
150-
151-
- name: build
152-
run: python -m build
181+
version_file_path: pyproject.toml
153182

154-
- run: twine check dist/*
183+
- run: uv build
155184

156185
- name: upload to pypi
157-
run: twine upload dist/*
158-
env:
159-
TWINE_USERNAME: __token__
160-
TWINE_PASSWORD: ${{ secrets.pypi_token }}
186+
run: uv publish --trusted-publishing always
161187

162188
- name: publish docs
163189
if: '!fromJSON(steps.check-tag.outputs.IS_PRERELEASE)'
164-
uses: cloudflare/wrangler-action@2.0.0
190+
uses: cloudflare/wrangler-action@953926a2e2182532811c01a25e53647d93bf07c0 # v4.1.3
165191
with:
166192
apiToken: ${{ secrets.cloudflare_api_token }}
167-
command: pages publish --project-name=python-devtools --branch=main site
168-
env:
169-
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.cloudflare_account_id }}
193+
accountId: ${{ secrets.cloudflare_account_id }}
194+
command: pages deploy --project-name=python-devtools --branch=main site
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Upload previews
2+
3+
on: # zizmor: ignore[dangerous-triggers] -- workflow_run is used safely here; no code checkout occurs
4+
workflow_run:
5+
workflows: [CI]
6+
types: [completed]
7+
8+
permissions:
9+
# smokeshow sets a commit status with the coverage result
10+
statuses: write
11+
12+
jobs:
13+
upload-previews:
14+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
# DO NOT run actions/checkout here, for security reasons
19+
# For details, refer to https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
20+
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
21+
with:
22+
python-version: '3.12'
23+
24+
- run: pip install smokeshow
25+
26+
- uses: dawidd6/action-download-artifact@eab87c9830c39eff17e5a6eadb20bfb4bc880477 # v27
27+
with:
28+
workflow: ci.yml
29+
commit: ${{ github.event.workflow_run.head_sha }}
30+
31+
- run: smokeshow upload coverage-html
32+
env:
33+
SMOKESHOW_GITHUB_STATUS_DESCRIPTION: Coverage {coverage-percentage}
34+
SMOKESHOW_GITHUB_COVERAGE_THRESHOLD: 90
35+
SMOKESHOW_GITHUB_CONTEXT: coverage
36+
SMOKESHOW_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
SMOKESHOW_GITHUB_PR_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
38+
SMOKESHOW_AUTH_KEY: ${{ secrets.SMOKESHOW_AUTH_KEY }}

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ old-version/
1818
/site/
1919
/site.zip
2020
/build/
21+
.venv/

‎.pre-commit-config.yaml‎

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
repos:
2-
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.3.0
4-
hooks:
5-
- id: check-yaml
6-
- id: check-toml
7-
- id: end-of-file-fixer
8-
- id: trailing-whitespace
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: check-yaml
6+
- id: check-toml
7+
- id: end-of-file-fixer
8+
- id: trailing-whitespace
99

10-
- repo: local
11-
hooks:
12-
- id: ruff
13-
name: Ruff
14-
entry: ruff
15-
args: [--fix, --exit-non-zero-on-fix]
16-
types: [python]
17-
language: system
18-
files: ^devtools/|^tests/
19-
- id: black
20-
name: Black
21-
entry: black
22-
types: [python]
23-
language: system
24-
files: ^devtools/|^tests/
25-
exclude: test_expr_render.py
10+
- repo: https://github.com/zizmorcore/zizmor-pre-commit
11+
rev: v1.30.1
12+
hooks:
13+
- id: zizmor
14+
15+
- repo: local
16+
hooks:
17+
- id: format
18+
name: Format
19+
entry: make
20+
args: [format]
21+
types: [python]
22+
language: system
23+
pass_filenames: false
24+
- id: lint
25+
name: Lint
26+
entry: make
27+
args: [lint]
28+
types: [python]
29+
language: system
30+
pass_filenames: false

0 commit comments

Comments
 (0)