Skip to content
New issue

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

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

Already on GitHub? # to your account

pdoc crashes on sys.stdout.reconfigure(encoding='utf-8') #745

Closed
teiesti opened this issue Oct 7, 2024 · 2 comments · Fixed by #751
Closed

pdoc crashes on sys.stdout.reconfigure(encoding='utf-8') #745

teiesti opened this issue Oct 7, 2024 · 2 comments · Fixed by #751
Labels

Comments

@teiesti
Copy link

teiesti commented Oct 7, 2024

Problem Description

pdoc crashes with the following error message if the code to document contains sys.stdout.reconfigure(encoding='utf-8').

$ pdoc foo.py -o docs
Traceback (most recent call last):
  File "/home/stolzmann/miniconda3/lib/python3.12/site-packages/pdoc/extract.py", line 218, in load_module
    return importlib.import_module(module)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/stolzmann/miniconda3/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/home/stolzmann/pdoc_bug/foo.py", line 2, in <module>
    sys.stdout.reconfigure(encoding='utf-8')
    ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: '_io.StringIO' object has no attribute 'reconfigure'

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

Traceback (most recent call last):
  File "/home/stolzmann/miniconda3/bin/pdoc", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home/stolzmann/miniconda3/lib/python3.12/site-packages/pdoc/__main__.py", line 199, in cli
    pdoc.pdoc(
  File "/home/stolzmann/miniconda3/lib/python3.12/site-packages/pdoc/__init__.py", line 526, in pdoc
    all_modules[module_name] = doc.Module.from_name(module_name)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/stolzmann/miniconda3/lib/python3.12/site-packages/pdoc/doc.py", line 406, in from_name
    return cls(extract.load_module(name))
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/stolzmann/miniconda3/lib/python3.12/contextlib.py", line 81, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/stolzmann/miniconda3/lib/python3.12/site-packages/pdoc/extract.py", line 220, in load_module
    raise RuntimeError(f"Error importing {module}") from e
RuntimeError: Error importing foo

Steps to reproduce the behavior:

  1. Create a file called foo.py with the following content:
    import sys
    sys.stdout.reconfigure(encoding='utf-8')
    
  2. Run pdoc foo.py -o docs to try to render documentation for that file.

System Information

$ pdoc --version
pdoc: 14.7.0
Python: 3.12.2
Platform: Linux-6.8.0-45-generic-x86_64-with-glibc2.39
@teiesti teiesti added the bug label Oct 7, 2024
@teiesti
Copy link
Author

teiesti commented Oct 7, 2024

Update: This issue might be related to pytest-dev/pytest#4843.

@teiesti
Copy link
Author

teiesti commented Oct 14, 2024

Wow, that was fast. Thanks a lot.

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

Successfully merging a pull request may close this issue.

1 participant