Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(console): self update didn't recognize Poetry's environment #9995

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

finswimmer
Copy link
Member

@finswimmer finswimmer commented Jan 8, 2025

Pull Request Check List

Resolves: #9964

  • Added tests for changed code.
  • Updated documentation for changed code.

Summary by Sourcery

Bug Fixes:

  • Fix an issue where self update would not recognize Poetry's environment, causing it to fail when adding a package.

Copy link

sourcery-ai bot commented Jan 8, 2025

Reviewer's Guide by Sourcery

This pull request fixes an issue where the self update command failed to recognize Poetry's environment, resulting in incorrect package installation. The fix involves updating the _system_project_handle method in src/poetry/console/commands/self/update.py to correctly set the Poetry instance within the add command's environment. This ensures that the correct package is installed during the update process.

Sequence diagram for Poetry self update command flow

sequenceDiagram
    participant User as User
    participant Update as UpdateCommand
    participant Add as AddCommand
    participant Env as Environment

    User->>Update: poetry self update
    Update->>Add: create add command
    Update->>Add: set_env(env)
    Update->>Add: set_poetry(poetry)
    Note right of Add: New step added to fix environment recognition
    Update->>Add: configure installer
    Add->>Env: install poetry package
Loading

Class diagram showing UpdateCommand and AddCommand relationship

classDiagram
    class UpdateCommand {
        -env: Environment
        -poetry: Poetry
        +_system_project_handle(): int
    }
    class AddCommand {
        -env: Environment
        -poetry: Poetry
        +set_env(env: Environment)
        +set_poetry(poetry: Poetry)
    }
    UpdateCommand ..> AddCommand : uses
    note for AddCommand "Now properly configured with Poetry instance"
Loading

File-Level Changes

Change Details Files
Set the Poetry instance in the add command's environment.
  • Added a line of code to set the Poetry instance using add_command.set_poetry(self.poetry) within the _system_project_handle method to ensure the correct environment is used during package installation.
src/poetry/console/commands/self/update.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@finswimmer finswimmer marked this pull request as ready for review January 8, 2025 12:27
@finswimmer finswimmer requested a review from a team January 8, 2025 12:27
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @finswimmer - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Please add a test case to verify the self-update command works correctly with Poetry's environment to prevent future regressions.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@abn
Copy link
Member

abn commented Jan 8, 2025

Verified that the changes work as follows.

podman run --rm -i --entrypoint bash python:latest <<EOF
export PATH="\${HOME}/.local/bin:\${PATH}"
set -xe
curl -sSL https://install.python-poetry.org | python3 -
poetry self update || :
curl -sSL https://install.python-poetry.org | POETRY_UNINSTALL=1 python3 -
curl -sSL https://install.python-poetry.org | python3 - --git 'https://github.com/python-poetry/poetry.git@refs/pull/9995/head'
poetry self update
EOF
console.output

+ curl -sSL https://install.python-poetry.org
+ python3 -
Retrieving Poetry metadata

# Welcome to Poetry!

This will download and install the latest version of Poetry,
a dependency and package manager for Python.

It will add the `poetry` command to Poetry's bin directory, located at:

/root/.local/bin

You can uninstall at any time by executing this script with the --uninstall option,
and these changes will be reverted.

Installing Poetry (2.0.0)
Installing Poetry (2.0.0): Creating environment
Installing Poetry (2.0.0): Installing Poetry
Installing Poetry (2.0.0): Creating script
Installing Poetry (2.0.0): Done

Poetry (2.0.0) is installed now. Great!

You can test that everything is set up by executing:

`poetry --version`

+ poetry self update
Updating Poetry version ...


Poetry could not find a pyproject.toml file in / or its parents
+ :
+ curl -sSL https://install.python-poetry.org
+ POETRY_UNINSTALL=1
+ python3 -
Removing Poetry (2.0.0)
+ curl -sSL https://install.python-poetry.org
+ python3 - --git https://github.com/python-poetry/poetry.git@refs/pull/9995/head
# Welcome to Poetry!

This will download and install the latest version of Poetry,
a dependency and package manager for Python.

It will add the `poetry` command to Poetry's bin directory, located at:

/root/.local/bin

You can uninstall at any time by executing this script with the --uninstall option,
and these changes will be reverted.

Installing Poetry (https://github.com/python-poetry/poetry.git@refs/pull/9995/head)
Installing Poetry (https://github.com/python-poetry/poetry.git@refs/pull/9995/head): Creating environment
Installing Poetry (https://github.com/python-poetry/poetry.git@refs/pull/9995/head): Installing Poetry
Installing Poetry (https://github.com/python-poetry/poetry.git@refs/pull/9995/head): Creating script
Installing Poetry (https://github.com/python-poetry/poetry.git@refs/pull/9995/head): Done

Poetry (https://github.com/python-poetry/poetry.git@refs/pull/9995/head) is installed now. Great!

You can test that everything is set up by executing:

`poetry --version`

+ poetry self update
Updating Poetry version ...

Using version ^2.0.0 for poetry

Updating dependencies
Resolving dependencies...

Package operations: 0 installs, 1 update, 0 removals

  - Updating poetry (2.0.0 9d84ee3 -> 2.0.0)

Writing lock file

@abn abn force-pushed the fix-self-update branch from 9d84ee3 to 1f89d4f Compare January 8, 2025 18:27
@abn abn enabled auto-merge (rebase) January 8, 2025 18:27
@abn abn merged commit b064dd7 into python-poetry:main Jan 8, 2025
73 checks passed
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.

"poetry self update" requires a pyproject.toml file
2 participants