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

Improved module importing / support for namespace packages #62

Merged
merged 3 commits into from May 3, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+9 −8
Diff settings

Always

Just for now

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
commit 0f5f96edf339ab5e462020784a53993c9e82aae5
@@ -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):
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.