Skip to content

Conversation

@finswimmer
Copy link
Member

@finswimmer finswimmer commented Nov 3, 2025

Pull Request Check List

Resolves: #10541
Resolves: #10287

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

Summary by Sourcery

Resolve the application's working directory to an absolute path when a relative --directory option is provided and expose it via a new property, with corresponding test updates.

New Features:

  • Add a working_directory property to expose the internal working directory Path

Enhancements:

  • Call resolve() on the directory path in _configure_global_options to convert relative paths to absolute

Tests:

  • Add a test to verify that passing a relative directory parameter yields an absolute WorkingDirectory
  • Update the existing version command test to assert usage of the application.working_directory property

@sourcery-ai
Copy link

sourcery-ai bot commented Nov 3, 2025

Reviewer's Guide

Adds a working_directory property to the Application, ensures it is resolved to an absolute path when provided via the --directory option, and updates tests to verify this behavior.

Sequence diagram for resolving working directory to absolute path

sequenceDiagram
participant IO
participant Application
IO->>Application: option("directory")
Application->>Application: ensure_path(option, is_directory=True)
Application->>Application: .resolve() (make absolute)
Application->>Application: set _working_directory
Loading

Class diagram for updated Application class

classDiagram
class Application {
  +project_directory: Path
  +working_directory: Path
  +poetry: Poetry
  _project_directory: Path
  _working_directory: Path
  _default_definition(): Definition
  _configure_global_options(io: IO): None
}
Application : +working_directory
Application : +project_directory
Application : +poetry
Loading

File-Level Changes

Change Details Files
Expose Application.working_directory via a public property
  • Added a @Property working_directory
  • Return self._working_directory in the new property
src/poetry/console/application.py
Resolve the working directory to an absolute path when parsing the --directory option
  • Appended .resolve() to the ensure_path call
  • Assigned the resolved path back to _working_directory
src/poetry/console/application.py
Update and add tests to verify the new working_directory behavior
  • Assert the application instance type and use application.working_directory instead of Path.cwd() in the mock
  • Modify existing test to expect the working_directory property
  • Add a new test for relative --directory parameter yielding an absolute path
tests/console/test_application_global_options.py

Assessment against linked issues

Issue Objective Addressed Explanation
#10541 Ensure that when poetry is run with a relative path via the -C/--directory option, the working directory is resolved to an absolute path before use, so that generated shebangs in installed scripts (e.g., .venv/bin/pytest) use the correct absolute path to the Python interpreter.
#10541 Add tests to verify that passing a relative directory parameter results in the working directory being set to the absolute path, and that this is reflected in output and behavior.

Possibly linked issues


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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant