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.12k stars 145 forks source link

HTTP Server doesn't detect changes if __all__ is used #264

Open thomasfrederikhoeck opened 3 years ago

thomasfrederikhoeck commented 3 years ago

Expected Behavior

I expect changes to be reflected when using the web server when I make changes to files, even though I use __all__and view the module.

Actual Behavior

Changes are not reflected.

Steps to Reproduce

  1. Create folder my_module

  2. Add two files

    
    #### __init__.py

from .file1 import my_func

all = ['my_func',]

file1.py

def my_func(x: int): """

Parameters
----------
x : int
    This is a number

Returns
-------
int
    Same as input

"""
return x

3. Run `pdoc --http localhost:1234 my_module` from parent dir.

4. Go to `localhost:1234/my_module`

5. Change `file1-py`  to:

file1.py

def my_func(x: int): """

Parameters
----------
x : int
    This is a number

Returns
-------
int
    Very different output

"""
return x


6. Notice no change on the web page

### Additional info

- pdoc version: 0.9.1
kernc commented 3 years ago

Ah, I see. localhost:1234/my_module doesn't update until localhost:1234/my_module/file1.html itself is visited.

I investigated Python bytecode caching via sys.dont_write_bytecode, and that did nothing.

I imagine the issue is thus: the requested module itself is always reloaded: https://github.com/pdoc3/pdoc/blob/d8b9dbc2a128099e89a9d7859720dac56d574094/pdoc/__init__.py#L223-L223 but its references (i.e. my_module.file1.my_func) still come from the existing loaded modules (i.e. sys.modules['my_module.file1']) which aren't reloaded. A solution would be to also recursively reload all the dependency modules beforehand, but I don't quickly see how to achieve that.

Ideas appreciated.

Lucas-C commented 3 years ago

I submitted a PR to solve this: https://github.com/pdoc3/pdoc/pull/300