poetry icon indicating copy to clipboard operation
poetry copied to clipboard

cli: suggest poetry self lock for self subcommands (#10536)

Open gabriel-trigo opened this issue 5 months ago • 1 comments

  • Add lock_command_hint_for() to choose hint by lockfile location (CONFIG_DIR → poetry self lock, else poetry lock).
  • Use in installer (stale lock), show (missing lock), and check (stale lock).

Motivation

  • Avoids suggesting poetry lock for poetry self … commands (fixes confusion in #10536).

Tests

  • tests/installation/test_installer.py::test_not_fresh_lock_in_self_context_suggests_self_lock
  • tests/console/commands/self/test_show.py::test_self_show_errors_without_lock_file

Compatibility

  • Project commands still suggest poetry lock.

Resolves: #10536

Pull Request Check List

  • [x] Added tests for changed code.
  • [ ] Updated documentation for changed code. (N/A)

Summary by Sourcery

Improve lock-related error messages by detecting when commands are running in Poetry’s own configuration directory and suggesting poetry self lock instead of poetry lock where applicable

New Features:

  • Introduce lock_command_hint_for helper to choose between poetry lock and poetry self lock based on lockfile location
  • Integrate lock_command_hint_for into show, check, and installer commands to suggest the appropriate lock command

Tests:

  • Add test verifying poetry self lock suggestion when lock is stale in self context installer
  • Add test verifying missing lock file error suggests poetry self lock in show command

gabriel-trigo avatar Sep 24 '25 01:09 gabriel-trigo

Reviewer's Guide

Introduces a helper to choose between poetry self lock and poetry lock based on the lockfile location, and updates the show, check, and installer commands to use this dynamic hint in their error messages, with new tests verifying the behavior in self contexts.

File-Level Changes

Change Details Files
Helper for dynamic lock command hints
  • Add lock_command_hint_for in utils/helpers to return poetry self lock when the lock file is in CONFIG_DIR, otherwise poetry lock with a fallback on import errors
src/poetry/utils/helpers.py
Use dynamic hints in CLI commands
  • Import and invoke lock_command_hint_for to generate the appropriate hint
  • Replace hardcoded poetry lock in the missing-lock error message in the show command
  • Replace hardcoded poetry lock in stale-lock errors in the check and installer commands
src/poetry/console/commands/show.py
src/poetry/console/commands/check.py
src/poetry/installation/installer.py
Add tests for self subcommands
  • Test that missing lock in the self show command suggests poetry self lock
  • Test that stale lock in installer self context raises with a hint to run poetry self lock
tests/console/commands/self/test_show.py
tests/installation/test_installer.py

Possibly linked issues

  • #10536: PR introduces lock_command_hint_for to suggest poetry self lock for self subcommands, fixing the incorrect hint.
  • #10536: The PR clarifies self command behavior by suggesting poetry self lock for Poetry's own project, addressing confusion related to issue #10536.

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. You can also reply to a review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull request title to generate a title at any time. You can also comment @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you want it. You can also comment @sourcery-ai summary on the pull request to (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment @sourcery-ai review to trigger a new review!

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

  • Contact our support team for questions or feedback.
  • Visit our documentation for detailed guides and information.
  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.

sourcery-ai[bot] avatar Sep 24 '25 01:09 sourcery-ai[bot]