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

feat(api): pass local version label to build backend interface #814

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

finswimmer
Copy link
Member

@finswimmer finswimmer commented Jan 13, 2025

Adds the ability to pass a local version label to the build backend via config_settings as described in PEP 517

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

Summary by Sourcery

Add the ability to pass a local version label to the build backend interface, allowing for more flexible versioning in builds. Update the Builder class to handle config_settings and apply local version labels to package versions. Include tests to ensure the new feature works as expected.

New Features:

  • Add support for passing a local version label to the build backend via config_settings, as per PEP 517.

Tests:

  • Introduce tests to verify the functionality of building wheels, sdists, and editable wheels with a local version label.

Copy link

sourcery-ai bot commented Jan 13, 2025

Reviewer's Guide by Sourcery

This pull request introduces the ability to pass a local version label to the build backend via 'config_settings', as per PEP 517. The implementation includes modifications to the Builder class to handle configuration settings and apply local version labels during package builds. Additionally, comprehensive tests have been added to ensure the correct functionality of building wheels, sdists, and editable wheels with local version labels.

Sequence diagram for local version label application during build

sequenceDiagram
    participant Client
    participant Builder
    participant Poetry
    participant Package

    Client->>Builder: create(poetry, config_settings)
    activate Builder
    Builder->>Builder: __init__()
    Builder->>Builder: _apply_local_version_label()
    alt has local version label
        Builder->>Poetry: get package
        Poetry->>Package: get version
        Package-->>Builder: current version
        Builder->>Package: replace(local=local_version_label)
    end
    deactivate Builder
Loading

Class diagram showing Builder class modifications

classDiagram
    class Builder {
        +str|None format
        -Poetry _poetry
        -dict _config_settings
        -Path _path
        -set|None _excluded_files
        +__init__(poetry: Poetry, executable: Path|None, config_settings: dict|None)
        +build(target_dir: Path|None) Path
        -_apply_local_version_label()
        +executable() Path
        +default_target_dir() Path
    }
    note for Builder "Added config_settings parameter and local version handling"
Loading

Flow diagram for build process with local version

flowchart TD
    A[Start Build] --> B{Has config_settings?}
    B -->|Yes| C{Has local-version?}
    B -->|No| E[Continue Build]
    C -->|Yes| D[Apply local version label]
    C -->|No| E
    D --> E
    E --> F[Build package]
    F --> G[End Build]
Loading

File-Level Changes

Change Details Files
Added support for local version labels in package builds via config settings.
  • Introduced a new parameter 'config_settings' in the Builder class to handle configuration settings.
  • Implemented a method '_apply_local_version_label' to apply the local version label to the package version.
  • Modified the WheelBuilder and SdistBuilder to accept 'config_settings' and apply the local version label during build processes.
src/poetry/core/masonry/builders/builder.py
src/poetry/core/masonry/api.py
src/poetry/core/masonry/builders/wheel.py
Added tests for building packages with local version labels.
  • Created test cases for building wheels with local version labels.
  • Created test cases for building sdists with local version labels.
  • Created test cases for preparing metadata with local version labels.
  • Created test cases for building editable wheels with local version labels.
tests/masonry/test_api.py
tests/masonry/builders/test_builder.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 13, 2025 20:29
@finswimmer finswimmer requested a review from a team January 13, 2025 20:29
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 documentation for the new local-version config setting to help users understand how to use this feature.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 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.

src/poetry/core/masonry/api.py Outdated Show resolved Hide resolved
src/poetry/core/masonry/api.py Outdated Show resolved Hide resolved
@finswimmer finswimmer force-pushed the local-version-to-api branch from 25e0ccf to 90a5e9e Compare January 13, 2025 20:37
@finswimmer
Copy link
Member Author

@sourcery-ai review

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 documentation for the new local version label feature, including how to use it and examples of valid values for the local-version config setting.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟡 Complexity: 1 issue found
  • 🟢 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.

tests/masonry/test_api.py Show resolved Hide resolved
src/poetry/core/masonry/api.py Outdated Show resolved Hide resolved
@finswimmer finswimmer force-pushed the local-version-to-api branch from 90a5e9e to fd81a1c Compare January 13, 2025 20:46
src/poetry/core/masonry/api.py Outdated Show resolved Hide resolved
@abn
Copy link
Member

abn commented Jan 13, 2025

@finswimmer also see #715

fix: `update`, `add` and `remove` shall not uninstall extra dependencies

With this change unrequested extras dependencies will also be kept when running `install` and are only removed when running `sync`!
Fix`build`  help regarding `--clean` (#9994)
@finswimmer finswimmer force-pushed the local-version-to-api branch from fd81a1c to 677b346 Compare January 14, 2025 07:21
@finswimmer
Copy link
Member Author

@sourcery-ai review

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 documentation for the new local version label config setting feature. Since this implements a PEP 517 capability, it should be documented for users who want to utilize this functionality.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 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.

src/poetry/core/masonry/builders/builder.py Show resolved Hide resolved
tests/masonry/test_api.py Show resolved Hide resolved
@finswimmer finswimmer requested a review from abn January 14, 2025 08:57
@@ -72,6 +82,13 @@ def executable(self) -> Path:
def default_target_dir(self) -> Path:
return self._path / "dist"

def _apply_local_version_label(self) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

nit picky, but can we make this more generic so we can add other config settings in the future? apply_config_settings or something?

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about it too, but came to the conclusion that the point when a config setting is applied depends on what the setting is for. So I decided for a specific method name for now.

Copy link
Member

Choose a reason for hiding this comment

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

In that case why even bother with a method? why not just do that inline?

Copy link
Member Author

Choose a reason for hiding this comment

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

In that case why even bother with a method? why not just do that inline?

Readability 😃 I don't want to mess up the init Method with logic.

Copy link
Member

Choose a reason for hiding this comment

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

/shrug not sure if that adds much in terms of readability right now, in fact I feel it is the other way. That said, not going to block on this as it does what it says on the tin, we can always re-evaluate later.

@abn
Copy link
Member

abn commented Jan 14, 2025

@finswimmer since this is getting merged, can you please coordinate with the author of #715 to see what needs to be done there now.

@abn abn merged commit f11dda9 into python-poetry:main Jan 14, 2025
18 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.

3 participants