Add generic environment-creation utilities (PEP 723 PR 5a/16) - #1651
Merged
StellaHuang95 merged 3 commits intoJul 27, 2026
Merged
Conversation
StellaHuang95
marked this pull request as ready for review
July 23, 2026 22:21
StellaHuang95
force-pushed
the
pep723-pr5-create-happy-path
branch
from
July 23, 2026 23:06
b1e9b95 to
f005e16
Compare
StellaHuang95
marked this pull request as draft
July 23, 2026 23:09
StellaHuang95
marked this pull request as ready for review
July 23, 2026 23:14
StellaHuang95
force-pushed
the
pep723-pr5-create-happy-path
branch
from
July 23, 2026 23:30
f005e16 to
d36561b
Compare
This was referenced Jul 23, 2026
StellaHuang95
marked this pull request as draft
July 23, 2026 23:34
StellaHuang95
marked this pull request as ready for review
July 23, 2026 23:35
edvilme
reviewed
Jul 23, 2026
edvilme
reviewed
Jul 24, 2026
StellaHuang95
force-pushed
the
pep723-pr5-create-happy-path
branch
from
July 24, 2026 00:13
d36561b to
104166d
Compare
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
StellaHuang95
force-pushed
the
pep723-pr5-create-happy-path
branch
from
July 24, 2026 17:28
0706167 to
e78bda6
Compare
edvilme
approved these changes
Jul 24, 2026
Comment on lines
+125
to
+127
| async function delay(milliseconds: number): Promise<void> { | ||
| return new Promise((resolve) => setTimeout(resolve, milliseconds)); | ||
| } |
Contributor
There was a problem hiding this comment.
Maybe this could be moved to a more generic location? But it doesn't bother me too much.
| }); | ||
|
|
||
| proc.on('error', (err) => { | ||
| if (cancellationRequested) { |
Member
There was a problem hiding this comment.
is cleanup required by this error stage? you went through and confirmed we aren't leaving stuff behind in people's file systems right?
Contributor
Author
There was a problem hiding this comment.
This change I made only catches proc.kill() throwing so the operation still reports CancellationError because it didn't catch the exception before, these 2 functions don't do cleanups, cleanup belongs to the caller. If you're asking about inline script manager in particular, that will be handled at the inline manager level later.
eleanorjboyd
approved these changes
Jul 27, 2026
StellaHuang95
added a commit
that referenced
this pull request
Jul 29, 2026
…1655) > 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 PRs grouped by dependency layer: > - **5a — generic env-creation utilities — #1651.** Merged. > - **5b — inline-script cache + interpreter utilities — this PR (#1655).** Rebased on `main`. > - **5c — `create()` happy path (manager + wiring) — #1656.** Stacked on 5b. > > #1651 has merged and this branch has been rebased. The diff now contains only this PR's seven files. **Remaining merge order: 5b → 5c.** ### 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 | merged (#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 merged PR #1651. **Interpreter-constraint trimming** (`src/common/inlineScriptInterpreter.ts`): `pickCompatibleInterpreter` now trims `requires-python`, so a whitespace-only constraint is treated as no constraint. **Manager ID constants** (`src/common/constants.ts`): centralizes the conda and inline-script manager IDs used by interpreter filtering. ### 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 rebased branch `npm run compile-tests` is clean and `npm run unittest` reports **1467 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 #1651 has merged. Merge this PR next, then #1656. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 39dcc6a3-0fbd-4f36-9d0f-68677de49c27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Roadmap context
This is the first slice of PR 5 of 16 in the PEP 723 inline-script roadmap. The full plan lives in #1602.
meta.jsonsidecarrequires-pythonto interpreter selectionInlineScriptEnvManagerskeletoncreate()happy path (manager + wiring)create()uv-install fallbackget,set, and MementoWhy this PR
PR 5c implements
InlineScriptEnvManager.create(). Before touching the manager, this PR lands the generic, reusable primitives it relies on — a cross-process file lock, a venv Python-path helper, a cancellation-hardened process runner, and two smallcreateWithProgressoptions. None of this code is inline-script-specific, so it is reviewed on its own.What this PR adds
Cross-process file lock (
src/common/lockfile.apis.ts, new):acquireFileLockuses an atomicmkdirof a<path>.lockdirectory plus a per-owner marker file, returningAcquiredFileLock { release, retain }.retain()writes aretainedmarker so a later acquirer fails fast withELOCKRETAINEDinstead of waiting out the 5-minute timeout — used when a build is cancelled mid-flight. Distinct error codes (ELOCKED,ELOCKRETAINED,ELOCKORPHANED,ECOMPROMISED,ERETAINFAILED) separate contention from corruption.Shared
getVenvPythonPath(src/common/utils/virtualEnvironment.ts, new): returnsScripts\python.exeon Windows, elsebin/python. Replaces an inline copy invenvUtilsand is reused by 5b/5c.Hardened process helper (
src/managers/builtin/helpers.ts):runUVandrunPythonnow share onerunProcessimplementation whose cancellation guardskill()intry/catchand still emits a cleanCancellationErrorif the process errors after a cancel. Per-caller options preserve existing behavior (collectStderr,logPrefix).venvUtils.ts:createWithProgressgainsCreateWithProgressOptions { trackUvEnvironment }, andCreateEnvironmentResultgainspkgInstallationCancelledso a caller can tell cancellation apart from a real install failure. Existing callers are unaffected (both are optional / additive).Tests
lockfile.apis.unit.test.ts— 9 tests: contention, retain/fail-fast, orphaned and compromised locks, and timeout.virtualEnvironment.unit.test.ts— 2 tests forgetVenvPythonPathon Windows and POSIX.helpers.cancellation.unit.test.ts— 4 tests forrunProcesscancellation safety.venvUtils.createWithProgress.unit.test.ts— 3 tests fortrackUvEnvironmentandpkgInstallationCancelled.On this branch alone
npm run compile-testsis clean andnpm run unittestreports 1447 passing, 0 failing, 4 pending.User impact
None. These are internal primitives with no new user-visible behavior. The refactors to
helpers.tsandvenvUtils.tsare behavior-preserving for existing callers.