File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 28
28
with :
29
29
python-version : ${{ matrix.python-version }}
30
30
31
+ - name : Install Poetry for version checking
32
+ run : |
33
+ pip install poetry
34
+
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
+
31
64
- name : Install Python dependencies
32
65
run : |
33
66
pipx install --python ${{ matrix.python-version }} poetry
You can’t perform that action at this time.
0 commit comments