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

poc: python installation management commands (experimental) #10112

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

abn
Copy link
Member

@abn abn commented Jan 25, 2025

This is a highly experimental implementation of Python installation management features for Poetry. That said, more testers the merrier. Feedback around functionality and output ux are welcome. The intent of the PR, if made ready would be to introduce the feature as an experimental feature meeting the following basic requirements:

  1. Use Python Standalone Builds with pbs-installer to provide Poetry users ability install/list/remove Python versions available.
  2. Make such Python versions accessibly for Project virtual environment creation.

Depends-on: #10097 - While, this is not a hard dependency, having findpython in the mix definitely makes discovery easier. There will have to be changes once that PR is finalized.

Resolves: #9905

Testing Changes

Using pipx

pipx install --suffix=@10112 'poetry @ git+https://github.com/python-poetry/poetry.git@refs/pull/10112/head'
alias poetry=poetry@10112
poetry python list
poetry python list --managed
poetry python list --all
poetry python install 3.13.0
poetry python list
poetry python remove 3.13.0

Using a container (podman | docker)

podman run --rm -i --entrypoint bash python:latest <<EOF
set -xe
python -m pip install --disable-pip-version-check -q git+https://github.com/python-poetry/poetry.git@refs/pull/10112/head
poetry python list
poetry python list --managed
poetry python list --all
poetry python install 3.13.0
poetry python list
poetry python remove 3.13.0
EOF

Summary by Sourcery

Add commands to manage Python installations using standalone builds. Install, list, and remove Python versions using poetry python install, poetry python list, and poetry python remove.

New Features:

  • Add experimental support for managing Python installations using standalone builds and pbs-installer.

Tests:

  • Add tests for new Python installation management commands.

Copy link

sourcery-ai bot commented Jan 25, 2025

Reviewer's Guide by Sourcery

This pull request introduces experimental Python installation management commands to Poetry, leveraging Python Standalone Builds and pbs-installer. It allows users to install, list, and remove Python versions, making them available for project virtual environment creation. The implementation focuses on integrating these tools with Poetry's existing environment management capabilities.

Sequence diagram for Python installation process

sequenceDiagram
    participant User
    participant PythonInstallCmd
    participant PBSInstaller
    participant PoetryPythonPathProvider
    User->>PythonInstallCmd: poetry python install <version>
    PythonInstallCmd->>PBSInstaller: get_download_link(version)
    PBSInstaller-->>PythonInstallCmd: download link
    PythonInstallCmd->>PBSInstaller: install(version, path)
    PBSInstaller-->>PythonInstallCmd: installation complete
    PythonInstallCmd->>PoetryPythonPathProvider: test installation
    PoetryPythonPathProvider-->>PythonInstallCmd: test results
    PythonInstallCmd-->>User: installation status
Loading

Class diagram for Python management classes

classDiagram
    class Python {
        -_python: findpython.PythonVersion
        +executable: Path
        +version: Version
        +patch_version: Version
        +minor_version: Version
        +find_all()
        +get_active_python()
        +from_executable(path)
        +get_system_python()
        +get_by_name(python_name)
        +get_preferred_python(config, io)
        +get_compatible_python(poetry, io)
    }
    class PoetryPythonPathProvider {
        +installation_dir(version, implementation)
        +_make_bin_paths(base)
        +installation_bin_paths(version, implementation)
        +create()
    }
    class Config {
        +virtualenvs_path: Path
        +python_installation_dir: Path
        +installer_max_workers: int
    }
    Python --* PoetryPythonPathProvider
    note for Python "Refactored to use findpython"
    note for PoetryPythonPathProvider "New provider for Python paths"
Loading

File-Level Changes

Change Details Files
Integration of findpython library for Python discovery.
  • Replaced custom Python discovery logic with findpython.
  • Registered a custom provider to find Poetry managed Python installations.
  • Modified the Python class to use findpython.PythonVersion objects.
src/poetry/utils/env/python_manager.py
Addition of Python installation management commands.
  • Implemented 'poetry python install' command to download and install Python versions.
  • Implemented 'poetry python list' command to display available Python versions.
  • Implemented 'poetry python remove' command to remove Poetry managed Python versions.
src/poetry/console/commands/python/install.py
src/poetry/console/commands/python/list.py
src/poetry/console/commands/python/remove.py
Configuration and data directory setup.
  • Added a 'data-dir' configuration option.
  • Added a 'python.installation-dir' configuration option.
  • Created a fixture for the data directory.
src/poetry/config/config.py
tests/conftest.py
Refactoring and updates to existing tests.
  • Updated tests to use mocked findpython library.
  • Added fixtures for mocking Python versions.
  • Adjusted tests to accommodate changes in Python discovery.
tests/utils/env/test_env_manager.py
tests/utils/test_python_manager.py
tests/console/commands/test_config.py
tests/console/commands/test_new.py
tests/console/commands/test_init.py
tests/console/commands/env/test_use.py
tests/types.py
Dependency updates.
  • Added 'findpython' and 'pbs-installer' as dependencies.
pyproject.toml
poetry.lock
Command registration.
  • Registered the new python commands.
src/poetry/console/application.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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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

@abn abn force-pushed the feat/python-commands branch 3 times, most recently from 37a8ea1 to 0856383 Compare January 25, 2025 19:34
@abn abn force-pushed the feat/python-commands branch from 0856383 to 3d4aa3f Compare January 27, 2025 00:16
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.

Can install the right Python version like PDM and UV do
1 participant