Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdoc does not seem to play nicely with GitPython when in a package #430

Closed
cquick01 opened this issue Aug 11, 2022 · 2 comments
Closed

pdoc does not seem to play nicely with GitPython when in a package #430

cquick01 opened this issue Aug 11, 2022 · 2 comments
Labels

Comments

@cquick01
Copy link

Problem Description

pdoc is unable to import package that uses GitPython.

We've noticed this issue in a large application, and I have created a minimal example that has been able to reproduce the issue here: https://github.com/cquick01/pdoc-test

Our larger application runs fine when running normally, and that other pdoc3 tool has no issues. So it is definitely something that pdoc is doing differently than the rest. When commenting out references to GitPython in our larger application, pdoc then runs successfully across our entire package.

Steps to reproduce the behavior:

  1. Follow README in https://github.com/cquick01/pdoc-test
  2. See errors
Warn: Error loading test_package:
Traceback (most recent call last):
  File "/home/cquick/test/venv/lib/python3.10/site-packages/git/__init__.py", line 87, in <module>
    refresh()
  File "/home/cquick/test/venv/lib/python3.10/site-packages/git/__init__.py", line 78, in refresh
    if not FetchInfo.refresh():
  File "/home/cquick/test/venv/lib/python3.10/site-packages/git/remote.py", line 304, in refresh
    if Git().version_info[:2] >= (2, 10):
  File "/home/cquick/test/venv/lib/python3.10/site-packages/git/cmd.py", line 679, in version_info
    return self._version_info
  File "/home/cquick/test/venv/lib/python3.10/site-packages/git/cmd.py", line 638, in __getattr__
    return LazyMixin.__getattr__(self, name)
  File "/home/cquick/test/venv/lib/python3.10/site-packages/gitdb/util.py", line 253, in __getattr__
    self._set_cache_(attr)
  File "/home/cquick/test/venv/lib/python3.10/site-packages/git/cmd.py", line 659, in _set_cache_
    version_numbers = process_version.split(' ')[2]
IndexError: list index out of range

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/cquick/test/venv/lib/python3.10/site-packages/pdoc/extract.py", line 207, in load_module
    return importlib.import_module(module)
  File "/home/cquick/.pyenv/versions/3.10.6/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/cquick/test/test_package/__init__.py", line 1, in <module>
    import git
  File "/home/cquick/test/venv/lib/python3.10/site-packages/git/__init__.py", line 89, in <module>
    raise ImportError('Failed to initialize: {0}'.format(exc)) from exc
ImportError: Failed to initialize: list index out of range

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/cquick/test/venv/lib/python3.10/site-packages/pdoc/extract.py", line 250, in walk_packages2
    module = load_module(mod.name)
  File "/home/cquick/.pyenv/versions/3.10.6/lib/python3.10/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/home/cquick/test/venv/lib/python3.10/site-packages/pdoc/extract.py", line 209, in load_module
    raise RuntimeError(f"Error importing {module}") from e
RuntimeError: Error importing test_package
 (/home/cquick/test/venv/lib/python3.10/site-packages/pdoc/extract.py:252)
pdoc server ready at http://localhost:8080

System Information

Paste the output of "pdoc --version" here.

pdoc --version
pdoc: 12.0.2
Python: 3.10.6
Platform: Linux-5.10.102.1-microsoft-standard-WSL2-x86_64-with-glibc2.35

Will try to provide more info if needed.

@cquick01 cquick01 added the bug label Aug 11, 2022
@mhils mhils closed this as completed in 460bb9f Aug 11, 2022
@mhils
Copy link
Member

mhils commented Aug 11, 2022

This is because GitPython invokes git version on import, wheras pdoc by default suppresses all side effects. I've whitelisted git now so that things should work again. 😃

@cquick01
Copy link
Author

Thanks @mhils for the speedy fix! All seems to be working now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants