Skip to content

Add basic Poetry environment lifecycle support - #1700

Draft
Eduardo Villalpando Mello (edvilme) wants to merge 2 commits into
mainfrom
poetry-environment-lifecycle
Draft

Eduardo Villalpando Mello (edvilme) wants to merge 2 commits into
mainfrom
poetry-environment-lifecycle

Conversation

@edvilme

Copy link
Copy Markdown
Contributor

Summary

  • add basic Poetry environment creation for existing projects using a selected global Python 3 interpreter
  • add Poetry environment removal with owning-project detection and selection/cache cleanup
  • add lifecycle unit coverage for creation, package failures, reused environments, removal, and multi-project associations

Validation

  • npm run lint
  • npm run compile-tests
  • npm run unittest

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 6b2fe9b5-38ea-442f-b07a-b6c71134d480

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds basic Poetry environment creation and removal for existing Python projects.

Changes:

  • Creates Poetry environments using global Python 3 interpreters.
  • Removes environments and clears cached selections.
  • Adds localized lifecycle messages and unit coverage.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/managers/poetry/poetryManager.ts Implements Poetry lifecycle operations.
src/managers/poetry/main.ts Supplies the output channel.
src/common/localize.ts Adds lifecycle messages.
src/test/managers/poetry/poetryManager.createRemove.unit.test.ts Tests creation and removal flows.
Suppressed comments (1)

src/managers/poetry/poetryManager.ts:208

  • After deleting the project mapping, get(root) falls back to globalEnv, but this event always reports new: undefined. When a different global Poetry environment exists, listeners receive a selection that disagrees with the manager's actual result. Report that fallback, except when the global environment is the one being removed.
                        new: undefined,

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/managers/poetry/poetryManager.ts Outdated
Comment on lines +151 to +155
this._onDidChangeEnvironment.fire({
uri: projectRoot,
old: previousEnvironment,
new: environment,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gated both _onDidChangeEnvironment.fire calls: create() now only fires when previousEnvironment?.envId.id !== environment.envId.id, and remove() only fires when there was actually a previous mapping for that project root. Addressed in 91628e9.

Comment thread src/managers/poetry/poetryManager.ts Outdated
Comment on lines +563 to +565
const environments = await this.api.getEnvironments('global');
const baseEnvironment = getLatest(
environments.filter(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched getBaseEnvironment() to read api.getEnvironment(undefined) and validate that the user's selected global interpreter is Python 3, has a run executable, and isn't itself a Poetry environment. Falls back to the noPython error otherwise, so the user's selection is honored instead of picking the highest global. Addressed in 91628e9.

Comment thread src/managers/poetry/poetryManager.ts Outdated
Comment on lines +554 to +555
if (scope === 'global' || (Array.isArray(scope) && scope.length !== 1)) {
throw new Error(PoetryStrings.create.singleProject);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled the global scope in the manager: getCreateProjectRoot() now distinguishes 'global' / empty-array scopes from the multi-project case and throws a dedicated, localized globalNotSupported message so the user sees a clear reason when Poetry is picked from the global creation flow, instead of the misleading "one project at a time" error. A scope-aware API-level filter is a bigger change that's out of scope for this PR. Addressed in 91628e9.

Co-authored-by: edvilme <5952839+edvilme@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants