/** * @file `resolvePipPackagePin()` — the Python mirror of * `resolveNpmPackagePin()` (dlx/lockfile). Resolves a pip spec and its full * dependency closure WITHOUT installing into the interpreter, then returns * everything needed to pin a reproducible, hash-verified install: * * - the resolved top-level name + version, * - the top-level artifact's hashes (sha512 SRI + sha256 hex), and * - a fully-hashed `requirements.txt` body (`name==version --hash=sha256:` * for every artifact in the closure) ready to feed back to * `downloadPipPackage` / `pip install --require-hashes`. Engine: `pip * download --dest ` downloads the spec + its resolved * closure as wheels/sdists into a scratch dir without installing anything * or creating a venv. Each file is hashed, then the scratch dir is torn * down. This is pip's own recipe for producing hashed requirements — * `pip-tools` is NOT required. Contrast `resolveNpmPackagePin` * (dlx/lockfile): same contract, npm engine (Arborist lockfile-only + * pacote), emits a `package-lock.json`. The pip side emits a hashed * `requirements.txt` because that — not a lockfile — is what `pip install * --require-hashes` consumes. NOTE on the soak window: * `resolveNpmPackagePin` applies a min-release-age cutoff via Arborist's * `before` date. pip has no native release-age gate, so this generator does * NOT enforce one — callers that need a soak must vet the resolved versions * out of band. The spec itself remains the primary pin: `==` (PyPI * is immutable per version) or a content-addressed git `@`. */ import type { ComputedHashes } from '../../crypto/integrity.js'; export interface ResolvePipPackagePinOptions { /** * Absolute path to the Python interpreter used to run `pip download`, * typically from `resolvePython()`. The interpreter is NOT modified. */ readonly pythonBin: string; /** * Directory `pip download` resolves the closure into. Defaults to a unique * scratch dir under the OS temp dir, removed before returning. */ readonly scratchDir?: string | undefined; /** * Pip spec to pin: `==` (PyPI exact pin) or a git-SHA pin * `git+https://@`. */ readonly spec: string; } export interface PipArtifactPin { /** * Sha256 hex of the artifact, the `--hash=sha256:` value pip expects. */ readonly checksum: string; /** * Downloaded artifact filename, e.g. `is_odd-3.0.1-py3-none-any.whl`. */ readonly file: string; /** * Distribution name parsed from the filename, e.g. `is-odd`. */ readonly name: string; /** * Distribution version parsed from the filename, e.g. `3.0.1`. */ readonly version: string; } export interface PipPackagePin { /** * Per-artifact pins for the full resolved closure (top-level + transitive). */ readonly artifacts: readonly PipArtifactPin[]; /** * Hashes of the top-level artifact (sha512 SRI + sha256 hex). The Python * analog of `NpmPackagePin.hash`. */ readonly hash: ComputedHashes; /** * Resolved top-level distribution name. */ readonly name: string; /** * Fully-hashed `requirements.txt` content, ready to write to disk and feed to * `pip install --require-hashes -r `. The Python analog of * `NpmPackagePin.lockfile`. */ readonly requirements: string; /** * Resolved top-level distribution version. */ readonly version: string; } /** * Thrown when `pip download` produces no artifacts or a filename can't be * parsed into a name + version. */ export declare class PipPackagePinError extends Error { constructor(message: string, options?: { cause?: unknown | undefined; } | undefined); } /** * Normalize a PEP 503 distribution name: lowercase, runs of `_ . -` collapse to * a single `-`. Wheel filenames use `_`; requirements/PyPI use `-`. */ export declare function normalizeDistName(name: string): string; /** * Parse `-` out of a wheel (`name-ver-...whl`) or sdist * (`name-ver.tar.gz` / `name-ver.zip`) filename. Returns undefined when the * shape isn't recognized. */ export declare function parseArtifactFilename(file: string): { name: string; version: string; } | undefined; /** * Generate a vendorable, hash-pinned closure for a pip spec without installing * it. Mirrors `resolveNpmPackagePin`. Throws `PipPackagePinError` on an empty * download or an unparseable artifact filename. */ export declare function resolvePipPackagePin(options: ResolvePipPackagePinOptions): Promise; /** * Best-effort distribution name from a pip spec for matching the top-level * artifact: strips a `==`/`>=`/etc. version and a `git+...#egg=` * fragment. Falls back to the raw spec when neither is present. */ export declare function specDistName(spec: string): string;