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

Add support for command-specific configuration sections #1966

Merged
merged 6 commits into from
Jan 3, 2024

Conversation

chrysle
Copy link
Contributor

@chrysle chrysle commented Aug 14, 2023

Addresses #1933 (comment)

This introduces configuration sections specific to pip-compile and pip-sync.

I'd like to refactor the make_config_file() pytest fixture in a follow-up PR, to introduce tests for this feature using multiple configuration sections.

Contributor checklist
  • Included tests for the changes.
  • PR title is short, clear, and ready to be included in the user-facing changelog.
Maintainer checklist
  • Verified one of these labels is present: backwards incompatible, feature, enhancement, deprecation, bug, dependency, docs or skip-changelog as they determine changelog listing.
  • Assign the PR to an existing or new milestone for the target version (following Semantic Versioning).

@chrysle chrysle added feature Request for a new feature config Related to pip-tools' configuration labels Aug 14, 2023
@webknjaz
Copy link
Member

webknjaz commented Aug 14, 2023

Could you adjust the PR title to match the description? Currently it reads as if you're adding features but the text suggests that it's tests.
So it wouldn't hurt to be more specific — it'll end up in the changelog, after all.

@chrysle
Copy link
Contributor Author

chrysle commented Aug 14, 2023

Thanks, it's actually this pull request I'd like to add more tests for (codecov is failing), but that needs some refactoring and doesn't really fit in. I've adjusted the description.

@webknjaz
Copy link
Member

webknjaz commented Aug 14, 2023

Ah, though I still don't understand what's tool-specific configuration. That title is just to generic to mean anything to me. It's quite unspecific wrt what it refers to. We already have pip-tools specific config, after all. That's the tool, right?

@chrysle
Copy link
Contributor Author

chrysle commented Aug 14, 2023

We already have pip-tools specific config, after all. That's the tool, right?

Yeah, but that is the global configuration (for both pip-compile and pip-sync). I added the possibility to specify configuration values only for those commands. I added some docs to the README.

Is the title better now?

@chrysle chrysle changed the title Add support for tool-specific configuration Add support for command-specific configuration sections Aug 14, 2023
@webknjaz
Copy link
Member

Is the title better now?

Much better, thanks! Titles shows up in email notifications among other places and tend to be a factor in deciding whether to even look inside. This is especially important when inbox is overflowing and people need to prioritize + figure out which notifications to discard. An accurate title helps draw attention of people who might be affected by the patch.

Copy link
Member

@webknjaz webknjaz left a comment

Choose a reason for hiding this comment

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

Initial review. I foresee the need to refactor things here and avoid complicating things.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
if config:
_validate_config(ctx, config)
_assign_config_to_cli_context(ctx, config)
piptools_config, pipcompile_config, pipsync_config = parse_config_file(
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's a good idea to return a tuple. If it is really necessary to have all these bits of data, wrap them into an object (dataclass?) and return that.

Though, I'd argue it should return a single config instead. Maybe, we need to pass an argument telling it for which command that config is to be extracted..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I can move the test below to parse_config_file().

Copy link
Member

@theryanwalker theryanwalker Aug 14, 2023

Choose a reason for hiding this comment

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

Suggested change
piptools_config, pipcompile_config, pipsync_config = parse_config_file(
config = Config.parse_file(config_file)

Given that you're in the process of refactoring this, how about introducing a Config class in piptools/config.py and moving the related logic there? This is an example of what the Config might look like:

@dataclass
class Config:
    pip_tools: dict[str, Any]
    pip_compile: dict[str, Any]
    pip_sync: dict[str, Any]
    
    @classmethod
    def parse_file(filename):
        ...

    def validate(self):
        ...
        
    def normalize_keys(self):
        ...
    
    def invert_negative_bool_options(self, ctx):
        ...
        
    def get_default_map() -> dict[str, Any]:
        ...
     
    def assign_to_cli(ctx):
        ...    

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@atugushev What do you think, should we dedicate an own file to that?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds great 👍🏻

Copy link
Member

Choose a reason for hiding this comment

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

@theryanwalker I like it, though I'd probably go for a different construction/classmethod name. How about Config.from_file_path()?

piptools/utils.py Outdated Show resolved Hide resolved
tests/test_cli_sync.py Show resolved Hide resolved
@chrysle chrysle requested a review from webknjaz August 26, 2023 09:26
piptools/utils.py Outdated Show resolved Hide resolved
piptools/utils.py Outdated Show resolved Hide resolved
@webknjaz
Copy link
Member

webknjaz commented Nov 2, 2023

@chrysle looks like this also needs to be rebased due to conflicts in tests.

piptools/utils.py Outdated Show resolved Hide resolved
piptools/utils.py Outdated Show resolved Hide resolved
piptools/utils.py Outdated Show resolved Hide resolved
piptools/utils.py Outdated Show resolved Hide resolved
tests/conftest.py Outdated Show resolved Hide resolved
chrysle and others added 3 commits January 2, 2024 15:17
Also tweak the wording in the configuration section of the README.

Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
@chrysle chrysle force-pushed the support-tool-specific-configuration branch 3 times, most recently from ad42514 to a6f9f11 Compare January 2, 2024 14:26
piptools/utils.py Outdated Show resolved Hide resolved
tests/test_cli_compile.py Outdated Show resolved Hide resolved
@chrysle chrysle force-pushed the support-tool-specific-configuration branch from a6f9f11 to 8bb2937 Compare January 2, 2024 14:34
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
@chrysle chrysle force-pushed the support-tool-specific-configuration branch from 8bb2937 to ec50d5e Compare January 2, 2024 14:35
@chrysle
Copy link
Contributor Author

chrysle commented Jan 2, 2024

Thank you for your suggestions and sorry for the long delay.
My code style is simply terrible... My new year's resolution definitely includes paying more attention in computer science class.

piptools/utils.py Outdated Show resolved Hide resolved
Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
@webknjaz
Copy link
Member

webknjaz commented Jan 2, 2024

@chrysle hey, no problem! This is open source and nobody expects free labor to be a top priority of every contributor.

Also, the code style is something that evolves and is subjective most of the time. People are only expected to unconditionally adhere what automatic checks say. Otherwise, code reviews is a multi-party discussion that exists to agree on things and receive insights from other people that aren't related to code style.

At times, it may feel like some comments are about code style at glance, but usually, there's more important underlying issues that motivate people to make suggestions. It's mostly a perception thing. I know that my comments are often seen as style nitpicks while I write them with maintainability in mind, informed by architectural considerations, usually.

Here's a few links that I collected about code reviews, by the way: https://gist.github.com/webknjaz/2aa9c7a43b51c1385260ff87e0cbb9e3.

P.S. The linkcheck job is failing because jazzband.co has a TLS certificate that expired on Dec 30 last year and wasn't auto-renewed for some reason. A tagged @jezdez on matrix so he could take a look.
This blocks merging the PR, but once fixed, restarting that one failing job should unblock us.

@chrysle
Copy link
Contributor Author

chrysle commented Jan 3, 2024

Thank you for your encouraging words and the time you invest into reviewing my code!
I'll also still have to solve the mystery how people get the right ideas for founding successful open source projects ;-)

@webknjaz webknjaz added this pull request to the merge queue Jan 3, 2024
Merged via the queue into jazzband:main with commit 129d099 Jan 3, 2024
36 checks passed
@chrysle chrysle deleted the support-tool-specific-configuration branch January 3, 2024 21:24
@atugushev atugushev added this to the 7.4.0 milestone Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config Related to pip-tools' configuration feature Request for a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants