MCPcopy Create free account
hub / github.com/promptfoo/promptfoo / load_user_module

Function load_user_module

src/python/persistent_wrapper.py:88–103  ·  view source on GitHub ↗

Load and return the user's Python module.

(script_path)

Source from the content-addressed store, hash-verified

86
87
88def load_user_module(script_path):
89 """Load and return the user's Python module."""
90 script_dir = os.path.dirname(os.path.abspath(script_path))
91 module_name = os.path.basename(script_path).rsplit(".", 1)[0]
92
93 if script_dir not in sys.path:
94 sys.path.insert(0, script_dir)
95
96 spec = importlib.util.spec_from_file_location(module_name, script_path)
97 if spec is None or spec.loader is None:
98 raise ImportError(f"Cannot load module from {script_path}")
99
100 module = importlib.util.module_from_spec(spec)
101 spec.loader.exec_module(module)
102
103 return module
104
105
106def get_callable(module, method_name):

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…