pdoc3 / pdoc

:snake: :arrow_right: :scroll: Auto-generate API documentation for Python projects
https://pdoc3.github.io/pdoc/
GNU Affero General Public License v3.0
1.13k stars 146 forks source link

When using --http, also reload submodules - fix #264 #300

Closed Lucas-C closed 3 years ago

Lucas-C commented 3 years ago

Fixes #264

The fix in cli.py was made to avoid this error while pressing F5 in my browser when using --http:

Error importing module fpdf:

Traceback (most recent call last):
  File "/home/lucas_cimon/.local/share/virtualenvs/pyfpdf/lib/python3.7/site-packages/pdoc/cli.py", line 234, in do_GET
    out = self.html()
  File "/home/lucas_cimon/.local/share/virtualenvs/pyfpdf/lib/python3.7/site-packages/pdoc/cli.py", line 267, in html
    skip_errors=args.skip_errors,
AttributeError: 'Namespace' object has no attribute 'skip_errors'
kernc commented 3 years ago

I was wondering how come I hadn't thought of that simple solution. Maybe it has some drawbacks I'm no longer aware of, but it seems to work around the issue. :smiley:

Much appreciated!

kernc commented 3 years ago

Ah, right, I remember now what I was thinking. This fix only applies when imported objects are from submodules of the current module, which might be a common, but certainly not the general case.

In terms of #264, the fix "breaks" if observed my_func() were defined in __init__ and imported/exposed in file1.

Ideas?

Lucas-C commented 3 years ago

Maybe #264 can be re-opened to track this. In my case this fix was enough to le me edit the docs interactively.

I may have an idea for a fix though: instead of checking if mod_key.startswith(module.__name__), we could check if mod_key.startswith(base_mod) where base_mod is the root module of module.__name__ (extracted with module.__name__.split(".", 1)[0] for example).

What do you think?

kernc commented 3 years ago

It's not too bad an idea at all. This will then work for all modules within a single package. :+1: