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

fix: parse the path for package manually when module is __main__ #21

Merged
merged 2 commits into from
Jan 24, 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
13 changes: 13 additions & 0 deletions projects/fal/src/fal/_serialization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from pathlib import Path
from functools import wraps

import dill
Expand Down Expand Up @@ -55,6 +56,18 @@ def add_serialization_listeners_for(obj):
return None

_MODULES.add(module_name)
if module_name == "__main__":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add an explainer for this. I think it's just including all the parent packages of the file called, right?

Does this help for local imports?

# When the module is __main__, we need to recursively go up the
# tree to locate the actual package name.
import __main__

path = Path(__main__.__file__)
parent = path
while (parent.parent / "__init__.py").exists():
parent = parent.parent

if parent != path:
_PACKAGES.add(parent.name)

if "." in module_name:
package_name, *_ = module_name.partition(".")
Expand Down
Loading