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)
| 33 | |
| 34 | |
| 35 | def 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 | |
| 59 | def get_module(modules, import_path): |