in flowtorch/docs.py [0:0]
def sparse_module_hierarchy(mod_names: Sequence[str]) -> Mapping[str, Any]:
# Make list of modules to search and their hierarchy, pruning entries that
# aren't in mod_names
results: Dict[str, Any] = OrderedDict()
this_dict = results
for module in sorted(mod_names):
submodules = module.split(".")
# Navigate to the correct insertion place for this module
for idx in range(0, len(submodules)):
submodule = ".".join(submodules[0 : (idx + 1)])
if submodule in this_dict:
this_dict = this_dict[submodule]
# Insert module if it doesn't exist already
this_dict.setdefault(module, {})
return results