Skip to content

Commit 4cb201f

Browse files
authored
Optimise Python tooling infrastructure (#359)
* uv package management (and cache) - over poetry and pre-commit * uv Python management (and cache) - over setup-python * uv build backend over poetry * ruff linter and formatter over black, isort and flake8 * Renovate automated dependency updates for pre-commit * Drop end-of-line Python 3.8 and 3.9 and add latest stable 3.14 * Python 3.10+ native type hints e.g. list over typing.List * Closes #29
1 parent 4467e09 commit 4cb201f

37 files changed

+800
-676
lines changed

.github/renovate.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
33
"extends": [
4-
"github>cucumber/renovate-config"
4+
"github>cucumber/renovate-config",
5+
":enablePreCommit"
56
]
67
}

.github/workflows/release-pypi.yaml

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ name: Release Python
22

33
on:
44
push:
5-
branches: [ release/* ]
5+
branches: [release/*]
66

77
jobs:
8-
release:
9-
name: Release
8+
publish-pypi:
9+
name: Publish PyPI Package
1010
runs-on: ubuntu-latest
1111
environment: Release
1212
permissions:
@@ -15,23 +15,17 @@ jobs:
1515
run:
1616
working-directory: python
1717
steps:
18-
- name: Checkout code
19-
uses: actions/checkout@v5
20-
- name: Set up Python 3.10
21-
uses: actions/setup-python@v6
18+
- uses: actions/checkout@v5
19+
20+
- name: Install uv and set the python version
21+
uses: astral-sh/setup-uv@v7
2222
with:
23+
enable-cache: true
2324
python-version: "3.14"
24-
25-
- name: Show Python version
26-
run: python --version
25+
version: "0.9.1"
2726

2827
- name: Build package
29-
run: |
30-
python -m pip install build twine
31-
python -m build
32-
twine check --strict dist/*
28+
run: uv build
3329

34-
- name: Publish package distributions to PyPI
35-
uses: pypa/gh-action-pypi-publish@release/v1
36-
with:
37-
packages-dir: python/dist
30+
- name: Publish package
31+
run: uv publish

.github/workflows/test-python.yml

Lines changed: 23 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,76 +11,50 @@ on:
1111

1212
jobs:
1313
test-python-linting:
14+
runs-on: "ubuntu-latest"
15+
strategy:
16+
fail-fast: false
1417
defaults:
1518
run:
1619
working-directory: python
17-
runs-on: ${{ matrix.os }}
18-
strategy:
19-
fail-fast: false
20-
matrix:
21-
os:
22-
- ubuntu-latest
23-
python-version: ["3.10"]
2420
steps:
2521
- uses: actions/checkout@v5
26-
- name: Set up Python ${{ matrix.python-version }}
27-
uses: actions/setup-python@v6
22+
23+
- name: Install uv and set the python version
24+
uses: astral-sh/setup-uv@v6
2825
with:
29-
python-version: ${{ matrix.python-version }}
26+
enable-cache: true
27+
python-version: "3.14"
28+
version: "0.9.1"
29+
3030
- name: Linting
31-
run: |
32-
python -m pip install pre-commit
33-
pre-commit run --all-files
34-
31+
run: uvx pre-commit run --all-files
32+
3533
test-python:
3634
runs-on: ${{ matrix.os }}
37-
defaults:
38-
run:
39-
working-directory: python
40-
shell: bash
4135
strategy:
4236
fail-fast: false
4337
matrix:
4438
os:
4539
- ubuntu-latest
46-
python-version: ["3.9", "3.10", "3.11", "3.12"]
40+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
4741
include:
4842
- os: windows-latest
4943
python-version: "3.10"
5044
- os : macos-latest
5145
python-version: "3.10"
46+
defaults:
47+
run:
48+
working-directory: python
5249
steps:
5350
- uses: actions/checkout@v5
54-
- name: Set up Python ${{ matrix.python-version }}
55-
uses: actions/setup-python@v6
51+
52+
- name: Install uv and set the python version
53+
uses: astral-sh/setup-uv@v7
5654
with:
55+
enable-cache: true
5756
python-version: ${{ matrix.python-version }}
58-
- name: Get full Python version
59-
id: full-python-version
60-
run: echo "version=$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")" >> $GITHUB_OUTPUT
61-
- name: Bootstrap poetry
62-
run: |
63-
curl -sL https://install.python-poetry.org | python - -y ${{ matrix.bootstrap-args }}
64-
- name: Update PATH
65-
if: ${{ matrix.os != 'windows-latest' }}
66-
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
67-
- name: Update Path for Windows
68-
if: ${{ matrix.os == 'windows-latest' }}
69-
run: echo "$APPDATA\Python\Scripts" >> $GITHUB_PATH
70-
- name: Configure poetry
71-
run: poetry config virtualenvs.in-project true
72-
- name: Set up cache
73-
uses: actions/cache@v4
74-
id: cache
75-
with:
76-
path: .venv
77-
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
78-
- name: Ensure cache is healthy
79-
if: steps.cache.outputs.cache-hit == 'true'
80-
run: timeout 10s poetry rupoen pip --version || rm -rf .venv
81-
- name: Install dependencies
82-
run: poetry install
83-
- name: Install pytest plugin
84-
run: poetry run pip install pytest-github-actions-annotate-failures
57+
version: "0.9.1"
58+
8559
- name: Run pytest
86-
run: poetry run python -m pytest -p no:sugar -q tests/
60+
run: uv run --with pytest-github-actions-annotate-failures pytest -p no:sugar --quiet tests/

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
- [Ruby] Minor cosmetic / CI changes for development (Nothing front-facing)
1111
- [Python] PEP 639 licence metadata specification ([#361](https://github.com/cucumber/cucumber-expressions/pull/361))
1212

13+
### Removed
14+
- [Python] Remove support for end-of-life Python 3.8 and 3.9 ([#359](https://github.com/cucumber/cucumber-expressions/pull/359))
15+
1316
## [18.0.1] - 2024-10-28
1417
### Fixed
1518
- [Python] Release process didn't release to pypi correctly

python/.pre-commit-config.yaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
repos:
2-
- repo: https://github.com/psf/black
3-
rev: 22.3.0
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.14.0
44
hooks:
5-
- id: black
6-
- repo: https://github.com/PyCQA/flake8
7-
rev: 4.0.1
5+
- id: ruff-check
6+
args: [--fix]
7+
- id: ruff-format
8+
- repo: https://github.com/astral-sh/uv-pre-commit
9+
rev: 0.9.1
810
hooks:
9-
- id: flake8
10-
args: ['--max-line-length=130','--ignore=E203,W503']
11+
# Ensure the uv lock file is up to date
12+
- id: uv-lock
13+
files: pyproject.toml
14+
args: [--project, python]

python/CONTRIBUTING.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Contributing
2+
3+
Thank you for your interest in contributing to `cucumber-expressions`, a simpler alternative to regular expressions! This guide will help you get set up and understand our development workflow.
4+
5+
## 🚀 Quick Start
6+
7+
Using [`uv`](https://docs.astral.sh/uv/) is recommended for contributing with this project, though you can also install dependencies via `pip` (use `pip install . --group dev` with v25.1+) or your preferred tool.
8+
9+
First change to the directory containing the Python implementation and install development dependencies.
10+
11+
```console
12+
cd python
13+
uv sync
14+
```
15+
16+
At the root of the repository, install pre-commit hooks to automatically validate linting and formatting of your Python code with every commit.
17+
18+
```console
19+
cd ..
20+
uv run pre-commit install
21+
```
22+
23+
Unit tests can run via `pytest`.
24+
25+
```console
26+
uv run pytest
27+
```

python/README.md

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,3 @@
11
# Cucumber Expressions for Python
22

33
[The main docs are here](https://github.com/cucumber/cucumber-expressions#readme).
4-
5-
## Build system
6-
7-
This project uses [Poetry](https://python-poetry.org/) as its build system.
8-
In order to develop on this project, please install Poetry as per your system's instructions on the link above.
9-
10-
## Tests
11-
12-
The test suite uses `pytest` as its testing Framework.
13-
14-
15-
### Preparing to run the tests
16-
17-
In order to set up your dev environment, run the following command from this project's directory:
18-
19-
``` python
20-
poetry install
21-
```
22-
It will install all package and development requirements, and once that is done it will do a dev-install of the source code.
23-
24-
You only need to run it once, code changes will propagate directly and do not require running the install again.
25-
26-
27-
### Running the tests
28-
29-
`pytest` automatically picks up files in the current directory or any subdirectories that have the prefix or suffix of `test_*.py`.
30-
Test function names must start with `test*`.
31-
Test class names must start with `Test*`.
32-
33-
To run all tests:
34-
35-
``` python
36-
poetry run pytest
37-
```
38-

0 commit comments

Comments
 (0)