Add PEP 723 inline script environment creation (PEP 723 PR 5c/16)#1656
Draft
StellaHuang95 wants to merge 3 commits into
Draft
Add PEP 723 inline script environment creation (PEP 723 PR 5c/16)#1656StellaHuang95 wants to merge 3 commits into
StellaHuang95 wants to merge 3 commits into
Conversation
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
Implement InlineScriptEnvManager.create(): select a compatible base interpreter and build or reuse a dependency-keyed virtual environment, with cache-ownership validation, cross-process locking, and cancellation-safe creation. Wire the manager's collaborators. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 39dcc6a3-0fbd-4f36-9d0f-68677de49c27
StellaHuang95
force-pushed
the
pep723-pr5c-manager
branch
from
July 24, 2026 00:13
0433271 to
95cb552
Compare
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 final slice of PR 5 of 16 — the actual
create()happy path. See #1651 for the full roadmap table.InlineScriptEnvManagerskeletoncreate()happy path (manager + wiring)create()uv-install fallbackWhy this PR
InlineScriptEnvManager.create()was a deliberately empty no-op after PR 4. This PR implements its happy path: the case where the machine already has a base interpreter that satisfies the script'srequires-python, so no uv Python install is required. Given a PEP 723 script, it builds — or reuses — a dependency-keyed virtual environment under the extension's global storage, following the pipx-style cache design from Q4 of #1601. The uv-install fallback (no compatible interpreter present) is deferred to PR 6.It composes the primitives from 5a (#1651) and the inline-script utilities from 5b (#1655); this PR adds only the manager and its wiring.
What this PR does
Wires the manager's collaborators (
extension.ts,inlineScriptMain.ts):registerInlineScriptFeaturesand theInlineScriptEnvManagerconstructor now receive theNativePythonFinder, thePythonEnvironmentApi, the base (system) environment manager, andglobalStorageUri.Implements
create(scope)(inlineScriptEnvManager.ts):file:URI (a bareUrior single-element array). Anything else —'global', a folder, or multiple URIs — logs a warning and returnsundefined.undefined.metadata.dependencieswithoptions.additionalPackages, trims each, and rejects empty entries.create()calls for the same key via apendingCreationsmap.Base-interpreter selection (
selectBaseInterpreter): starts fromgetEnvironments('global'), keeps only true base managers (system, pyenv, condabase), and excludes derived environments by rejecting a non-absolutesysPrefixor the presence ofpyvenv.cfg. It then picks the newest compatible interpreter withpickCompatibleInterpreterand resolves the executable throughfs.realpathso the cache key is canonical. If a candidate cannot be resolved it falls through to the next.Create-or-reuse under a cross-process lock (
createOrReuseEnvironment): acquires a directory lock (5a), inspects the existing cache entry, and reuses / rebuilds / preserves accordingly, always releasing the lock infinally.Fail-closed cache inspection (
inspectCacheEntry) returnsabsent | stale | uncertain | reusable:resolveCacheEntryPath)..meta.jsonsidecar and confirms the recorded base-interpreter path and version still match the selected base.getBaseInterpreterStatus).PythonEnvironment, confirms it is genuinely ours via realpath containment (inspectOwnedCacheEntry), compares Python release segments, and re-checksrequires-pythonwith the existingmatchesPythonVersion.stale(rebuild); any doubt yieldsuncertain, and an uncertain entry is preserved, never deleted. A reused entry has itslastUsedAtrefreshed.Environment build (
buildCacheEntry): delegates to the existingcreateWithProgressvenv flow with{ trackUvEnvironment: false }(5a) so cached script environments are not registered as workspace venvs. On success it writes the sidecar and re-validates that the built environment matches the requested release and is owned by this entry. On failure it removes the directory and returns empty. On cancellation it retains the lock (5a) so a half-built environment is not silently reused later.Tests
inlineScriptEnvManager.unit.test.ts— 40 tests across scope/metadata validation, base-interpreter selection, cache creation, cache reuse, transaction rollback, and events/disposal.inlineScriptMain.unit.test.ts— updated for the newregisterInlineScriptFeaturessignature.On this branch (5a + 5b + 5c, i.e. the full original change)
npm run lintandnpm run compile-testsare clean andnpm run unittestreports 1487 passing, 0 failing, 5 pending.User impact
None on the default path. The manager is still registered only when the undeclared
python-envs.inlineScripts.enabledflag is on, so default users see nothing.create()is now a declared method (PR 4 omitted it), so with the flag on the inline manager can appear as a create target. But it acts only on a single local script URI and no-ops on every other scope, and nothing in the extension routes a script URI to it yet. Wiring the trigger is later work: routing in PR 9, and the "Set up env for this script" picker item and bulk command in PR 11/12.Merge order
Merge #1651 first, then #1655, then this PR.