Skip to content

Commit 9ada15e

Browse files
committed
ENH: apply exclude pattern before import
This helps to filter out parts of a big package to be documented which might fail during import.
1 parent 06d6b20 commit 9ada15e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/sphinx_autodoc/main.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -364,20 +364,23 @@ def main():
364364

365365
print(f"processing package: {package_name}")
366366
package = importlib.import_module(package_name)
367+
368+
if args.exclude is not None:
369+
rex = re.compile(args.exclude)
370+
mod_filter = lambda name: rex.search(name) is None
371+
else:
372+
mod_filter = lambda name: True
373+
367374
mods = [
368375
Module(
369376
name,
370377
source=args.source,
371378
apipath=args.apipath,
372379
docpath=args.docpath,
373380
)
374-
for name in walk_package(package)
381+
for name in walk_package(package) if mod_filter(name)
375382
]
376383

377-
if args.exclude is not None:
378-
rex = re.compile(args.exclude)
379-
mods = [mod for mod in mods if rex.search(mod.name) is None]
380-
381384
modules_api = ""
382385
modules_doc = ""
383386

0 commit comments

Comments
 (0)