pdoc
pdoc copied to clipboard
pre-commit hook usage with virtualenv fails
Expected Behavior
After running pre-commit hook, to have generated pdoc output in the directory
Actual Behavior
ModuleNotFoundError is raised when running the pdoc pre-commit hook
Steps to Reproduce
- Install pre-commit framework
- Add pdoc to .pre-commit-config.yaml hooks
- Install pre-commit hooks
- Run the command "pre-commit run --all-files"
Additional info
- pdoc version: 0.9.2
please share the .pre-commit-config.yaml file where you have added pdoc hook and possibly the github project link if the project is public
I'm having the same issue, here is my pre-commit (only pdoc related) :
- repo: https://github.com/pdoc3/pdoc
rev: master
hooks:
- id: pdoc
name: pdoc
description: 'pdoc: Auto-generate API documentation for Python projects'
entry: pdoc --html -f -o docs module1 module2 module3
language: python
language_version: python3
require_serial: true
types: [python]
always_run: true
I have some packages installed that are out of stdlib that raise ModyleNotfoundError. I didn't take time to replicate with minimal version but it should be easy :
- Create new git project
- Create virtualenv
- install pre-commit hook
- add the hook as described above (a single module is enough, even a single file)
- pip install (using virtualenv) a module
- import a non stdlib module (pandas/numpy/whatever) in your project
- commit to trigger pre-commit hooks
A possible source of success is which python is used to trigger pdoc within pre-commit. If it's systems default (python or python3), depending on whether the module is installed or not, it might work.
Edit : I looked into my logs and it seems that pre-commit has its own virtualenv (kinda). It's probably more related to pre-commit than pdoc. Pdoc triggers this because it imports modules (other hooks usually don't, they only take them as text).
/Users/<username>/.cache/pre-commit/<repo_version>/py_env-python3/lib/python3.8/site-packages/pdoc/__init__.py", line 224, in import_module
I looked into my logs and it seems that pre-commit has its own virtualenv
Seems to me the only workaround, then, is to use repository-local hooks? Something like:
- repo: local
hooks:
- id: pdoc
name: pdoc
language: system
entry: python -m pip install pdoc3 && pdoc --html -f -o docs package
:confused:
It does work and I agree with you, it's probably the only solution. Do you want a PR to include this in the readme ?