prospector
prospector copied to clipboard
[BUG] pre-commit hook fails on Python 3.12 because of deprecated pkg_resources
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
- Install Python 3.12 (or use container image)
- Run
pip install pre-committo install pre-commit - Create .pre-commit-config.yaml with content from below
- Create test.py with content from below
- Run
git initto create an empty repository - Run
pre-commit run --files test.py prospector - 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
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
See also #656.
Easy workaround, add setuptools to additional_dependencies
- repo: https://github.com/landscapeio/prospector
rev: v1.10.3
hooks:
- id: prospector
additional_dependencies: ["setuptools"]