Skip to content

Commit fd656d0

Browse files
authored
Merge branch 'main' into add-zizmor
2 parents 040ad8f + a670d60 commit fd656d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+550
-3013
lines changed

.codecov.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# -- repository yaml --
2+
3+
# Explicitly wait for all jobs to finish, as wait_for_ci prematurely triggers.
4+
# See https://github.com/python-trio/trio/issues/2689
5+
codecov:
6+
notify:
7+
# This number needs to be changed whenever the number of runs in CI is changed.
8+
# Another option is codecov-cli: https://github.com/codecov/codecov-cli#send-notifications
9+
after_n_builds: 31
10+
wait_for_ci: false
11+
notify_error: true # if uploads fail, replace cov comment with a comment with errors.
12+
require_ci_to_pass: false
13+
14+
# Publicly exposing the token has some small risks from mistakes or malicious actors.
15+
# See https://docs.codecov.com/docs/codecov-tokens for correctly configuring it.
16+
token: 87cefb17-c44b-4f2f-8b30-1fff5769ce46
17+
18+
# only post PR comment if coverage changes
19+
comment:
20+
require_changes: true
21+
22+
coverage:
23+
# required range
24+
precision: 5
25+
round: down
26+
range: 100..100
27+
status:
28+
project:
29+
default:
30+
target: 100%
31+
patch:
32+
default:
33+
target: 100% # require patches to be 100%

.github/workflows/ci.yml

Lines changed: 198 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,133 @@ concurrency:
1414
group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && format('-{0}', github.sha) || '' }}
1515
cancel-in-progress: true
1616

17+
env:
18+
dists-artifact-name: python-package-distributions
19+
dist-name: trio
20+
1721
jobs:
22+
build:
23+
name: 👷 dists
24+
25+
runs-on: ubuntu-latest
26+
27+
outputs:
28+
dist-version: ${{ steps.dist-version.outputs.version }}
29+
sdist-artifact-name: ${{ steps.artifact-name.outputs.sdist }}
30+
wheel-artifact-name: ${{ steps.artifact-name.outputs.wheel }}
31+
32+
steps:
33+
- name: Switch to using Python 3.11
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version: 3.11
37+
38+
- name: Grab the source from Git
39+
uses: actions/checkout@v4
40+
41+
- name: Get the dist version
42+
id: dist-version
43+
run: >-
44+
echo "version=$(
45+
grep ^__version__ src/trio/_version.py
46+
| sed 's#__version__ = "\([^"]\+\)"#\1#'
47+
)"
48+
>> "${GITHUB_OUTPUT}"
49+
50+
- name: Set the expected dist artifact names
51+
id: artifact-name
52+
run: |
53+
echo 'sdist=${{ env.dist-name }}-*.tar.gz' >> "${GITHUB_OUTPUT}"
54+
echo 'wheel=${{
55+
env.dist-name
56+
}}-*-py3-none-any.whl' >> "${GITHUB_OUTPUT}"
57+
58+
- name: Install build
59+
run: python -Im pip install build
60+
61+
- name: Build dists
62+
run: python -Im build
63+
- name: Verify that the artifacts with expected names got created
64+
run: >-
65+
ls -1
66+
dist/${{ steps.artifact-name.outputs.sdist }}
67+
dist/${{ steps.artifact-name.outputs.wheel }}
68+
- name: Store the distribution packages
69+
uses: actions/upload-artifact@v4
70+
with:
71+
name: ${{ env.dists-artifact-name }}
72+
# NOTE: Exact expected file names are specified here
73+
# NOTE: as a safety measure — if anything weird ends
74+
# NOTE: up being in this dir or not all dists will be
75+
# NOTE: produced, this will fail the workflow.
76+
path: |
77+
dist/${{ steps.artifact-name.outputs.sdist }}
78+
dist/${{ steps.artifact-name.outputs.wheel }}
79+
retention-days: 5
80+
81+
- name: >-
82+
Smoke-test:
83+
retrieve the project source from an sdist inside the GHA artifact
84+
uses: re-actors/checkout-python-sdist@release/v2
85+
with:
86+
source-tarball-name: ${{ steps.artifact-name.outputs.sdist }}
87+
workflow-artifact-name: ${{ env.dists-artifact-name }}
88+
89+
- name: >-
90+
Smoke-test: move the sdist-retrieved dir into sdist-src
91+
run: |
92+
mv -v '${{ github.workspace }}' '${{ runner.temp }}/sdist-src'
93+
mkdir -pv '${{ github.workspace }}'
94+
mv -v '${{ runner.temp }}/sdist-src' '${{ github.workspace }}/sdist-src'
95+
shell: bash -eEuo pipefail {0}
96+
97+
- name: >-
98+
Smoke-test: grab the source from Git into git-src
99+
uses: actions/checkout@v4
100+
with:
101+
path: git-src
102+
103+
- name: >-
104+
Smoke-test: install test requirements from the Git repo
105+
run: >-
106+
python -Im
107+
pip install -c test-requirements.txt -r test-requirements.txt
108+
shell: bash -eEuo pipefail {0}
109+
working-directory: git-src
110+
111+
- name: >-
112+
Smoke-test: collect tests from the Git repo
113+
env:
114+
PYTHONPATH: src/
115+
run: >-
116+
pytest --collect-only -qq .
117+
| sort
118+
| tee collected-tests
119+
shell: bash -eEuo pipefail {0}
120+
working-directory: git-src
121+
122+
- name: >-
123+
Smoke-test: collect tests from the sdist tarball
124+
env:
125+
PYTHONPATH: src/
126+
run: >-
127+
pytest --collect-only -qq .
128+
| sort
129+
| tee collected-tests
130+
shell: bash -eEuo pipefail {0}
131+
working-directory: sdist-src
132+
133+
- name: >-
134+
Smoke-test:
135+
verify that all the tests from Git are included in the sdist
136+
run: diff --unified sdist-src/collected-tests git-src/collected-tests
137+
shell: bash -eEuo pipefail {0}
138+
18139
Windows:
19140
name: 'Windows (${{ matrix.python }}, ${{ matrix.arch }}${{ matrix.extra_name }})'
141+
needs:
142+
- build
143+
20144
timeout-minutes: 20
21145
runs-on: 'windows-latest'
22146
strategy:
@@ -58,10 +182,11 @@ jobs:
58182
|| false
59183
}}
60184
steps:
61-
- name: Checkout
62-
uses: actions/checkout@v4
185+
- name: Retrieve the project source from an sdist inside the GHA artifact
186+
uses: re-actors/checkout-python-sdist@release/v2
63187
with:
64-
persist-credentials: false
188+
source-tarball-name: ${{ needs.build.outputs.sdist-artifact-name }}
189+
workflow-artifact-name: ${{ env.dists-artifact-name }}
65190
- name: Setup python
66191
uses: actions/setup-python@v5
67192
with:
@@ -87,12 +212,18 @@ jobs:
87212
uses: codecov/codecov-action@v3
88213
with:
89214
directory: empty
90-
token: 87cefb17-c44b-4f2f-8b30-1fff5769ce46
91215
name: Windows (${{ matrix.python }}, ${{ matrix.arch }}${{ matrix.extra_name }})
216+
# multiple flags is marked as an error in codecov UI, but is actually fine
217+
# https://github.com/codecov/feedback/issues/567
92218
flags: Windows,${{ matrix.python }}
219+
# this option cannot be set in .codecov.yml
220+
fail_ci_if_error: true
93221

