MCPcopy Create free account
hub / github.com/apache/mesos / import_modules

Function import_modules

src/python/cli_new/lib/cli/util.py:35–56  ·  view source on GitHub ↗

Looks for python packages under `package_paths` and imports them as modules. Returns a dictionary of the basename of the `package_paths` to the imported modules.

(package_paths, module_type)

Source from the content-addressed store, hash-verified

33
34
35def import_modules(package_paths, module_type):
36 """
37 Looks for python packages under `package_paths` and imports
38 them as modules. Returns a dictionary of the basename of the
39 `package_paths` to the imported modules.
40 """
41 modules = {}
42 for package_path in package_paths:
43 # We put the imported module into the namespace of
44 # "mesos.<module_type>.<>" to keep it from cluttering up
45 # the import namespace elsewhere.
46 package_name = os.path.basename(package_path)
47 package_dir = os.path.dirname(package_path)
48 module_name = "cli." + module_type + "." + package_name
49 try:
50 module = importlib.import_module(module_name)
51 except Exception:
52 obj, filename, data = imp.find_module(package_name, [package_dir])
53 module = imp.load_module(module_name, obj, filename, data)
54 modules[package_name] = module
55
56 return modules
57
58
59def get_module(modules, import_path):

Callers

nothing calls this directly

Calls 2

dirnameMethod · 0.80
basenameMethod · 0.45

Tested by

no test coverage detected