def scandir(path): try: return _scandir(path) # fallback for systems where sys.getfilesystemencoding() returns the "wrong" value except UnicodeDecodeError: return scandir_listdir_fallback(path)
def scandir(path, force_listdir=False): if _scandir is not None and not force_listdir: for item in _scandir(path): yield item else: for item in os.listdir(path): fullpath = os.path.join(path, item) yield fake_DirEntry(fullpath)
def get_python_package_entry_point(package, entry_point): """ Find an CLI entry point from a Python package. Args: package (str): Package name. entry_point (str): Entry point name. Returns: str or None: Path to entry point, or None if nothing found. """ site_packages_path = _dirname(_import_module(package).__path__[0]) # Find package info # Can be a directory ending by ".dist-info" or ".egg-info" with _scandir(site_packages_path) as entries: for entry in entries: if (entry.name.startswith(f'{package}-') and _splitext(entry.name)[1] in ('.dist-info', '.egg-info')): package_info_path = entry.path break else: # Package is not installed or do not have package info return None # Find manifest file # Can be a "RECORD" or a "installed-files.txt" file in package info folder for name in ('RECORD', 'installed-files.txt'): manifest_path = _join(package_info_path, name) if _isfile(manifest_path): break else: # Package do not have manifest file return None # Find entry point relative path in manifest file # Possibles manifest file lines formats: "path\n" or "path,checksum\n" with open(manifest_path, 'rt') as manifest: for line in manifest: entry_point_rel_path = line.strip().split(',', 1)[0] if _basename(entry_point_rel_path) == entry_point: break else: # Entry point is not present in manifest return None # Convert to absolute path # Paths in manifest are relative to site-packages or package info for prefix in (site_packages_path, package_info_path): entry_point_path = _realpath(_join(prefix, entry_point_rel_path)) if _isfile(entry_point_path): return entry_point_path