94222
Ubuntu:
95223
name: 'Ubuntu (${{ matrix.python }}${{ matrix.extra_name }})'
224+
needs:
225+
- build
226+
96227
timeout-minutes: 10
97228
runs-on: 'ubuntu-latest'
98229
strategy:
@@ -120,7 +251,14 @@ jobs:
120251
|| false
121252
}}
122253
steps:
123-
- name: Checkout
254+
- name: Retrieve the project source from an sdist inside the GHA artifact
255+
if: matrix.check_formatting != '1'
256+
uses: re-actors/checkout-python-sdist@release/v2
257+
with:
258+
source-tarball-name: ${{ needs.build.outputs.sdist-artifact-name }}
259+
workflow-artifact-name: ${{ env.dists-artifact-name }}
260+
- name: Grab the source from Git
261+
if: matrix.check_formatting == '1'
124262
uses: actions/checkout@v4
125263
with:
126264
persist-credentials: false
@@ -135,16 +273,21 @@ jobs:
135273
env:
136274
CHECK_FORMATTING: '${{ matrix.check_formatting }}'
137275
NO_TEST_REQUIREMENTS: '${{ matrix.no_test_requirements }}'
138-
- if: always()
276+
- if: >-
277+
always()
278+
&& matrix.check_formatting != '1'
139279
uses: codecov/codecov-action@v3
140280
with:
141281
directory: empty
142-
token: 87cefb17-c44b-4f2f-8b30-1fff5769ce46
143282
name: Ubuntu (${{ matrix.python }}${{ matrix.extra_name }})
144283
flags: Ubuntu,${{ matrix.python }}
284+
fail_ci_if_error: true
145285
146286
macOS:
147287
name: 'macOS (${{ matrix.python }})'
288+
needs:
289+
- build
290+
148291
timeout-minutes: 15
149292
runs-on: 'macos-latest'
150293
strategy:
@@ -161,10 +304,11 @@ jobs:
161304
|| false
162305
}}
163306
steps:
164-
- name: Checkout
165-
uses: actions/checkout@v4
307+
- name: Retrieve the project source from an sdist inside the GHA artifact
308+
uses: re-actors/checkout-python-sdist@release/v2
166309
with:
167-
persist-credentials: false
310+
source-tarball-name: ${{ needs.build.outputs.sdist-artifact-name }}
311+
workflow-artifact-name: ${{ env.dists-artifact-name }}
168312
- name: Setup python
169313
uses: actions/setup-python@v5
170314
with:
@@ -177,40 +321,51 @@ jobs:
177321
uses: codecov/codecov-action@v3
178322
with:
179323
directory: empty
180-
token: 87cefb17-c44b-4f2f-8b30-1fff5769ce46
181324
name: macOS (${{ matrix.python }})
182325
flags: macOS,${{ matrix.python }}
326+
fail_ci_if_error: true
183327

