@@ -214,7 +214,7 @@ def cli_parser() -> Namespace:
214214 return parser .parse_args ()
215215
216216
217- def _flatten_io (io : list [Iterable ]) -> list [str ]:
217+ def _flatten_io (io : Iterable [Iterable ]) -> list [str ]:
218218 """Given a list of strings or iterables thereof, flatten the list to all strings."""
219219 if all (isinstance (resource , str ) for resource in io ):
220220 return cast (list [str ], io )
@@ -243,7 +243,7 @@ def find_directly_set_resources(package_name: str) -> dict[str, list[str]]:
243243 dict
244244 A dictionary containing the name of the resource and the name of the functions that set it.
245245 """
246- resources : dict [str [ list [str ] ]] = {}
246+ resources : dict [str , list [str ]] = {}
247247 for dirpath , _ , filenames in os .walk (str (files (package_name ))):
248248 for filename in filenames :
249249 if filename .endswith (".py" ):
@@ -280,7 +280,7 @@ def resource_inventory(package: str = "CPAC") -> dict[str, ResourceIO]:
280280 "CPAC.unet._torch" ,
281281 ],
282282 ):
283- nbf_name = f"{ nbf .__module__ } .{ nbf .__qualname__ } "
283+ nbf_name = f"{ nbf .name } ( { nbf . __module__ } .{ nbf .__qualname__ } ) "
284284 if hasattr (nbf , "inputs" ):
285285 for nbf_input in _flatten_io (cast (list [Iterable ], nbf .inputs )):
286286 if nbf_input :
@@ -331,6 +331,24 @@ def dump_inventory_to_yaml(inventory: dict[str, ResourceIO]) -> str:
331331 )
332332
333333
334+ def where_to_find (resources : list [str ] | str ) -> str :
335+ """Return a multiline string describing where each listed resource is output from."""
336+ if isinstance (resources , str ):
337+ resources = [resources ]
338+ resources = _flatten_io (resources )
339+ inventory = resource_inventory ("CPAC" )
340+ output = ""
341+ for resource in resources :
342+ output += f"'{ resource } ' is output from:\n "
343+ if resource in inventory :
344+ for source in inventory [resource ].output_from :
345+ output += f" { source } \n "
346+ else :
347+ output += " !! Nowhere !!\n "
348+ output += "\n "
349+ return output .rstrip ()
350+
351+
334352def main () -> None :
335353 """Save the NodeBlock inventory to a file."""
336354 args = cli_parser ()
0 commit comments