Add PEP 723 inline-script setup CodeLens and bulk command (PEP 723 PR 11-12) - #1750
Conversation
… 11-12) Behind the internal python-envs.inlineScripts.enabled flag (nothing added to package.json): a 'Set up environment for this script' CodeLens shown above the PEP 723 block only when saved metadata has no current inline environment, and a 'Set Up Environments for Inline Script Files' bulk command that scans the workspace, filters to inline-script files, and sets up the selected ones. Both reuse the existing create -> setEnvironment (register project + persist + publish) pipeline via a shared setUpInlineScriptEnvironment helper. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🔒 Automated review in progress — Rich Chiodo (@rchiodo) is auto-reviewing this PR. |
Rich Chiodo (rchiodo)
left a comment
There was a problem hiding this comment.
Review center is taking too long. Looks fine to me.
| return environment; | ||
| } | ||
|
|
||
| function setupInlineScriptEnvironmentHandler( |
There was a problem hiding this comment.
Warning · Non-blocking recommendation
For bulk-selected scripts that have not been observed by the routing registry, can getMetadataIdentity be undefined both before and after create? If so, saving changed metadata while setup runs bypasses this guard and associates an environment built from stale metadata. Preserve the discovered identity or re-read metadata before associating, and cover this unopened-file race.
| routing.setValidatedAssociation(scriptUri, true); | ||
|
|
||
| sub.dispose(); | ||
| assert.ok(fireCount >= 1, 'onDidChangeCodeLenses should fire when routing state changes'); |
There was a problem hiding this comment.
Warning · Non-blocking recommendation
This test can pass solely because setMetadata fires the counter, even if routeability changes never refresh CodeLens. Reset the counter after setting metadata, then assert that setValidatedAssociation independently fires the event.
|
Result: 🔴 Verification detailsVerification: Isolated verification observed failures that were not classified as caused by this PR: Repository test-discovery preflight. The relevant tests could not be fully run in the isolated environment; this review is not fully verified. Summary: Verification could not run because the container lacked a usable repository checkout and `npm`. The targeted command `npm run compile-tests && npm run unittest -- --grep ...` stopped with `npm: not found`, so none of the 11 added tests executed. Coverage inspection found the configured-script preselection behavior untested. Confidence is limited to static test inventory. Test runs: 1 failed, 1 not run
|
3570eeb
into
microsoft:main
Roadmap context
This implements the two PEP 723 Phase 4 (UX) PRs together, since they share one setup pipeline:
Everything is gated behind the internal, undeclared
python-envs.inlineScripts.enabledflag (default off, latched at activation) and, per the roadmap, nothing is contributed inpackage.json— the commands are registered programmatically (hidden, likepython-envs.clearScriptEnvCache) and the CodeLens provider is only registered when the flag is on. With the flag off (every user today), there is no behavior change.What this adds
.pyfile's# /// scriptblock, shown only when the file has saved PEP 723 metadata that is not currently backed by a validated inline-script environment. It hides once setup completes and reappears if a later metadata change invalidates the association..pyfiles (excluding.venv/node_modules, capped), keeps those that declare a# /// scriptblock, offers a multi-select quick pick (already-configured scripts shown but not pre-checked), and runs setup for each selection.setUpInlineScriptEnvironmenthelper: reuses the pipeline earlier PRs already built —InlineScriptEnvManager.create(select/uv-install a compatible base, build the cached venv, install deps) followed bysetEnvironment(register the exact script project (PR 10), persist the association (PR 7), and publish the per-file change so routing (PR 9) picks it up).Behavior / safety notes
InlineScriptRoutingRegistry(getMetadata+shouldRoute); it also returns[]for a dirty document (the manager validates against the saved file).createand skips associating if it changed during the build, so a slow setup can't overwrite a newer one.isLocalPythonFile/ extension checks are case-insensitive where it matters; bulk setup runs sequentially (avoids overlapping modal uv prompts) and is idempotent (cache reuse).Testing
tsc -p . --noEmit,eslint, and Prettier: clean.src/test/features/inlineScript/codeLens.unit.test.ts,setupEnvironment.unit.test.ts) cover CodeLens visibility (no metadata / metadata-but-unrouteable / routeable / dirty), the create→set helper (including the metadata-changed-during-create guard), and the bulk filter/selection/loop.npm run unittest): 1969 passing.Scope
UX only; no change to the parsing/manager/routing internals and no
package.jsoncontributions. The bulk command is implemented but intentionally has no palette entry yet — exposing these surfaces to users is a later, deliberate step.