Skip to content

Commit 221b0b8

Browse files
committed
add scanfilter parameter, move _iter_modules out of method scope, addresses #99
1 parent 86eac27 commit 221b0b8

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

pdoc/__init__.py

+25-19
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,23 @@ def __lt__(self, other):
479479
return self.refname < other.refname
480480

481481

482+
def _iter_modules(paths):
483+
"""
484+
Custom implementation of `pkgutil.iter_modules()`
485+
because that one doesn't play well with namespace packages.
486+
See: https://github.com/pypa/setuptools/issues/83
487+
"""
488+
from os.path import isdir, join, splitext
489+
for pth in paths:
490+
for file in os.listdir(pth):
491+
if file.startswith(('.', '__pycache__', '__init__.py')):
492+
continue
493+
if file.endswith(_SOURCE_SUFFIXES):
494+
yield splitext(file)[0]
495+
if isdir(join(pth, file)) and '.' not in file:
496+
yield file
497+
498+
482499
class Module(Doc):
483500
"""
484501
Representation of a module's documentation.
@@ -491,7 +508,8 @@ class Module(Doc):
491508
__slots__ = ('supermodule', 'doc', '_context', '_is_inheritance_linked')
492509

493510
def __init__(self, module: Union[ModuleType, str], *, docfilter: Callable[[Doc], bool] = None,
494-
supermodule: 'Module' = None, context: Context = None):
511+
supermodule: 'Module' = None, context: Context = None,
512+
scanfilter: Callable[[str], bool] = None):
495513
"""
496514
Creates a `Module` documentation object given the actual
497515
module Python object.
@@ -563,23 +581,7 @@ def is_from_this_module(obj):
563581
# If the module is a package, scan the directory for submodules
564582
if self.is_package:
565583

566-
def iter_modules(paths):
567-
"""
568-
Custom implementation of `pkgutil.iter_modules()`
569-
because that one doesn't play well with namespace packages.
570-
See: https://github.com/pypa/setuptools/issues/83
571-
"""
572-
from os.path import isdir, join, splitext
573-
for pth in paths:
574-
for file in os.listdir(pth):
575-
if file.startswith(('.', '__pycache__', '__init__.py')):
576-
continue
577-
if file.endswith(_SOURCE_SUFFIXES):
578-
yield splitext(file)[0]
579-
if isdir(join(pth, file)) and '.' not in file:
580-
yield file
581-
582-
for root in iter_modules(self.obj.__path__):
584+
for root in _iter_modules(self.obj.__path__):
583585
# Ignore if this module was already doc'd.
584586
if root in self.doc:
585587
continue
@@ -590,9 +592,13 @@ def iter_modules(paths):
590592

591593
assert self.refname == self.name
592594
fullname = "%s.%s" % (self.name, root)
595+
596+
if scanfilter and not scanfilter(fullname):
597+
continue
598+
593599
self.doc[root] = m = Module(import_module(fullname),
594600
docfilter=docfilter, supermodule=self,
595-
context=self._context)
601+
context=self._context, scanfilter=scanfilter)
596602
# Skip empty namespace packages because they may
597603
# as well be other auxiliary directories
598604
if m.is_namespace and not m.doc:

0 commit comments

Comments
 (0)