Пример #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]
Пример #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)
Пример #3
0
 def from_dist(cls, dist: Distribution) -> "Requirement":
     direct_url_json = dist.read_text("direct_url.json")
     if direct_url_json is not None:
         direct_url = json.loads(direct_url_json)
         data = {
             "name": dist.metadata["Name"],
             "url": direct_url.get("url"),
             "editable": direct_url.get("dir_info", {}).get("editable"),
             "subdirectory": direct_url.get("subdirectory"),
         }
         if "vcs_info" in direct_url:
             vcs_info = direct_url["vcs_info"]
             data.update(
                 url=f"{vcs_info['vcs']}+{direct_url['url']}",
                 ref=vcs_info.get("requested_revision"),
                 revision=vcs_info.get("commit_id"),
             )
             return VcsRequirement.create(**data)
         return FileRequirement.create(**data)
     return NamedRequirement.create(name=dist.metadata["Name"],
                                    version=f"=={dist.version}")
def _get_modules_by_toplevel_txt(dist: Distribution) -> Optional[List[str]]:
    modules = dist.read_text("top_level.txt")
    if modules is None:
        return None
    else:
        return modules.rstrip().split("\n")