Skip to content

Commit 3dcbded

Browse files
committed
add docstring for ModuleImporter
1 parent 51c6350 commit 3dcbded

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

metaflow/plugins/env_escape/client_modules.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,27 @@ def __setattr__(self, name, value):
121121

122122

123123
class ModuleImporter(object):
124-
# This ModuleImporter implements the MetaPathFinder and Loader protocols (PEP 302/451)
124+
"""
125+
A custom import hook that proxies module imports to a different Python environment.
126+
127+
This class implements the MetaPathFinder and Loader protocols (PEP 451) to enable
128+
"environment escape" - allowing the current Python process to import and use modules
129+
from a different Python interpreter with potentially different versions or packages.
130+
131+
When a module is imported through this importer:
132+
1. A client spawns a server process in the target Python environment
133+
2. The module is loaded in the remote environment
134+
3. A _WrappedModule proxy is returned that forwards all operations (function calls,
135+
attribute access, etc.) to the remote environment via RPC
136+
4. Data is serialized/deserialized using pickle for cross-environment communication
137+
138+
Args:
139+
python_executable: Path to the Python interpreter for the remote environment
140+
pythonpath: Python path to use in the remote environment
141+
max_pickle_version: Maximum pickle protocol version supported by remote interpreter
142+
config_dir: Directory containing configuration for the environment escape
143+
module_prefixes: List of module name prefixes to handle
144+
"""
125145
def __init__(
126146
self,
127147
python_executable,

0 commit comments

Comments
 (0)