Attempt to compute a root path for a (hopefully importable) name.

        Based in part on Flask's `root_path` calculation. See:

            https://github.com/mitsuhiko/flask/blob/master/flask/helpers.py#L777
427513
def get_root_path(self, name):
        
        module = modules.get(name)
        if module is not None and hasattr(module, '__file__'):
            return dirname(abspath(module.__file__))

        # Flask keeps looking at this point. We instead set the root path to None,
        # assume that the user doesn't need resource loading, and raise an error
        # when resolving the resource path.
        return None
407486
def path(self) -> str:
        
        path: str = ELIBConfig.config_sep_str.join(self._raw_path)
        if ELIBConfig.root_path:
            prefix = ELIBConfig.config_sep_str.join(ELIBConfig.root_path)
            path = ELIBConfig.config_sep_str.join((prefix, path))
        return path
467284
def get_root_path(obj):
    
    try:
        filename = os.path.abspath(obj.__globals__['__file__'])
    except (KeyError, AttributeError):
        if getattr(obj, '__wrapped__', None):
            # decorator package has been used in view
            return get_root_path(obj.__wrapped__)
        filename = inspect.getfile(obj)
    return os.path.dirname(filename)
478058
def import_name(name):
    
    if isinstance(name, str):
        components = name.split('.')
        mod = __import__('.'.join(components[0:-1]), globals(), locals(), [components[-1]] )
        return getattr(mod, components[-1])
    else:
        return name
912302
def GetKey(self, path, cycle=9999, rootpy=True, **kwargs):
        
        key = super(_DirectoryBase, self).GetKey(path, cycle)
        if not key:
            raise DoesNotExist
        if rootpy:
            return asrootpy(key, **kwargs)
        return key
200133
def get_python_path() -> str:
    
    python_bin = None
    if os.name == 'nt':
        python_root = os.path.abspath(
            os.path.join(os.__file__, os.pardir, os.pardir))
        python_bin = os.path.join(python_root, 'python.exe')
    else:
        python_root = os.path.abspath(
            os.path.join(os.__file__, os.pardir, os.pardir, os.pardir))
        python = os.__file__.rsplit('/')[-2]
        python_bin = os.path.join(python_root, 'bin', python)
    return python_bin
202419
def find_config_root(path=sys.argv[0]):
    
    dirname = os.path.dirname(path)
    lastdirname = None

    while dirname != lastdirname:
        config_root = os.path.join(dirname, 'config')
        if os.path.exists(config_root):
            return config_root

        lastdirname, dirname = dirname, os.path.dirname(dirname)
884851
def path(self):
        
        if self.parent is None:
            return "/"
        else:
            return os.path.join(self.parent.path, self.name)
1193383
def path_for(self, *args):
        """"""
        if args and args[0].startswith(os.path.sep):
            return os.path.join(*args)
        return os.path.join(self._root_path or os.getcwd(), *args)
943941
def auto_find_instance_path(self) -> Path:
        
        prefix, package_path = find_package(self.import_name)
        if prefix is None:
            return package_path / "instance"
        return prefix / "var" / f"{self.name}-instance"
590511
def BasenamePath(self, path):
    
    if path.endswith(self.PATH_SEPARATOR):
      path = path[:-1]
    _, _, basename = path.rpartition(self.PATH_SEPARATOR)
    return basename
1123842
def GetRootFileEntry(self):
    
    path_spec = lvm_path_spec.LVMPathSpec(
        location=self.LOCATION_ROOT, parent=self._path_spec.parent)
    return self.GetFileEntryByPathSpec(path_spec)
568521
def GetRootFileEntry(self):
    
    kwargs = {}

    root_inode = self.GetRootInode()
    if root_inode is not None:
      kwargs['inode'] = root_inode

    kwargs['location'] = self.LOCATION_ROOT
    kwargs['parent'] = self._path_spec.parent

    path_spec = tsk_path_spec.TSKPathSpec(**kwargs)
    return self.GetFileEntryByPathSpec(path_spec)
852415
def base_path(self):
        
        path = UrlPath()

        # Walk up the API to find the base object
        parent = self.parent
        while parent:
            path_prefix = getattr(parent, 'path_prefix', NoPath)
            path = path_prefix + path
            parent = getattr(parent, 'parent', None)

        return path
716662
def calculate_mypypath() -> List[str]:
    """"""

    typeshed_root = None
    count = 0
    started = time.time()
    for parent in itertools.chain(
        # Look in current script's parents, useful for zipapps.
        Path(__file__).parents,
        # Look around site-packages, useful for virtualenvs.
        Path(mypy.api.__file__).parents,
        # Look in global paths, useful for globally installed.
        Path(os.__file__).parents,
    ):
        count += 1
        candidate = parent / 'lib' / 'mypy' / 'typeshed'
        if candidate.is_dir():
            typeshed_root = candidate
            break

        # Also check the non-installed path, useful for `setup.py develop`.
        candidate = parent / 'typeshed'
        if candidate.is_dir():
            typeshed_root = candidate
            break

    LOG.debug(
        'Checked %d paths in %.2fs looking for typeshed. Found %s',
        count,
        time.time() - started,
        typeshed_root,
    )

    if not typeshed_root:
        return []

    stdlib_dirs = ('3.7', '3.6', '3.5', '3.4', '3.3', '3.2', '3', '2and3')
    stdlib_stubs = [
        typeshed_root / 'stdlib' / stdlib_dir
        for stdlib_dir in stdlib_dirs
    ]
    third_party_dirs = ('3.7', '3.6', '3', '2and3')
    third_party_stubs = [
        typeshed_root / 'third_party' / tp_dir
        for tp_dir in third_party_dirs
    ]
    return [
        str(p) for p in stdlib_stubs + third_party_stubs
    ]
1110712
def get_root_path():
    """"""
    root_path = __file__
    return os.path.dirname(os.path.realpath(root_path))
909696
def _root_path(self):
        """'"""
        if self.ROOT_PATH_FOR_DYNACONF is not None:
            return self.ROOT_PATH_FOR_DYNACONF
        elif self._loaded_files:  # called once
            root_path = os.path.dirname(self._loaded_files[0])
            self.set("ROOT_PATH_FOR_DYNACONF", root_path)
            return root_path