From e17b91ce7361132e3a717618fe7f15332f8eedfe Mon Sep 17 00:00:00 2001 From: Kevin Su Date: Wed, 11 Sep 2024 11:57:57 -0700 Subject: [PATCH] revert 2303 Signed-off-by: Kevin Su --- flytekit/core/tracker.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flytekit/core/tracker.py b/flytekit/core/tracker.py index 9670f578ac..8d7b2a9b19 100644 --- a/flytekit/core/tracker.py +++ b/flytekit/core/tracker.py @@ -33,14 +33,14 @@ class InstanceTrackingMeta(type): @staticmethod def _get_module_from_main(globals) -> Optional[str]: + curdir = Path.cwd() file = globals.get("__file__") if file is None: return None file = Path(file) try: - root_dir = os.path.commonpath([file.resolve(), Path.cwd()]) - file_relative = Path(os.path.relpath(file.resolve(), root_dir)) + file_relative = file.relative_to(curdir) except ValueError: return None @@ -49,8 +49,8 @@ def _get_module_from_main(globals) -> Optional[str]: if len(module_components) == 0: return None - # make sure /root directory is in the PYTHONPATH. - sys.path.insert(0, root_dir) + # make sure current directory is in the PYTHONPATH. + sys.path.insert(0, str(curdir)) try: return import_module_from_file(module_name, file) except ModuleNotFoundError: @@ -328,8 +328,8 @@ def extract_task_module(f: Union[Callable, TrackedInstance]) -> Tuple[str, str, f = f.task_function # If the module is __main__, we need to find the actual module name based on the file path inspect_file = inspect.getfile(f) # type: ignore - # get module name for instances in the same file as the __main__ module - mod_name, _ = InstanceTrackingMeta._find_instance_module() + file_name, _ = os.path.splitext(os.path.basename(inspect_file)) + mod_name = get_full_module_path(f, file_name) # type: ignore return f"{mod_name}.{name}", mod_name, name, os.path.abspath(inspect_file) mod_name = get_full_module_path(mod, mod_name)