Uh oh!
There was an error while loading. Please reload this page.
"Fixed" tracing bug if module name and current working directory are identically named - #137
Conversation
Essoz
commented
Jun 5, 2026
✅ The fix solves the immediate problem, but I share your concern about potential edge cases. Potential issue: Better approach: Instead of parsing the file path string directly, we:
Example Code (you can probably use a coding agent to help you implement this, should be a pretty lightweight change). frompathlibimportPathfromimportlib.utilimportfind_specdefget_module_path_from_file_path(file_path: str, root_module: str) ->str|None:
""" Get the module path from a file path using importlib and pathlib. """try:
# Find the root module's locationspec=find_spec(root_module)
ifspecisNoneorspec.originisNone:
returnNoneroot_module_path=Path(spec.origin).parentfile_path_obj=Path(file_path).resolve()
# Get the relative path from root module to filetry:
relative_path=file_path_obj.relative_to(root_module_path)
exceptValueError:
# file_path is not under the root modulereturnNone# Convert to module pathmodule_name=str(relative_path.with_suffix(''))
module_path=f"{root_module}.{module_name.replace('/', '.')}"returnmodule_pathexceptException:
returnNoneThis approach is import-aware and doesn't rely on fragile string parsing. |
Uh oh!
There was an error while loading. Please reload this page.
173297e to
b6b0e5bCompareUh oh!
There was an error while loading. Please reload this page.
For Python projects named reponame/packagename where reponame equals packagename (i.e. torchtitan/torchtitan), .split() will improperly split at the first instance in the string. The path after the root module will then still have module name on it. For example, it splits "/home/daniel/torchtitan/torchtitan/config/manager.py" into ['/home/daniel', 'torchtitan/config/manager.py'] instead of ['/home/daniel/torchtitan', 'config/manager.py']. Thus, after prepending the module name, we get torchtitan/torchtitan/config/manager.py, which doesn't exist.