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

Set up command construction to support generic iterables and mappings #595

Merged

Conversation

LewisGaul
Copy link
Collaborator

@LewisGaul LewisGaul commented May 25, 2024

First step in working on #584.

  • Command.add_args_list() previously had a misleading name and type annotation - it is used for accepting either a list or a single item. Renamed to Command.add_args_iterable_or_single().
  • Added Command.add_args_iterable() for the case you know you're dealing with an iterable (more efficient than always creating a new list).
  • Updated utils.to_list() to support generic iterables (still always returns a list, as per the name - my plan is to phase out its use where it's not needed).
  • Updated utils.format_dict_for_cli() to support generic mappings.
  • Added Command.add_args_mapping() as a convenience that wraps utils.format_dict_for_cli(), which will allow tidying up code that constructs commands.

Next step is to tidy up the components' code that constructs commands, allowing arguments to be Iterable and Mapping in place of List and Dict. With these changes it should be fairly straightforward, simply calling the correct method on the Command class.

Here's an example of what upcoming changes look like: LewisGaul/python-on-whales@command-construction...command-construction-image

@LewisGaul LewisGaul force-pushed the command-construction branch from 466b8cf to ac88990 Compare May 25, 2024 13:39
Copy link
Owner

@gabrieldemarmiesse gabrieldemarmiesse left a comment

Choose a reason for hiding this comment

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

Looks good overall. We can drop the speed optimisation. I don't think anyone is going to notice.

I usually refuse code that is added "to make things faster" unless there is a benchmark showing that the speed increase is noticeable.

python_on_whales/client_config.py Show resolved Hide resolved
@gabrieldemarmiesse gabrieldemarmiesse merged commit 8b05066 into gabrieldemarmiesse:master May 29, 2024
35 checks passed
@LewisGaul LewisGaul deleted the command-construction branch May 29, 2024 17:06
gabrieldemarmiesse pushed a commit that referenced this pull request Sep 5, 2024
gabrieldemarmiesse pushed a commit that referenced this pull request Sep 5, 2024
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.

2 participants