@@ -274,6 +274,22 @@ def _is_object_ignored(obj: Any) -> bool:
274
274
return False
275
275
276
276
277
+ def _is_module_ignored (module_name : str , ignored_modules : List [str ]) -> bool :
278
+ """Checks if a given module is ignored."""
279
+ if module_name .split ("." )[- 1 ].startswith ("_" ):
280
+ return True
281
+
282
+ for ignored_module in ignored_modules :
283
+ if module_name == ignored_module :
284
+ return True
285
+
286
+ # Check is module is subpackage of an ignored package
287
+ if module_name .startswith (ignored_module + "." ):
288
+ return True
289
+
290
+ return False
291
+
292
+
277
293
def _get_src_root_path (obj : Any ) -> str :
278
294
"""Get the root path to a imported module.
279
295
@@ -862,7 +878,7 @@ def generate_docs(
862
878
src_root_path : Optional [str ] = None ,
863
879
src_base_url : Optional [str ] = None ,
864
880
remove_package_prefix : bool = False ,
865
- ignored_modules : List [str ] = [] ,
881
+ ignored_modules : Optional [ List [str ]] = None ,
866
882
overview_file : Optional [str ] = None ,
867
883
watermark : bool = True ,
868
884
validate : bool = False ,
@@ -886,6 +902,9 @@ def generate_docs(
886
902
# Create output path
887
903
os .makedirs (output_path )
888
904
905
+ if not ignored_modules :
906
+ ignored_modules = list ()
907
+
889
908
if not src_root_path :
890
909
try :
891
910
# Set src root path to git root
@@ -923,17 +942,23 @@ def generate_docs(
923
942
924
943
if not stdout_mode :
925
944
print (f"Generating docs for python package at: { path } " )
945
+
926
946
# Generate one file for every discovered module
927
947
for loader , module_name , _ in pkgutil .walk_packages ([path ]):
928
- if module_name in ignored_modules : # lgtm [py/non-iterable-in-for-loop]
929
- continue
930
-
931
- if module_name .split ("." )[- 1 ].startswith ("_" ):
948
+ if _is_module_ignored (module_name , ignored_modules ):
949
+ # Add module to ignore list, so submodule will also be ignored
950
+ ignored_modules .append (module_name )
932
951
continue
933
952
934
953
try :
935
954
mod = loader .find_module (module_name ).load_module (module_name ) # type: ignore
936
955
module_md = generator .module2md (mod )
956
+ if not module_md :
957
+ # Module md is empty -> ignore module and all submodules
958
+ # Add module to ignore list, so submodule will also be ignored
959
+ ignored_modules .append (module_name )
960
+ continue
961
+
937
962
if stdout_mode :
938
963
print (module_md )
939
964
else :
@@ -995,16 +1020,23 @@ def generate_docs(
995
1020
path = obj .__path__ , # type: ignore
996
1021
prefix = obj .__name__ + "." , # type: ignore
997
1022
):
998
- if module_name in ignored_modules :
1023
+ if _is_module_ignored (module_name , ignored_modules ):
1024
+ # Add module to ignore list, so submodule will also be ignored
1025
+ ignored_modules .append (module_name )
999
1026
continue
1000
1027
1001
- if module_name .split ("." )[- 1 ].startswith ("_" ):
1002
- continue
1003
1028
try :
1004
1029
mod = loader .find_module (module_name ).load_module ( # type: ignore
1005
1030
module_name
1006
1031
)
1007
1032
module_md = generator .module2md (mod )
1033
+
1034
+ if not module_md :
1035
+ # Module MD is empty -> ignore module and all submodules
1036
+ # Add module to ignore list, so submodule will also be ignored
1037
+ ignored_modules .append (module_name )
1038
+ continue
1039
+
1008
1040
if stdout_mode :
1009
1041
print (module_md )
1010
1042
else :
0 commit comments