MCPcopy Create free account
hub / github.com/modelscope/modelscope / import_modules_from_file

Function import_modules_from_file

modelscope/utils/import_utils.py:36–53  ·  view source on GitHub ↗

Import module from a certrain file Args: py_file: path to a python file to be imported Return:

(py_file: str)

Source from the content-addressed store, hash-verified

34
35
36def import_modules_from_file(py_file: str):
37 """ Import module from a certrain file
38
39 Args:
40 py_file: path to a python file to be imported
41
42 Return:
43
44 """
45 dirname, basefile = os.path.split(py_file)
46 if dirname == '':
47 dirname = Path.cwd()
48 module_name = osp.splitext(basefile)[0]
49 sys.path.insert(0, dirname)
50 validate_py_syntax(py_file)
51 mod = import_module(module_name)
52 sys.path.pop(0)
53 return module_name, mod
54
55
56def is_method_overridden(method, base_class, derived_class):

Callers 1

_file2dictMethod · 0.90

Calls 2

validate_py_syntaxFunction · 0.85
insertMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…