@@ -304,10 +304,10 @@ def skip_doc(cls) -> bool:
304
304
return cls .__name__ .endswith ("Box" ) or (hasattr (cls , "no_doc" ) and cls .no_doc )
305
305
306
306
307
- def skip_module_doc (module , modules_seen ) -> bool :
307
+ def skip_module_doc (module , must_be_skipped ) -> bool :
308
308
return (
309
309
module .__doc__ is None
310
- or module in modules_seen
310
+ or module in must_be_skipped
311
311
or module .__name__ .split ("." )[0 ] not in ("mathics" , "pymathics" )
312
312
or hasattr (module , "no_doc" )
313
313
and module .no_doc
@@ -1052,8 +1052,13 @@ def doc_part(self, title, modules, builtins_by_module, start):
1052
1052
"""
1053
1053
1054
1054
builtin_part = self .part_class (self , title , is_reference = start )
1055
+
1056
+ # This is used to ensure that we pass just once over each module.
1057
+ # The algorithm we use to walk all the modules without repetitions
1058
+ # relies on this, which in my opinion is hard to test and susceptible
1059
+ # to errors. I guess we include it as a temporal fixing to handle
1060
+ # packages inside ``mathics.builtin``.
1055
1061
modules_seen = set ([])
1056
- submodule_names_seen = set ([])
1057
1062
1058
1063
want_sorting = True
1059
1064
if want_sorting :
@@ -1065,6 +1070,34 @@ def doc_part(self, title, modules, builtins_by_module, start):
1065
1070
)
1066
1071
else :
1067
1072
module_collection_fn = lambda x : x
1073
+
1074
+ # For some weird reason, it seems that this produces an
1075
+ # overflow error in test.builitin.directories.
1076
+ '''
1077
+ def filter_toplevel_modules(module_list):
1078
+ """
1079
+ Keep just the modules at the top level.
1080
+ """
1081
+ if len(module_list) == 0:
1082
+ return module_list
1083
+
1084
+ modules_and_levels = sorted(
1085
+ ((module.__name__.count("."), module) for module in module_list),
1086
+ key=lambda x: x[0],
1087
+ )
1088
+ top_level = modules_and_levels[0][0]
1089
+ return (entry[1] for entry in modules_and_levels if entry[0] == top_level)
1090
+ '''
1091
+ # This ensures that the chapters are built
1092
+ # from the top-level modules. Without this,
1093
+ # if this happens is just by chance, or by
1094
+ # an obscure combination between the sorting
1095
+ # of the modules and the way in which visited
1096
+ # modules are skipped.
1097
+ #
1098
+ # However, if I activate this, some tests are lost.
1099
+ #
1100
+ # modules = filter_toplevel_modules(modules)
1068
1101
for module in module_collection_fn (modules ):
1069
1102
if skip_module_doc (module , modules_seen ):
1070
1103
continue
@@ -1075,6 +1108,10 @@ def doc_part(self, title, modules, builtins_by_module, start):
1075
1108
builtins = builtins_by_module .get (module .__name__ )
1076
1109
if module .__file__ .endswith ("__init__.py" ):
1077
1110
# We have a Guide Section.
1111
+
1112
+ # This is used to check if a symbol is not duplicated inside
1113
+ # a guide.
1114
+ submodule_names_seen = set ([])
1078
1115
name = get_doc_name_from_module (module )
1079
1116
guide_section = self .add_section (
1080
1117
chapter , name , module , operator = None , is_guide = True
@@ -1102,6 +1139,10 @@ def doc_part(self, title, modules, builtins_by_module, start):
1102
1139
continue
1103
1140
1104
1141
submodule_name = get_doc_name_from_module (submodule )
1142
+ # This has the side effect that Symbols with the same
1143
+ # short name but in different contexts be skipped.
1144
+ # This happens with ``PlaintextImport`` that appears in
1145
+ # the HTML and XML contexts.
1105
1146
if submodule_name in submodule_names_seen :
1106
1147
continue
1107
1148
section = self .add_section (
0 commit comments