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

[BUG] pre-commit hook fails on Python 3.12 because of deprecated pkg_resources #646

Open
ldallmayr opened this issue Nov 26, 2023 · 3 comments
Labels

Comments

@ldallmayr
Copy link

ldallmayr commented Nov 26, 2023

Describe the bug
On Python 3.12 the pre-commit hook fails with ModuleNotFoundError: No module named 'pkg_resources' on Python 3.12.
The usage pkg_resources has been deprecated and should be replaced by their equivalent importlib modules.

To Reproduce

  1. Install Python 3.12 (or use container image)
  2. Run pip install pre-commit to install pre-commit
  3. Create .pre-commit-config.yaml with content from below
  4. Create test.py with content from below
  5. Run git init to create an empty repository
  6. Run pre-commit run --files test.py prospector
  7. See error ModuleNotFoundError: No module named 'pkg_resources'

.pre-commit-config.yaml

repos:
-   repo: https://github.com/landscapeio/prospector
    rev: v1.10.3
    hooks:
      - id: prospector

test.py

import os
print(os.getcwd())

Expected behavior
The prospector hook passes without errors.

Environment (please complete the following information):

  • OS: Linux (mcr.microsoft.com/devcontainers/python:3-bookworm)
  • Tool pre-commit
  • Prospector version 1.10.3
  • Python version 3.12
@dotysan
Copy link

dotysan commented Feb 25, 2024

A workaround is to use pip to install prospector and it's hidden dependency, setuptools. Then run pre-commit in "local" mode.

.pre-commit-config.yaml:

repos:

#  # this will fail on run in Python 3.12 without setuptools
#  - repo: https://github.com/PyCQA/prospector
#    #rev: v1.10.3
#    rev: master
#    hooks:
#      - id: prospector

  # this works fine
  - repo: local
    hooks:
      - id: prospector
        name: Prospector
        description: Analyze Python code using Prospector
        entry: prospector
        language: python

@dotysan
Copy link

dotysan commented Feb 25, 2024

See also #656.

@drice
Copy link

drice commented Mar 21, 2024

Easy workaround, add setuptools to additional_dependencies

  - repo: https://github.com/landscapeio/prospector
    rev: v1.10.3
    hooks:
      - id: prospector
        additional_dependencies: ["setuptools"]

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

No branches or pull requests

4 participants