Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre Commits Hooks fails when installed with Python-3.12.1 #207

Open
m4hi2 opened this issue Apr 11, 2024 · 1 comment
Open

Pre Commits Hooks fails when installed with Python-3.12.1 #207

m4hi2 opened this issue Apr 11, 2024 · 1 comment

Comments

@m4hi2
Copy link

m4hi2 commented Apr 11, 2024

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
@cheewoei1997
Copy link

cheewoei1997 commented Apr 19, 2024

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:

  1. Update flake8 = "~7.0.0" and wemake-python-styleguide = "^0.19.2"
  2. poetry update
  3. poetry run pre-commit autoupdate
  4. Push everything to Github

Hope that this solves any future problems that others might face.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants