Finds the file that might contain the import_path.
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
47514
def find_modules(module_path):
    
    if module_path.is_file():
        if module_path.suffix == '.py':
            yield module_path
    elif module_path.is_dir():
        pyfiles = glob.glob('{}/**/*.py'.format(module_path), recursive=True)
        yield from (Path(pyfile) for pyfile in pyfiles)
34537
def find_module(module, path=None, imp=None):
    """"""
    if imp is None:
        imp = importlib.import_module
    with cwd_in_path():
        if "." in module:
            last = None
            parts = module.split(".")
            for i, part in enumerate(parts[:-1]):
                mpart = imp(".".join(parts[:i + 1]))
                try:
                    path = mpart.__path__
                except AttributeError:
                    raise NotAPackage(module)
                last = _imp.find_module(parts[i + 1], path)
            return last
        return _imp.find_module(module)
67306
def find_file(name)
      @load_path.each do |dir|
        file_path = File.join(dir, "#{name}.rb")
        return file_path if File.exist? file_path
      end
      raise("Module #{name} not found")
    end
31787
def find(self, path, all=False):
        '''
        
        '''
        found = os.path.join(settings.STATIC_ROOT, path)
        if all:
            return [found]
        else:
            return found
813319
def find_module(self, fullname, path=None):
        """"""
        basepaths = [""] + list(sys.path)
        if fullname.startswith("."):
            if path is None:
                # we can't do a relative import if there's no package path
                return None
            fullname = fullname[1:]
            basepaths.insert(0, path)
        fullpath = os.path.join(*fullname.split("."))
        for head in basepaths:
            path = os.path.join(head, fullpath)
            filepath = path + self.ext
            dirpath = os.path.join(path, "__init__" + self.ext)
            if os.path.exists(filepath):
                self.run_compiler(filepath)
                # Coconut file was found and compiled, now let Python import it
                return None
            if os.path.exists(dirpath):
                self.run_compiler(path)
                # Coconut package was found and compiled, now let Python import it
                return None
        return None
977345
def load_path(self, path):
        '''
        
        '''
        containing_module, _, last_item = path.rpartition('.')
        if last_item[0].isupper():
            # Is a class definition, should do an "import from"
            path = containing_module
        imported_obj = importlib.import_module(path)
        if last_item[0].isupper():
            try:
                imported_obj = getattr(imported_obj, last_item)
            except AttributeError:
                msg = 'Cannot import "%s". ' \
                    '(Hint: CamelCase is only for classes)' % last_item
                raise ConfigurationError(msg)
        return imported_obj
1362742
def _package_path(name):
    
    loader = pkgutil.get_loader(name)
    if loader is None or name == '__main__':
        return None

    if hasattr(loader, 'get_filename'):
        filepath = loader.get_filename(name)
    else:
        # Fall back to importing the specified module.
        __import__(name)
        filepath = sys.modules[name].__file__

    return os.path.dirname(os.path.abspath(filepath))
1330868
def _find_file(self, path, saltenv='base'):
        '''
        
        '''
        fnd = {'path': '',
               'rel': ''}

        if salt.utils.url.is_escaped(path):
            # The path arguments are escaped
            path = salt.utils.url.unescape(path)
        for root in self.opts['pillar_roots'].get(saltenv, []):
            full = os.path.join(root, path)
            if os.path.isfile(full):
                fnd['path'] = full
                fnd['rel'] = path
                return fnd
        return fnd
771697
def resolve_import(import_path, from_module):
    '''
    '''
    if not import_path or not import_path.startswith('.'):
        return import_path

    from_module = from_module.split('.')
    dots = 0
    for c in import_path:
        if c == '.':
            dots += 1
        else:
            break

    if dots:
        from_module = from_module[:-dots]
        import_path = import_path[dots:]

    if import_path:
        from_module.append(import_path)

    return '.'.join(from_module)
