Skip to content

Commit

Permalink
fix: parse the path for package manually when module is __main__ (#21)
Browse files Browse the repository at this point in the history
* fix: parse the path for package manually when module is `__main__`

* describe the reason
  • Loading branch information
isidentical authored Jan 24, 2024
1 parent 3ce907c commit b5cae79
Showing 1 changed file with 13 additions and 0 deletions.
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__":
# 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

0 comments on commit b5cae79

Please sign in to comment.