@@ -479,6 +479,23 @@ def __lt__(self, other):
479
479
return self .refname < other .refname
480
480
481
481
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
+
482
499
class Module (Doc ):
483
500
"""
484
501
Representation of a module's documentation.
@@ -491,7 +508,8 @@ class Module(Doc):
491
508
__slots__ = ('supermodule' , 'doc' , '_context' , '_is_inheritance_linked' )
492
509
493
510
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 ):
495
513
"""
496
514
Creates a `Module` documentation object given the actual
497
515
module Python object.
@@ -563,23 +581,7 @@ def is_from_this_module(obj):
563
581
# If the module is a package, scan the directory for submodules
564
582
if self .is_package :
565
583
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__ ):
583
585
# Ignore if this module was already doc'd.
584
586
if root in self .doc :
585
587
continue
@@ -590,9 +592,13 @@ def iter_modules(paths):
590
592
591
593
assert self .refname == self .name
592
594
fullname = "%s.%s" % (self .name , root )
595
+
596
+ if scanfilter and not scanfilter (fullname ):
597
+ continue
598
+
593
599
self .doc [root ] = m = Module (import_module (fullname ),
594
600
docfilter = docfilter , supermodule = self ,
595
- context = self ._context )
601
+ context = self ._context , scanfilter = scanfilter )
596
602
# Skip empty namespace packages because they may
597
603
# as well be other auxiliary directories
598
604
if m .is_namespace and not m .doc :
0 commit comments