Skip to content

Commit

Permalink
BUG: Document compiled/bytecode submodules
Browse files Browse the repository at this point in the history
Fixes #132
  • Loading branch information
kernc committed Jan 15, 2020
1 parent 88e7274 commit 6604a51
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions pdoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
_URL_INDEX_MODULE_SUFFIX = '.m.html' # For modules named literal 'index'
_URL_PACKAGE_SUFFIX = '/index.html'

_SOURCE_SUFFIXES = tuple(importlib.machinery.SOURCE_SUFFIXES)

T = TypeVar('T', bound='Doc')

__pdoc__ = {} # type: Dict[str, Union[bool, str]]
Expand Down Expand Up @@ -166,10 +164,13 @@ def import_module(module, *, reload: bool = False) -> ModuleType:
"""
@contextmanager
def _module_path(module):
from os.path import isfile, isdir, split, abspath, splitext
path, module = '_pdoc_dummy_nonexistent', module
if isdir(module) or isfile(module) and module.endswith(_SOURCE_SUFFIXES):
path, module = split(splitext(abspath(module))[0])
from os.path import abspath, basename, dirname, isfile, isdir
path = '_pdoc_dummy_nonexistent'
module_name = inspect.getmodulename(module)
if isdir(module):
path, module = dirname(abspath(module)), basename(module)
elif isfile(module) and module_name:
path, module = dirname(abspath(module)), module_name
try:
sys.path.insert(0, path)
yield module
Expand Down Expand Up @@ -569,13 +570,14 @@ def iter_modules(paths):
because that one doesn't play well with namespace packages.
See: https://github.com/pypa/setuptools/issues/83
"""
from os.path import isdir, join, splitext
from os.path import isdir, join
for pth in paths:
for file in os.listdir(pth):
if file.startswith(('.', '__pycache__', '__init__.py')):
continue
if file.endswith(_SOURCE_SUFFIXES):
yield splitext(file)[0]
module_name = inspect.getmodulename(file)
if module_name:
yield module_name
if isdir(join(pth, file)) and '.' not in file:
yield file

Expand Down

0 comments on commit 6604a51

Please sign in to comment.