poetry icon indicating copy to clipboard operation
poetry copied to clipboard

fix: respect local config file in `poetry python` commands

Open finswimmer opened this issue 4 months ago • 1 comments

https://github.com/python-poetry/poetry/pull/10595 should be merged first, otherwise we are unable to set the relevant configs anyway.

Pull Request Check List

Resolves: #issue-number-here

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

Summary by Sourcery

Enhancements:

  • Add PoetryPythonPathProvider.base_installation_dir to load and merge local poetry.toml into the config for determining python installation paths

finswimmer avatar Oct 24 '25 09:10 finswimmer

Reviewer's Guide

This PR refactors the determination of Poetry’s python installation directory by introducing a new base_installation_dir method that merges settings from a local poetry.toml, and updates all provider implementations and console commands to use this method instead of directly calling Config.create().

Class diagram for updated PoetryPythonPathProvider and related usage

classDiagram
    class PoetryPythonPathProvider {
        +base_installation_dir() Path
        +installation_dir(version: Version, implementation: str) Path
        +_make_bin_paths(base: Path | None) list[Path]
    }
    class Config {
        +create() Config
        python_installation_dir Path
        +merge(data)
    }
    class TOMLFile {
        +read()
        +exists()
    }
    class Factory {
        +locate()
    }
    class PythonInstaller
    class python_remove_py
    class python_list_py
    PoetryPythonPathProvider --|> PathProvider
    PoetryPythonPathProvider ..> Config : uses
    PoetryPythonPathProvider ..> TOMLFile : uses
    PoetryPythonPathProvider ..> Factory : uses
    PythonInstaller o-- PoetryPythonPathProvider : uses base_installation_dir
    python_remove_py o-- PoetryPythonPathProvider : uses installation_dir
    python_list_py o-- PoetryPythonPathProvider : uses base_installation_dir

Flow diagram for resolving python installation directory with local config

flowchart TD
    A["Start: Need python installation directory"] --> B["Check for local poetry.toml config file"]
    B -->|Exists| C["Merge local config into main config"]
    B -->|Does not exist| D["Use main config only"]
    C --> E["Return python_installation_dir from merged config"]
    D --> E
    E["Directory used for python installation"]

File-Level Changes

Change Details Files
Added base_installation_dir method that merges local poetry.toml into the global config
  • Implemented classmethod in PoetryPythonPathProvider to locate and read local poetry.toml
  • Merged local config into default Config object under a suppress context
  • Exposed merged python_installation_dir as base_installation_dir
src/poetry/utils/env/python/providers.py
Updated provider methods to use the new base_installation_dir
  • Changed installation_dir to call base_installation_dir
  • Updated _make_bin_paths to fall back on base_installation_dir
src/poetry/utils/env/python/providers.py
Replaced direct Config.create().python_installation_dir calls in CLI commands
  • Removed Config import and used PoetryPythonPathProvider.installation_dir in remove command
  • Switched list command to use PoetryPythonPathProvider.base_installation_dir
src/poetry/console/commands/python/remove.py
src/poetry/console/commands/python/list.py
Updated PythonInstaller to use the new provider for default installation directory
  • Removed direct Config.create call from default_factory
  • Switched to PoetryPythonPathProvider.base_installation_dir in installer constructor
src/poetry/utils/env/python/installer.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. 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 Oct 24 '25 09:10 sourcery-ai[bot]