stfc / pre-commit-hooks

Custom pre-commit hooks for use within our projects
https://stfc.github.io/pre-commit-hooks/
MIT License
2 stars 0 forks source link

check-missing-requirements hook fails for python 3.12.4 #39

Open RobFirth opened 2 months ago

RobFirth commented 2 months ago

Running pre-commit hooks gives the following error in python 3.12.4:

Check for missing requirements from the environment.......................Failed
- hook id: check-missing-requirements
- exit code: 1

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/berto/PycharmProjects/HT06272_RAG_Benchmarking/rag_bench/.venv/lib/python3.12/site-packages/hooks/check_missing_requirements.py", line 9, in <module>
    import requirements
  File "/Users/berto/PycharmProjects/HT06272_RAG_Benchmarking/rag_bench/.venv/lib/python3.12/site-packages/requirements/__init__.py", line 1, in <module>
    from .parser import parse   # noqa
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/berto/PycharmProjects/HT06272_RAG_Benchmarking/rag_bench/.venv/lib/python3.12/site-packages/requirements/parser.py", line 4, in <module>
    from .requirement import Requirement
  File "/Users/berto/PycharmProjects/HT06272_RAG_Benchmarking/rag_bench/.venv/lib/python3.12/site-packages/requirements/requirement.py", line 3, in <module>
    from pkg_resources import Requirement as Req
ModuleNotFoundError: No module named 'pkg_resources'
RobFirth commented 2 months ago

ensuring setuptools is specified as a dependency in the project python environment solves this issue.

Interestingly, the same error can be resolved for nbdev using the additional_dependencies option:

    - repo: https://github.com/fastai/nbdev
      rev: 2.3.25
      hooks:
      - id: nbdev_clean
        additional_dependencies: [setuptools]