Iterates trough the all enabled `~zengine.settings.ACTIVITY_MODULES_IMPORT_PATHS` to find the given path.
517358
def _load_activity(self, activity):
        
        fpths = []
        full_path = ''
        errors = []
        paths = settings.ACTIVITY_MODULES_IMPORT_PATHS
        number_of_paths = len(paths)
        for index_no in range(number_of_paths):
            full_path = "%s.%s" % (paths[index_no], activity)
            for look4kls in (0, 1):
                try:
                    self.current.log.info("try to load from %s[%s]" % (full_path, look4kls))
                    kls, cls_name, cls_method = self._import_object(full_path, look4kls)
                    if cls_method:
                        self.current.log.info("WILLCall %s(current).%s()" % (kls, cls_method))
                        self.wf_activities[activity] = lambda crnt: getattr(kls(crnt), cls_method)()
                    else:
                        self.wf_activities[activity] = kls
                    return
                except (ImportError, AttributeError):
                    fpths.append(full_path)
                    errmsg = "{activity} not found under these paths:\n\n >>> {paths} \n\n" \
                             "Error Messages:\n {errors}"
                    errors.append("\n========================================================>\n"
                                  "| PATH | %s"
                                  "\n========================================================>\n\n"
                                  "%s" % (full_path, traceback.format_exc()))
                    assert index_no != number_of_paths - 1, errmsg.format(activity=activity,
                                                                          paths='\n >>> '.join(
                                                                              set(fpths)),
                                                                          errors='\n\n'.join(errors)
                                                                          )
                except:
                    self.current.log.exception("Cannot found the %s" % activity)
1323220
def resolve_python_path(path):
    
    # Get the module
    module_path, local_path = path.split(':', 1)
    thing = importlib.import_module(module_path)
    # Traverse the local sections
    local_bits = local_path.split('.')
    for bit in local_bits:
        thing = getattr(thing, bit)
    return thing
123164
def _import_modules(dir_path):
    

    def _import_module(module):
        """ Imports the specified module.
            """
        # already loaded, skip
        if module in mods_loaded:
            return False

        __import__(module)
        mods_loaded.append(module)

    mods_loaded = []

    # check if provided path exists
    if not os.path.isdir(dir_path):
        return

    try:
        # update import search path
        sys.path.insert(0, dir_path)

        # check for modules in the dir path
        for entry in os.listdir(dir_path):
            path = os.path.join(dir_path, entry)

            if os.path.isdir(path):  # directory
                _import_module(entry)

            elif _RE_PY_EXT.search(entry):  # python file
                if not _RE_INIT_PY.match(entry):  # exclude init
                    name = _RE_PY_EXT.sub('', entry)
                    _import_module(name)
    finally:
        # remove inserted path
        sys.path.pop(0)
930228
def get_importable_modules(folder):
    
    for fname in os.listdir(folder):
        if fname.endswith('.py') and not fname.startswith('_'):
            yield fname[:-3]
869792
def _get_from_path(import_path):
    # type: (str) -> Callable
    
    module_name, obj_name = import_path.rsplit('.', 1)
    module = import_module(module_name)
    return getattr(module, obj_name)
163026
def find_package(name: str) -> Tuple[Optional[Path], Path]:
    
    module = name.split(".")[0]
    loader = pkgutil.get_loader(module)
    if name == "__main__" or loader is None:
        package_path = Path.cwd()
    else:
        if hasattr(loader, 'get_filename'):
            filename = loader.get_filename(module)  # type: ignore
        else:
            __import__(name)
            filename = sys.modules[name].__file__
        package_path = Path(filename).resolve().parent
        if hasattr(loader, 'is_package'):
            is_package = loader.is_package(module)  # type: ignore
            if is_package:
                package_path = Path(package_path).resolve().parent
    sys_prefix = Path(sys.prefix).resolve()
    try:
        package_path.relative_to(sys_prefix)
    except ValueError:
        return None, package_path
    else:
        return sys_prefix, package_path
1339217
def find_module(self, fullname, path=None):
        
        # path points to the top-level package path if any
        # and we can only import sub-modules/-packages
        if path is None:
            return
        if fullname.startswith(self.module_prefix):
            return self
        else:
            return None
327079
def file_containing_import(import_path, import_root):
    '''
    '''
    if not _import_paths:
        load_stdlib()

    if os.path.isfile(import_root):
        import_root = os.path.dirname(import_root)

    search_paths = [import_root] + _import_paths
    module_parts = import_path.split('.')
    for i in range(len(module_parts), 0, -1):
        module_path = os.path.join(*module_parts[:i])
        for sp in search_paths:
            p = os.path.join(sp, module_path)
            if os.path.isdir(p):
                return os.path.join(p, '__init__.py')
            elif os.path.isfile(p + '.py'):
                return p + '.py'
    return None
792343
def _find_and_load_module(self, name, path=None):
        
        bits = name.split('.')
        while len(bits) > 1:
            # Treat the first bit as a package
            packagename = bits.pop(0)
            package = self._find_and_load_module(packagename, path)
            try:
                path = package.__path__
            except AttributeError:
                # This could be e.g. moves.
                flog.debug('Package {0} has no __path__.'.format(package))
                if name in sys.modules:
                    return sys.modules[name]
                flog.debug('What to do here?')

        name = bits[0]
        module_info = imp.find_module(name, path)
        return imp.load_module(name, *module_info)
