Skip to content

Commit 22b5eb4

Browse files
authored
Poetry enforce specific Python version (#173)
* 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
1 parent 3dddb91 commit 22b5eb4

File tree

4 files changed

+16
-29
lines changed

4 files changed

+16
-29
lines changed

.github/workflows/python_integration_tests.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ jobs:
8080
- name: Install Python dependencies
8181
run: |
8282
pipx install --python ${{ matrix.python-version }} poetry
83+
# This forces poetry to use specific Python version when installing a project.
84+
# Raises error, if this Python version does not match project specific Python constraints.
85+
poetry config virtualenvs.use-poetry-python true
86+
poetry env use ${{ matrix.python-version }}
8387
make install-dev
8488
8589
- name: Run integration tests

.github/workflows/python_lint_check.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ jobs:
2323
- name: Install Python dependencies
2424
run: |
2525
pipx install --python ${{ matrix.python-version }} poetry
26+
# This forces poetry to use specific Python version when installing a project.
27+
# Raises error, if this Python version does not match project specific Python constraints.
28+
poetry config virtualenvs.use-poetry-python true
29+
poetry env use ${{ matrix.python-version }}
2630
make install-dev
2731
2832
- name: Run lint check

.github/workflows/python_type_check.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ jobs:
2323
- name: Install Python dependencies
2424
run: |
2525
pipx install --python ${{ matrix.python-version }} poetry
26+
# This forces poetry to use specific Python version when installing a project.
27+
# Raises error, if this Python version does not match project specific Python constraints.
28+
poetry config virtualenvs.use-poetry-python true
29+
poetry env use ${{ matrix.python-version }}
2630
make install-dev
2731
2832
- name: Run type check

.github/workflows/python_unit_tests.yaml

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,13 @@ jobs:
3232
run: |
3333
pip install poetry
3434
35-
- name: Check Python version against project requirements
36-
shell: python
37-
run: |
38-
import sys
39-
from contextlib import suppress
40-
from poetry.core.constraints.version import parse_constraint
41-
42-
try:
43-
import tomllib
44-
except ImportError:
45-
import tomli as tomllib
46-
47-
config = tomllib.load(open('pyproject.toml', 'rb'))
48-
constraints = []
49-
50-
with suppress(KeyError):
51-
constraints.append(parse_constraint(config['tool']['poetry']['dependencies']['python']))
52-
with suppress(KeyError):
53-
constraints.append(parse_constraint(config['project']['requires-python']))
54-
55-
python_version = parse_constraint('${{ matrix.python-version }}')
56-
if not all(con.allows(python_version) for con in constraints):
57-
print(f'Python version {str(python_version)} is not allowed by project settings', file=sys.stderr)
58-
sys.exit(1)
59-
60-
- name: Uninstall global poetry again
61-
run: |
62-
pip uninstall -y poetry
63-
6435
- name: Install Python dependencies
6536
run: |
6637
pipx install --python ${{ matrix.python-version }} poetry
38+
# This forces poetry to use specific Python version when installing a project.
39+
# Raises error, if this Python version does not match project specific Python constraints.
40+
poetry config virtualenvs.use-poetry-python true
41+
poetry env use ${{ matrix.python-version }}
6742
make install-dev
6843
6944
- name: Run unit tests

0 commit comments

Comments
 (0)