Skip to content

Commit b7b273c

Browse files
Update 'Building and testing Python' for Python 3.13 (#34915)
Co-authored-by: Alex Nguyen <150945400+nguyenalex836@users.noreply.github.com>
1 parent 4a4ee6d commit b7b273c

File tree

1 file changed

+26
-28
lines changed

1 file changed

+26
-28
lines changed

content/actions/use-cases-and-examples/building-and-testing/building-and-testing-python.md

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,21 @@ We recommend that you have a basic understanding of Python, and pip. For more in
7070

7171
steps:
7272
- uses: {% data reusables.actions.action-checkout %}
73-
- name: Set up Python 3.10
73+
- name: Set up Python 3.13
7474
uses: {% data reusables.actions.action-setup-python %}
7575
with:
76-
python-version: "3.10"
76+
python-version: "3.13"
7777
- name: Install dependencies
7878
run: |
7979
python -m pip install --upgrade pip
80-
pip install flake8 pytest
80+
pip install ruff pytest
8181
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
82-
- name: Lint with flake8
82+
- name: Lint and format Python code with ruff
8383
run: |
84-
# stop the build if there are Python syntax errors or undefined names
85-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
86-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
87-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
84+
# Lint with the default set of ruff rules with GitHub Annotations
85+
ruff check --format=github --target-version=py39
86+
# Verify the code is properly formatted
87+
ruff format --diff --target-version=py39
8888
- name: Test with pytest
8989
run: |
9090
pytest
@@ -136,7 +136,7 @@ jobs:
136136
runs-on: ubuntu-latest
137137
strategy:
138138
matrix:
139-
python-version: ["pypy3.9", "pypy3.10", "3.9", "3.10", "3.11", "3.12"]
139+
python-version: ["pypy3.10", "3.9", "3.10", "3.11", "3.12", "3.13"]
140140
141141
steps:
142142
- uses: {% data reusables.actions.action-checkout %}
@@ -151,7 +151,7 @@ jobs:
151151

152152
### Using a specific Python version
153153

154-
You can configure a specific version of Python. For example, 3.10. Alternatively, you can use semantic version syntax to get the latest minor release. This example uses the latest minor release of Python 3.
154+
You can configure a specific version of Python. For example, 3.12. Alternatively, you can use semantic version syntax to get the latest minor release. This example uses the latest minor release of Python 3.
155155

156156
```yaml copy
157157
name: Python package
@@ -180,7 +180,7 @@ jobs:
180180

181181
### Excluding a version
182182

183-
If you specify a version of Python that is not available, `setup-python` fails with an error such as: `##[error]Version 3.6 with arch x64 not found`. The error message includes the available versions.
183+
If you specify a version of Python that is not available, `setup-python` fails with an error such as: `##[error]Version 3.7 with arch x64 not found`. The error message includes the available versions.
184184

185185
You can also use the `exclude` keyword in your workflow if there is a configuration of Python that you do not wish to run. For more information, see "[AUTOTITLE](/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategy)."
186186

@@ -196,12 +196,12 @@ jobs:
196196
strategy:
197197
matrix:
198198
os: [ubuntu-latest, macos-latest, windows-latest]
199-
python-version: ["3.9", "3.10", "3.11", "pypy3.9", "pypy3.10"]
199+
python-version: ["3.9", "3.11", "3.13", "pypy3.10"]
200200
exclude:
201201
- os: macos-latest
202-
python-version: "3.9"
202+
python-version: "3.11"
203203
- os: windows-latest
204-
python-version: "3.9"
204+
python-version: "3.11"
205205
```
206206

207207
### Using the default Python version
@@ -259,7 +259,7 @@ steps:
259259
- uses: {% data reusables.actions.action-checkout %}
260260
- uses: {% data reusables.actions.action-setup-python %}
261261
with:
262-
python-version: '3.11'
262+
python-version: '3.12'
263263
cache: 'pip'
264264
- run: pip install -r requirements.txt
265265
- run: pip test
@@ -294,9 +294,9 @@ steps:
294294
pytest tests.py --doctest-modules --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
295295
```
296296

297-
### Using Ruff to lint code
297+
### Using Ruff to lint and/or format code
298298

299-
The following example installs or upgrades `ruff` and uses it to lint all files. For more information, see [Ruff](https://beta.ruff.rs/docs).
299+
The following example installs or upgrades `ruff` and uses it to lint all files. For more information, see [Ruff](https://docs.astral.sh/ruff).
300300

301301
```yaml copy
302302
steps:
@@ -305,18 +305,16 @@ steps:
305305
uses: {% data reusables.actions.action-setup-python %}
306306
with:
307307
python-version: '3.x'
308-
- name: Install dependencies
309-
run: |
310-
python -m pip install --upgrade pip
311-
pip install -r requirements.txt
312-
- name: Lint with Ruff
313-
run: |
314-
pip install ruff
315-
ruff check --output-format=github .
308+
- name: Install the code linting and formatting tool Ruff
309+
run: pipx install ruff
310+
- name: Lint code with Ruff
311+
run: ruff check --output-format=github --target-version=py39
312+
- name: Check code formatting with Ruff
313+
run: ruff format --diff --target-version=py39
316314
continue-on-error: true
317315
```
318316

319-
The linting step has `continue-on-error: true` set. This will keep the workflow from failing if the linting step doesn't succeed. Once you've addressed all of the linting errors, you can remove this option so the workflow will catch new issues.
317+
The formatting step has `continue-on-error: true` set. This will keep the workflow from failing if the formatting step doesn't succeed. Once you've addressed all of the formatting errors, you can remove this option so the workflow will catch new issues.
320318

321319
### Running tests with tox
322320

@@ -333,7 +331,7 @@ jobs:
333331
runs-on: ubuntu-latest
334332
strategy:
335333
matrix:
336-
python: ["3.9", "3.10", "3.11"]
334+
python: ["3.9", "3.11", "3.13"]
337335
338336
steps:
339337
- uses: {% data reusables.actions.action-checkout %}
@@ -365,7 +363,7 @@ jobs:
365363
runs-on: ubuntu-latest
366364
strategy:
367365
matrix:
368-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
366+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
369367
370368
steps:
371369
- uses: {% data reusables.actions.action-checkout %}

0 commit comments

Comments
 (0)