508518
function findImportedPath(url, prev, includedFilesMap, includedPaths) {
  let candidateFromPaths;

  if(prev !== 'stdin') {
    const prevPath = path.posix.dirname(prev);
    candidateFromPaths = [prevPath, ...includedPaths];
  } else {
    candidateFromPaths = [...includedPaths];
  }

  for(let i = 0; i < candidateFromPaths.length; i++) {
    let candidatePath;
    let candidateFromPath = normalizePath(makeAbsolute(candidateFromPaths[i]));
    if (path.isAbsolute(url)) {
      candidatePath = normalizePath(url);
    } else {
      // Get normalize absolute candidate from path
      candidatePath = path.posix.join(candidateFromPath, url);
    }

    if(includedFilesMap[candidatePath]) {
      return candidatePath;
    } else {
      let urlBasename = path.posix.basename(url);
      let indexOfBasename = url.lastIndexOf(urlBasename);
      let partialUrl = `${url.substring(0, indexOfBasename)}_${urlBasename}`;

      if (path.isAbsolute(partialUrl)) {
        candidatePath = normalizePath(partialUrl);
      } else {
        candidatePath = path.posix.join(candidateFromPath, partialUrl);
      }

      if(includedFilesMap[candidatePath]) {
        return candidatePath;
      }
    }
  }

  return null;
}
1036405
def is_path_python_module(thepath):
    
    thepath = path.normpath(thepath)

    if path.isfile(thepath):
        base, ext = path.splitext(thepath)
        if ext in _py_suffixes:
            return True
        return False

    if path.isdir(thepath):
        for suffix in _py_suffixes:
            if path.isfile(path.join(thepath, '__init__%s' % suffix)):
                return True
    return False
564695
def find_related_module(app, related_name):
    """"""

    try:
        app_path = importlib.import_module(app).__path__
    except ImportError as exc:
        warn('Autodiscover: Error importing %s.%s: %r' % (
            app, related_name, exc,
        ))
        return
    except AttributeError:
        return

    try:
        f, _, _ = imp.find_module(related_name, app_path)
        # f is returned None when app_path is a module
        f and f.close()
    except ImportError:
        return

    return importlib.import_module('{0}.{1}'.format(app, related_name))
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
1102256
def check_file_type_and_import(path, single_transaction=true, verbose=true)
	  	if File.exists?(path)
	    	if File.extname(path) == ".csv"
	      	puts "CSV file found at '#{path.to_s}'.".green if verbose
	      	self.import_from_csv(path.to_s, single_transaction, verbose)
	      elsif File.extname(path) == ".xlsx"
	      	puts "XSLX file found at '#{path.to_s}'.".green if verbose
	      	self.import_from_xslx(path.to_s, single_transaction, verbose)
	      else
	      	puts "Unsupported File encountered'#{path.to_s}'.".red if verbose
	      	return
	      end
	    else
	      puts "Import File not found at '#{path.to_s}'.".red if verbose
	    end
	  end
1072130
def findModuleOfName(self, dotted_name, level, filename, extrapath=None):
        """"""
        if dotted_name.endswith('.*'):
            return dotted_name[:-2]
        name = dotted_name

        # extrapath is None only in a couple of test cases; in real life it's
        # always present
        if level and level > 1 and extrapath:
            # strip trailing path bits for each extra level to account for
            # relative imports
            # from . import X has level == 1 and nothing is stripped (the level > 1 check accounts for this case)
            # from .. import X has level == 2 and one trailing path component must go
            # from ... import X has level == 3 and two trailing path components must go
            extrapath = extrapath.split(os.path.sep)
            level -= 1
            extrapath = extrapath[0:-level]
            extrapath = os.path.sep.join(extrapath)

        while name:
            candidate = self.isModule(name, extrapath)
            if candidate:
                return candidate
            candidate = self.isPackage(name, extrapath)
            if candidate:
                return candidate
            name = name[:name.rfind('.')]
        self.warn(dotted_name, '%s: could not find %s', filename, dotted_name)
        return dotted_name
1238524
def find_module(module, paths=None):
    """"""

    parts = module.split('.')

    while parts:
        part = parts.pop(0)
        f, path, (suffix, mode, kind) = info = imp.find_module(part, paths)

        if kind == PKG_DIRECTORY:
            parts = parts or ['__init__']
            paths = [path]

        elif parts:
            raise ImportError("Can't find %r in %s" % (parts, module))

    return info