184328
# run CI on a musl linux
185329
Alpine:
186330
name: "Alpine"
331+
needs:
332+
- build
333+
187334
runs-on: ubuntu-latest
188335
container: alpine
189336
steps:
190-
- name: Checkout
191-
uses: actions/checkout@v4
192-
with:
193-
persist-credentials: false
194337
- name: Install necessary packages
195338
# can't use setup-python because that python doesn't seem to work;
196339
# `python3-dev` (rather than `python:alpine`) for some ctypes reason,
197340
# `nodejs` for pyright (`node-env` pulls in nodejs but that takes a while and can time out the test).
198341
# `perl` for a platform independent `sed -i` alternative
199342
run: apk update && apk add python3-dev bash nodejs perl
343+
- name: Retrieve the project source from an sdist inside the GHA artifact
344+
# must be after `apk add` because it relies on `bash` existing
345+
uses: re-actors/checkout-python-sdist@release/v2
346+
with:
347+
source-tarball-name: ${{ needs.build.outputs.sdist-artifact-name }}
348+
workflow-artifact-name: ${{ env.dists-artifact-name }}
200349
- name: Enter virtual environment
201350
run: python -m venv .venv
202351
- name: Run tests
203352
run: source .venv/bin/activate && ./ci.sh
353+
- name: Get Python version for codecov flag
354+
id: get-version
355+
run: echo "version=$(python -V | cut -d' ' -f2 | cut -d'.' -f1,2)" >> "${GITHUB_OUTPUT}"
204356
- if: always()
205357
uses: codecov/codecov-action@v3
206358
with:
207359
directory: empty
208-
token: 87cefb17-c44b-4f2f-8b30-1fff5769ce46
209360
name: Alpine
210-
flags: Alpine,3.12
361+
flags: Alpine,${{ steps.get-version.outputs.version }}
362+
fail_ci_if_error: true
211363

212364
Cython:
213365
name: "Cython"
366+
needs:
367+
- build
368+
214369
runs-on: ubuntu-latest
215370
strategy:
216371
fail-fast: false
@@ -225,26 +380,46 @@ jobs:
225380
- python: '3.13' # We support running cython3 on 3.13
226381
cython: '>=3' # cython 3 (or greater)
227382
steps:
228-
- name: Checkout
229-
uses: actions/checkout@v4
383+
- name: Retrieve the project source from an sdist inside the GHA artifact
384+
uses: re-actors/checkout-python-sdist@release/v2
230385
with:
231-
persist-credentials: false
386+
source-tarball-name: ${{ needs.build.outputs.sdist-artifact-name }}
387+
workflow-artifact-name: ${{ env.dists-artifact-name }}
232388
- name: Setup python
233389
uses: actions/setup-python@v5
234390
with:
235391
python-version: '${{ matrix.python }}'
236392
cache: pip
237393
# setuptools is needed to get distutils on 3.12, which cythonize requires
238394
- name: install trio and setuptools
239-
run: python -m pip install --upgrade pip . setuptools
395+
run: python -m pip install --upgrade pip . setuptools 'coverage[toml]'
396+
397+
- name: add cython plugin to the coveragepy config
398+
run: >-
399+
sed -i 's#plugins\s=\s\[\]#plugins = ["Cython.Coverage"]#'
400+
pyproject.toml
240401
241402
- name: install cython & compile pyx file
403+
env:
404+
CFLAGS: ${{ env.CFLAGS }} -DCYTHON_TRACE_NOGIL=1
242405
run: |
243406
python -m pip install "cython${{ matrix.cython }}"
244-
cythonize --inplace tests/cython/test_cython.pyx
407+
cythonize --inplace -X linetrace=True tests/cython/test_cython.pyx
245408
246409
- name: import & run module
247-
run: python -c 'import tests.cython.test_cython'
410+
run: coverage run -m tests.cython.run_test_cython
411+
412+
- name: get Python version for codecov flag
413+
id: get-version
414+
run: >-
415+
echo "version=$(python -V | cut -d' ' -f2 | cut -d'.' -f1,2)"
416+
>> "${GITHUB_OUTPUT}"
417+
- if: always()
418+
uses: codecov/codecov-action@v5
419+
with:
420+
name: Cython
421+
flags: Cython,${{ steps.get-version.outputs.version }}
422+
fail_ci_if_error: true
248423

249424
# https://github.com/marketplace/actions/alls-green#why
250425
check: # This job does nothing and is only used for the branch protection

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# In case somebody wants to restore the directory for local testing
2+
notes-to-self/
3+
14
# Project-specific generated files
25
docs/build/
36

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ repos:
2222
hooks:
2323
- id: black
2424
- repo: https://github.com/astral-sh/ruff-pre-commit
25-
rev: v0.8.2
25+
rev: v0.8.3
2626
hooks:
2727
- id: ruff
2828
types: [file]

0 commit comments

Comments
 (0)