386394
def enumerate_local_modules(tokens, path):
    
    # Have to get a list of all modules before we can do anything else
    modules = enumerate_imports(tokens)
    local_modules = []
    parent = ""
    # Now check the local dir for matching modules
    for root, dirs, files in os.walk(path):
        if not parent:
            parent = os.path.split(root)[1]
        for f in files:
            if f.endswith('.py'):
                f = f[:-3] # Strip .py
                module_tree = root.split(parent)[1].replace('/', '.')
                module_tree = module_tree.lstrip('.')
                if module_tree:
                    module = "%s.%s" % (module_tree, f)
                else:
                    module = f
                if not module in modules:
                    local_modules.append(module)
    return local_modules
37530
public function getImportPaths($path = null)
    {
        if ($path === null) {
            return $this->importPaths;
        }

        return isset($this->importPaths[$path])
            ? $this->importPaths[$path]
            : [];
    }
484341
def getModulePath(project_path,module_name,verbose):
    ''''''
    if not module_name:
        return None
    sys.path.append(project_path)
    try:
        package = pkgutil.get_loader(module_name)
    except ImportError:
        if verbose:
            print("Parent module for "+module_name+" not found.")
        return None
    except:
        if verbose:
            print(module_name+" not loaded for bizarre reasons")
    try:
        if package: 
                if package.get_code(module_name):
                    filename = package.get_code(module_name).co_filename
                    return filename
                elif package.find_spec(module_name).has_location==False:
                    return None #built-in module such as itertools
                else:
                    pass #perhaps filename is in package.find_spec(module_name).origin?
                    pass #a good reference is https://www.python.org/dev/peps/pep-0302/
    except ImportError:
        if verbose:
            print("Code object unavailable for "+module_name)
        return None
    except AttributeError:
        if verbose:
            print(module_name+" is an ExtensionFileLoader object")
        return None
    except:
        if verbose:
            print(module_name+" not loaded for bizarre reasons")
        return None
    else:
        if verbose:
            print ("Module "+module_name+" not found.")
        return None
128329
def import_path(self):
    """"""
    return os.path.join(self.remote_root, self.pkg) if self.pkg else self.remote_root
447556
def _get_module_path(name, fail=False, install_path=None):
    
    import imp

    module = imp.find_module(name)
    if not module and fail:
        raise RuntimeError("can't find module '" + name + "'")
    path = module[1]
    if not path and fail:
        raise RuntimeError("module '" + name + "' is missing a file path")
    
    if install_path:
        return os.path.join(install_path, os.path.split(path)[1])

    return path
857794
def load_collectors_from_paths(paths):
    
    # Initialize return value
    collectors = {}

    if paths is None:
        return

    if isinstance(paths, basestring):
        paths = paths.split(',')
        paths = map(str.strip, paths)

    load_include_path(paths)

    for path in paths:
        # Get a list of files in the directory, if the directory exists
        if not os.path.exists(path):
            raise OSError("Directory does not exist: %s" % path)

        if path.endswith('tests') or path.endswith('fixtures'):
            return collectors

        # Load all the files in path
        for f in os.listdir(path):

            # Are we a directory? If so process down the tree
            fpath = os.path.join(path, f)
            if os.path.isdir(fpath):
                subcollectors = load_collectors_from_paths([fpath])
                for key in subcollectors:
                    collectors[key] = subcollectors[key]

            # Ignore anything that isn't a .py file
            elif (os.path.isfile(fpath) and
                  len(f) > 3 and
                  f[-3:] == '.py' and
                  f[0:4] != 'test' and
                  f[0] != '.'):

                modname = f[:-3]

                fp, pathname, description = imp.find_module(modname, [path])

                try:
                    # Import the module
                    mod = imp.load_module(modname, fp, pathname, description)
                except (KeyboardInterrupt, SystemExit) as err:
                    logger.error(
                        "System or keyboard interrupt "
                        "while loading module %s"
                        % modname)
                    if isinstance(err, SystemExit):
                        sys.exit(err.code)
                    raise KeyboardInterrupt
                except Exception:
                    # Log error
                    logger.error("Failed to import module: %s. %s",
                                 modname,
                                 traceback.format_exc())
                else:
                    for name, cls in get_collectors_from_module(mod):
                        collectors[name] = cls
                finally:
                    if fp:
                        fp.close()

    # Return Collector classes
    return collectors
894724
public Manifest findByPath(String path) {
        for (Manifest manifest : this) {
            String mpath = ((ManifestEx) manifest).path;

            if (path.startsWith(mpath)) {
                return manifest;
            }
        }

        return null;
    }
341655
def get_paths(cls, packages):
        """"""
        allowable_packages = dict((app_config.name, app_config) for app_config in apps.get_app_configs())
        app_configs = [allowable_packages[p] for p in packages if p in allowable_packages]
        # paths of requested packages
        return [os.path.join(app.path, 'locale') for app in app_configs]