Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert #2303 #2746

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions flytekit/core/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
Loading