Skip to content
Permalink
Browse files

REF: Only reload modules when in --http mode

Maybe avoids problems with modules whose importing
has side effects.
  • Loading branch information...
kernc committed May 3, 2019
1 parent 8e69541 commit 947af75c6bee414ce445663f60af73b26cad5d88
Showing with 9 additions and 8 deletions.
  1. +6 −6 pdoc/__init__.py
  2. +3 −2 pdoc/cli.py
@@ -123,7 +123,7 @@ def _render_template(template_name, **kwargs):
raise


def html(module_name, docfilter=None, **kwargs) -> str:
def html(module_name, docfilter=None, reload=False, **kwargs) -> str:
"""
Returns the documentation for the module `module_name` in HTML
format. The module must be a module or an importable string.
@@ -133,12 +133,12 @@ def html(module_name, docfilter=None, **kwargs) -> str:
that takes a single argument (a documentation object) and returns
`True` or `False`. If `False`, that object will not be documented.
"""
mod = Module(import_module(module_name), docfilter=docfilter)
mod = Module(import_module(module_name, reload=reload), docfilter=docfilter)
link_inheritance()
return mod.html(**kwargs)


def text(module_name, docfilter=None, **kwargs) -> str:
def text(module_name, docfilter=None, reload=False, **kwargs) -> str:
"""
Returns the documentation for the module `module_name` in plain
text format suitable for viewing on a terminal.
@@ -149,12 +149,12 @@ def text(module_name, docfilter=None, **kwargs) -> str:
that takes a single argument (a documentation object) and returns
`True` or `False`. If `False`, that object will not be documented.
"""
mod = Module(import_module(module_name), docfilter=docfilter)
mod = Module(import_module(module_name, reload=reload), docfilter=docfilter)
link_inheritance()
return mod.text(**kwargs)


def import_module(module) -> ModuleType:
def import_module(module, *, reload: bool = False) -> ModuleType:
"""
Return module object matching `module` specification (either a python
module path or a filesystem path to file/directory).
@@ -183,7 +183,7 @@ def _module_path(module):
assert inspect.ismodule(module)
# If this is pdoc itself, return without reloading. Otherwise later
# `isinstance(..., pdoc.Doc)` calls won't work correctly.
if not module.__name__.startswith(__name__):
if reload and not module.__name__.startswith(__name__):
module = importlib.reload(module)
return module

@@ -167,7 +167,7 @@ def do_GET(self):
importlib.invalidate_caches()
code = 200
if self.path == "/":
modules = [pdoc.import_module(module)
modules = [pdoc.import_module(module, reload=True)
for module in self.args.modules]
modules = sorted((module.__name__, inspect.getdoc(module))
for module in modules)
@@ -236,7 +236,8 @@ def html(self):
"""
# TODO: pass extra pdoc.html() params
return pdoc.html(self.import_path_from_req_url,
http_server=True, external_links=True, **self.template_config)
reload=True, http_server=True, external_links=True,
**self.template_config)

def resolve_ext(self, import_path):
def exists(p):

0 comments on commit 947af75

Please sign in to comment.
You can’t perform that action at this time.