Skip to content

Commit

Permalink
Updated the way the current_script_name works.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcdermott committed Jul 16, 2024
1 parent 67e0469 commit b44f315
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/MEDS_polars_functions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,18 @@ def get_script_docstring() -> str:


def current_script_name() -> str:
"""Returns the name of the script that called this function."""
"""Returns the name of the module that called this function."""

main_module = sys.modules["__main__"]
main_func = getattr(main_module, "main", None)
if main_func and callable(main_func):
func_module = main_func.__module__
if func_module == "__main__":
return Path(sys.argv[0]).stem
else:
return func_module.split(".")[-1]

logger.warning("Can't find main function in __main__ module. Using sys.argv[0] as a fallback.")
return Path(sys.argv[0]).stem


Expand Down

0 comments on commit b44f315

Please sign in to comment.