Skip to content

Add inline-script cache and interpreter utilities (PEP 723 PR 5b/16)#1655

Draft
StellaHuang95 wants to merge 2 commits into
microsoft:mainfrom
StellaHuang95:pep723-pr5b-cache-utils
Draft

Add inline-script cache and interpreter utilities (PEP 723 PR 5b/16)#1655
StellaHuang95 wants to merge 2 commits into
microsoft:mainfrom
StellaHuang95:pep723-pr5b-cache-utils

Conversation

@StellaHuang95

@StellaHuang95 StellaHuang95 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Part of #1602 (PEP 723 inline script env support). Design doc: #1601.

Split for review (3 PRs). Reviewers flagged the original PR 5 as too large, so it is split into three stacked PRs grouped by dependency layer:

Applied together the three PRs are byte-for-byte identical to the original single change. Merge order: 5a → 5b → 5c.

This PR is stacked on #1651, so the diff below currently also includes the 5a commit. To review just this PR, open the Add inline-script cache and interpreter utilities for creation commit (09b7664, 6 files). Once #1651 merges to main, this PR reduces to its own changes with no rebase needed.

Roadmap context

This is the second slice of PR 5 of 16. See #1651 for the full roadmap table.

Phase 2: Manager PR Status
PR 4: InlineScriptEnvManager skeleton merged (#1610)
PR 5a: generic env-creation utilities #1651
PR 5b: inline-script cache + interpreter utilities this PR (#1655)
PR 5c: create() happy path (manager + wiring) #1656

Why this PR

With the generic primitives from 5a in place, this PR lands the inline-script-specific utilities that create() (5c) composes: a normalized dependency cache key, cache-layout ownership/status checks, and interpreter-constraint handling. These are pure functions with no manager wiring yet, so they are reviewed on their own.

What this PR adds

Cache-key tail normalization (src/common/inlineScriptCacheKey.ts): adds normalizeRequirementTail, a quote-aware scanner that collapses whitespace and tightens comparator spacing (>= 1.0>=1.0) in a requirement's version/marker tail while preserving quoted PEP 508 marker literals verbatim (e.g. python_version >= "3.11"). Direct-reference requirements (pkg @ https://…) are kept verbatim after the name and extras. The effect is that semantically identical dependency strings normalize to the same cache key, so they reuse the same cached environment.

Cache-layout additions (src/common/inlineScriptCacheLayout.ts): resolveCacheEntryPath (containment under the cache root), inspectOwnedCacheEntry (realpath ownership), getBaseInterpreterStatus (available | missing | unavailable), inspectMetaJson (typed sidecar read), and a stricter validateMeta. The .meta.json sidecar schema is { schemaVersion, baseInterpreterPath, baseInterpreterVersion, lastUsedAt }. Uses getVenvPythonPath from 5a (the edge that stacks this PR on #1651).

Interpreter-constraint trimming (src/common/inlineScriptInterpreter.ts): pickCompatibleInterpreter now trims requires-python, so a whitespace-only constraint is treated as no constraint.

Tests

  • inlineScriptCacheKey.unit.test.ts — canonicalization cases including marker literals and direct references.
  • inlineScriptCacheLayout.unit.test.ts — the new containment, ownership, base-interpreter-status, and typed sidecar-read helpers.
  • inlineScriptInterpreter.unit.test.ts — constraint trimming / selection.

On this branch (5a + 5b) npm run compile-tests is clean and npm run unittest reports 1465 passing, 0 failing, 5 pending.

User impact

None. These are pure utilities. Nothing calls the new code paths until the manager lands in 5c (#1656).

Merge order

Merge #1651 first, then this PR, then #1656.

StellaHuang95 and others added 2 commits July 23, 2026 17:04
Cross-process file lock, venv Python-path helper, cancellation-safe process runner, and createWithProgress tracking options that inline-script environment creation builds on.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 39dcc6a3-0fbd-4f36-9d0f-68677de49c27
Cache-key tail normalization, cache-layout ownership/status checks with typed sidecar reads, and interpreter-constraint trimming that inline-script environment creation builds on.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 39dcc6a3-0fbd-4f36-9d0f-68677de49c27
@StellaHuang95
StellaHuang95 force-pushed the pep723-pr5b-cache-utils branch from 09b7664 to 7363231 Compare July 24, 2026 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature-request Request for new features or functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant