landscapeio / prospector

Inspects Python source files and provides information about type and location of classes, methods etc
GNU General Public License v2.0
1.94k stars 171 forks source link

[BUG] missing dependency: setuptools #656

Open dotysan opened 7 months ago

dotysan commented 7 months ago

On Python 3.12, one cannot assume setuptools is available. https://github.com/python/cpython/issues/95299

$ python3.12 -m venv .venv
$ source .venv/bin/activate
(.venv) $ pip install --upgrade pip
  ...
(.venv) $ pip list
Package Version
------- -------
pip     24.0
(.venv) $ pip install prospector
  ...
(.venv) $ prospector 
Traceback (most recent call last):
  File "/home/curtis/src/pre-commit/.venv/bin/prospector", line 5, in <module>
    from prospector.run import main
  File "/home/curtis/src/pre-commit/.venv/lib64/python3.12/site-packages/prospector/run.py", line 9, in <module>
    from prospector import blender, postfilter, tools
  File "/home/curtis/src/pre-commit/.venv/lib64/python3.12/site-packages/prospector/blender.py", line 9, in <module>
    import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'

Workaround:

(.venv) $ pip install setuptools
  ...
(.venv) $ prospector 
Messages
========

foo.py
  Line: 1
    pylint: disallowed-name / Disallowed name "foo"

Check Information
=================
         Started: 2024-02-25 15:00:20.065460
        Finished: 2024-02-25 15:00:20.162956
      Time Taken: 0.10 seconds
       Formatter: grouped
        Profiles: default, no_doc_warnings, no_test_warnings, strictness_medium, strictness_high, strictness_veryhigh, no_member_warnings
      Strictness: None
  Libraries Used: 
       Tools Run: dodgy, mccabe, profile-validator, pycodestyle, pyflakes, pylint
  Messages Found: 1
drice commented 6 months ago

Easy workaround, add setuptools to additional_dependencies

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

Shouldn't we use import lib? https://docs.python.org/3/library/importlib.html