@@ -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,14 +508,18 @@ 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
+ scanfilter : Callable [[str ], bool ] = None , supermodule : 'Module' = None ,
512
+ context : Context = None ):
495
513
"""
496
514
Creates a `Module` documentation object given the actual
497
515
module Python object.
498
516
499
517
`docfilter` is an optional predicate that controls which
500
518
sub-objects are documentated (see also: `pdoc.html()`).
501
519
520
+ `scanfilter` is an optional predicate that controls which
521
+ submodules are ignored during parsing.
522
+
502
523
`supermodule` is the parent `pdoc.Module` this module is
503
524
a submodule of.
504
525
@@ -563,23 +584,7 @@ def is_from_this_module(obj):
563
584
# If the module is a package, scan the directory for submodules
564
585
if self .is_package :
565
586
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__ ):
587
+ for root in _iter_modules (self .obj .__path__ ):
583
588
# Ignore if this module was already doc'd.
584
589
if root in self .doc :
585
590
continue
@@ -590,9 +595,13 @@ def iter_modules(paths):
590
595
591
596
assert self .refname == self .name
592
597
fullname = "%s.%s" % (self .name , root )
598
+
599
+ if scanfilter and not scanfilter (fullname ):
600
+ continue
601
+
593
602
self .doc [root ] = m = Module (import_module (fullname ),
594
- docfilter = docfilter , supermodule = self ,
595
- context = self ._context )
603
+ docfilter = docfilter , scanfilter = scanfilter ,
604
+ supermodule = self , context = self ._context )
596
605
# Skip empty namespace packages because they may
597
606
# as well be other auxiliary directories
598
607
if m .is_namespace and not m .doc :
0 commit comments