Skip to content

Commit

Permalink
Poetry enforce specific Python version (#173)
Browse files Browse the repository at this point in the history
* Simplify poetry using correct python version

* Make sure that exactly same Python version is used as for poetry

* Set same Python version enforcement for lint job as well

* Do for all related workflows

* Update python_docs_check.yaml

* Add comment explaining the change
  • Loading branch information
Pijukatel authored Feb 18, 2025
1 parent 3dddb91 commit 22b5eb4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 29 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/python_integration_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ jobs:
- name: Install Python dependencies
run: |
pipx install --python ${{ matrix.python-version }} poetry
# This forces poetry to use specific Python version when installing a project.
# Raises error, if this Python version does not match project specific Python constraints.
poetry config virtualenvs.use-poetry-python true
poetry env use ${{ matrix.python-version }}
make install-dev
- name: Run integration tests
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/python_lint_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ jobs:
- name: Install Python dependencies
run: |
pipx install --python ${{ matrix.python-version }} poetry
# This forces poetry to use specific Python version when installing a project.
# Raises error, if this Python version does not match project specific Python constraints.
poetry config virtualenvs.use-poetry-python true
poetry env use ${{ matrix.python-version }}
make install-dev
- name: Run lint check
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/python_type_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ jobs:
- name: Install Python dependencies
run: |
pipx install --python ${{ matrix.python-version }} poetry
# This forces poetry to use specific Python version when installing a project.
# Raises error, if this Python version does not match project specific Python constraints.
poetry config virtualenvs.use-poetry-python true
poetry env use ${{ matrix.python-version }}
make install-dev
- name: Run type check
Expand Down
33 changes: 4 additions & 29 deletions .github/workflows/python_unit_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,13 @@ jobs:
run: |
pip install poetry
- name: Check Python version against project requirements
shell: python
run: |
import sys
from contextlib import suppress
from poetry.core.constraints.version import parse_constraint
try:
import tomllib
except ImportError:
import tomli as tomllib
config = tomllib.load(open('pyproject.toml', 'rb'))
constraints = []
with suppress(KeyError):
constraints.append(parse_constraint(config['tool']['poetry']['dependencies']['python']))
with suppress(KeyError):
constraints.append(parse_constraint(config['project']['requires-python']))
python_version = parse_constraint('${{ matrix.python-version }}')
if not all(con.allows(python_version) for con in constraints):
print(f'Python version {str(python_version)} is not allowed by project settings', file=sys.stderr)
sys.exit(1)
- name: Uninstall global poetry again
run: |
pip uninstall -y poetry
- name: Install Python dependencies
run: |
pipx install --python ${{ matrix.python-version }} poetry
# This forces poetry to use specific Python version when installing a project.
# Raises error, if this Python version does not match project specific Python constraints.
poetry config virtualenvs.use-poetry-python true
poetry env use ${{ matrix.python-version }}
make install-dev
- name: Run unit tests
Expand Down

0 comments on commit 22b5eb4

Please sign in to comment.