Pre Commits Hooks fails when installed with Python-3.12.1
Hello,
Flake8, add-trailing-comma, pre-commit-hooks, and language-formatters-pre-commit-hooks versions need to be updated. Otherwise fails with following errors on a newly generated project:
boilerplate (master) ✗ poetry run pre-commit install
pre-commit installed at .git/hooks/pre-commit
boilerplate (master) ✗ poetry run pre-commit run -a
Check python ast.........................................................Passed
Trim Trailing Whitespace.................................................Passed
Check Toml...............................................................Passed
Fix End of Files.........................................................Passed
Add trailing commas......................................................Failed
- hook id: add-trailing-comma
- exit code: 1
Traceback (most recent call last):
File "/Users/m4hi2/.cache/pre-commit/repoqonxr4s2/py_env-python3.12/bin/add-trailing-comma", line 5, in <module>
from add_trailing_comma._main import main
ModuleNotFoundError: No module named 'add_trailing_comma'
Traceback (most recent call last):
File "/Users/m4hi2/.cache/pre-commit/repoqonxr4s2/py_env-python3.12/bin/add-trailing-comma", line 5, in <module>
from add_trailing_comma._main import main
ModuleNotFoundError: No module named 'add_trailing_comma'
Traceback (most recent call last):
File "/Users/m4hi2/.cache/pre-commit/repoqonxr4s2/py_env-python3.12/bin/add-trailing-comma", line 5, in <module>
from add_trailing_comma._main import main
ModuleNotFoundError: No module named 'add_trailing_comma'
Traceback (most recent call last):
File "/Users/m4hi2/.cache/pre-commit/repoqonxr4s2/py_env-python3.12/bin/add-trailing-comma", line 5, in <module>
from add_trailing_comma._main import main
ModuleNotFoundError: No module named 'add_trailing_comma'
Traceback (most recent call last):
File "/Users/m4hi2/.cache/pre-commit/repoqonxr4s2/py_env-python3.12/bin/add-trailing-comma", line 5, in <module>
from add_trailing_comma._main import main
ModuleNotFoundError: No module named 'add_trailing_comma'
Traceback (most recent call last):
File "/Users/m4hi2/.cache/pre-commit/repoqonxr4s2/py_env-python3.12/bin/add-trailing-comma", line 5, in <module>
from add_trailing_comma._main import main
ModuleNotFoundError: No module named 'add_trailing_comma'
Traceback (most recent call last):
File "/Users/m4hi2/.cache/pre-commit/repoqonxr4s2/py_env-python3.12/bin/add-trailing-comma", line 5, in <module>
from add_trailing_comma._main import main
ModuleNotFoundError: No module named 'add_trailing_comma'
Traceback (most recent call last):
File "/Users/m4hi2/.cache/pre-commit/repoqonxr4s2/py_env-python3.12/bin/add-trailing-comma", line 5, in <module>
from add_trailing_comma._main import main
ModuleNotFoundError: No module named 'add_trailing_comma'
Pretty format YAML.......................................................Failed
- hook id: pretty-format-yaml
- exit code: 1
Traceback (most recent call last):
File "/Users/m4hi2/.cache/pre-commit/repoh6sog_z7/py_env-python3.12/bin/pretty-format-yaml", line 5, in <module>
from language_formatters_pre_commit_hooks.pretty_format_yaml import pretty_format_yaml
File "/Users/m4hi2/.cache/pre-commit/repoh6sog_z7/py_env-python3.12/lib/python3.12/site-packages/language_formatters_pre_commit_hooks/__init__.py", line 8, in <module>
import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'
Traceback (most recent call last):
File "/Users/m4hi2/.cache/pre-commit/repoh6sog_z7/py_env-python3.12/bin/pretty-format-yaml", line 5, in <module>
from language_formatters_pre_commit_hooks.pretty_format_yaml import pretty_format_yaml
File "/Users/m4hi2/.cache/pre-commit/repoh6sog_z7/py_env-python3.12/lib/python3.12/site-packages/language_formatters_pre_commit_hooks/__init__.py", line 8, in <module>
import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'
autoflake................................................................Passed
Format with Black........................................................Passed
isort....................................................................Passed
Check with Flake8........................................................Failed
- hook id: flake8
- exit code: 1
Traceback (most recent call last):
File "/Users/m4hi2/Library/Caches/pypoetry/virtualenvs/boilerplate-eD2Xgr7s-py3.12/bin/flake8", line 8, in <module>
sys.exit(main())
^^^^^^
File "/Users/m4hi2/Library/Caches/pypoetry/virtualenvs/boilerplate-eD2Xgr7s-py3.12/lib/python3.12/site-packages/flake8/main/cli.py", line 22, in main
app.run(argv)
File "/Users/m4hi2/Library/Caches/pypoetry/virtualenvs/boilerplate-eD2Xgr7s-py3.12/lib/python3.12/site-packages/flake8/main/application.py", line 375, in run
self._run(argv)
File "/Users/m4hi2/Library/Caches/pypoetry/virtualenvs/boilerplate-eD2Xgr7s-py3.12/lib/python3.12/site-packages/flake8/main/application.py", line 363, in _run
self.initialize(argv)
File "/Users/m4hi2/Library/Caches/pypoetry/virtualenvs/boilerplate-eD2Xgr7s-py3.12/lib/python3.12/site-packages/flake8/main/application.py", line 343, in initialize
self.find_plugins(config_finder)
File "/Users/m4hi2/Library/Caches/pypoetry/virtualenvs/boilerplate-eD2Xgr7s-py3.12/lib/python3.12/site-packages/flake8/main/application.py", line 157, in find_plugins
self.check_plugins = plugin_manager.Checkers(local_plugins.extension)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/m4hi2/Library/Caches/pypoetry/virtualenvs/boilerplate-eD2Xgr7s-py3.12/lib/python3.12/site-packages/flake8/plugins/manager.py", line 363, in __init__
self.manager = PluginManager(
^^^^^^^^^^^^^^
File "/Users/m4hi2/Library/Caches/pypoetry/virtualenvs/boilerplate-eD2Xgr7s-py3.12/lib/python3.12/site-packages/flake8/plugins/manager.py", line 243, in __init__
self._load_entrypoint_plugins()
File "/Users/m4hi2/Library/Caches/pypoetry/virtualenvs/boilerplate-eD2Xgr7s-py3.12/lib/python3.12/site-packages/flake8/plugins/manager.py", line 261, in _load_entrypoint_plugins
eps = importlib_metadata.entry_points().get(self.namespace, ())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'EntryPoints' object has no attribute 'get'
Validate types with MyPy.................................................Passed
Workaround, update Flake8 on pyproject.toml file, run poetry update and to update pre-commit hooks run:
poetry run pre-commit autoupdate
I had the same problem and managed to solve this. Thanks, @m4hi2!
My computer specs are Macbook Pro 13-inch, M1 2020, 8GB RAM, running Sonoma 14.2.1 and Python 3.12.1. I had issues pushing to my Github repository.
Here's what I did:
- Update
flake8 = "~7.0.0"andwemake-python-styleguide = "^0.19.2" poetry updatepoetry run pre-commit autoupdate- Push everything to Github
Hope that this solves any future problems that others might face.
This issue should be resolved in a new version, since the template is no longer use flake. It has been replaced with ruff.