After changing from Python 3.10.0 to 3.12.3 our workflow fails with:
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.12.3/x64/bin/pylint", line 8, in <module>
sys.exit(run_pylint())
^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/pylint/__init__.py", line 25, in run_pylint
PylintRun(argv or sys.argv[1:])
File "/opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/pylint/lint/run.py", line 207, in __init__
linter.check(args)
File "/opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/pylint/lint/pylinter.py", line 650, in check
check_parallel(
File "/opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/pylint/lint/parallel.py", line 152, in check_parallel
for (
File "/opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/multiprocessing/pool.py", line 873, in next
raise value
astroid.exceptions.AstroidBuildingError: Building error when trying to create ast representation of module 'program_name.core.startup_rest'
Error: Process completed with exit code 1.
name: linting
on: [push]
jobs:
linting-job:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.12.3
uses: actions/setup-python@v4
with:
python-version: '3.12.3'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
- name: ansible_lint
run: ansible-lint resources/playbook/roles/program_name/tasks/main.yaml
- name: pylint_lint
run: pylint program_name
in the pylint_lint step. I am unsure what causes this. One source suggested to add __init__.py
to all folders which I have now added, but this didn't fix the issue.
The pylint version set by the requirements-dev.txt is pylint==2.14.5
In the past we used Python 3.10.0 for our linting, which worked fine, but that caused issues when we switched to Python 3.12.03 in our working environment. Python 3.12.03 apparently knows more pylint errors. Disabling some of those at certain places (aka pylint: disable=...
) raises an error on workflow execution with Python 3.10.0, because it doesn't know them.
Pylint 2.14.5 is not supported for Python 3.12; it's only supported for Python versions 3.7, 3.8, 3.9 and 3.10. It has not been tested with 3.12: it may work, it may fail (and the latter seems to be the case).
So you should upgrade your Pylint version to a Python 3.12 compatible version (pip --upgrade pylint
should do that for you).
In fact, when you upgrade Python by a minor or major version (not so much a bugfix release), you should upgrade all your packages to match the new version: you can't rely on previously installed packages to be forward-compatible with newer Python versions (these packages could never even have been tested against that newer Python version).