prospector icon indicating copy to clipboard operation
prospector copied to clipboard

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

Open ldallmayr opened this issue 2 years ago • 3 comments

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

ldallmayr avatar Nov 26 '23 16:11 ldallmayr

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 avatar Feb 25 '24 22:02 dotysan

See also #656.

dotysan avatar Feb 25 '24 23:02 dotysan

Easy workaround, add setuptools to additional_dependencies

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

drice avatar Mar 21 '24 21:03 drice