Exemple #1
0
def get_pkg_paths(pkg: Distribution) -> t.List[Path]:
    # Some egg-info packages have e.g. src/ paths in their SOURCES.txt file,
    # but they also have this:
    mods = set((pkg.read_text("top_level.txt") or "").split())
    if not mods and pkg.files:
        # Fall back to RECORD file for dist-info packages without top_level.txt
        mods = {
            f.parts[0] if len(f.parts) > 1 else f.with_suffix("").name
            for f in pkg.files
            if f.suffix == ".py" or Path(pkg.locate_file(f)).is_symlink()
        }
    if not mods:
        raise RuntimeError(
            f"Can’t determine top level packages of {pkg.metadata['Name']}"
        )
    return [Path(pkg.locate_file(mod)) for mod in mods]
Exemple #2
0
def get_apps(dist: metadata.Distribution, bin_path: Path) -> List[str]:
    apps = set()

    sections = {"console_scripts", "gui_scripts"}
    # "entry_points" entry in setup.py are found here
    for ep in dist.entry_points:
        if ep.group not in sections:
            continue
        if (bin_path / ep.name).exists():
            apps.add(ep.name)
        if WINDOWS and (bin_path / (ep.name + ".exe")).exists():
            # WINDOWS adds .exe to entry_point name
            apps.add(ep.name + ".exe")

    # search installed files
    # "scripts" entry in setup.py is found here (test w/ awscli)
    for path in dist.files or []:
        # vast speedup by ignoring all paths not above distribution root dir
        #   (venv/bin or venv/Scripts is above distribution root)
        if Path(path).parts[0] != "..":
            continue

        dist_file_path = Path(dist.locate_file(path))
        try:
            if dist_file_path.parent.samefile(bin_path):
                apps.add(path.name)
        except FileNotFoundError:
            pass

    # not sure what is found here
    inst_files = dist.read_text("installed-files.txt") or ""
    for line in inst_files.splitlines():
        entry = line.split(",")[0]  # noqa: T484
        inst_file_path = Path(dist.locate_file(entry)).resolve()
        try:
            if inst_file_path.parent.samefile(bin_path):
                apps.add(inst_file_path.name)
        except FileNotFoundError:
            pass

    return sorted(apps)