Skip to content

refactor: decouple CLI from custom method arguments #1999

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

Closed
wants to merge 1 commit into from

Conversation

nejch
Copy link
Member

@nejch nejch commented May 1, 2022

A more generic approach for #1985

This helps towards #1982. This way, instead of handling parameters in every individual custom method, we can add them in a more declarative way in the decorators and just pull payload in POST/PUT methods from that.

It will also help us completely decouple the CLI from the API client hopefully - making it easier to switch libraries or approaches if we can untangle this.

@codecov-commenter
Copy link

codecov-commenter commented May 1, 2022

Codecov Report

Merging #1999 (5628004) into main (0e3c461) will increase coverage by 0.05%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1999      +/-   ##
==========================================
+ Coverage   94.62%   94.68%   +0.05%     
==========================================
  Files          78       78              
  Lines        4983     5038      +55     
==========================================
+ Hits         4715     4770      +55     
  Misses        268      268              
Flag Coverage Δ
cli_func_v4 82.77% <100.00%> (+0.19%) ⬆️
py_func_v4 81.16% <100.00%> (+0.20%) ⬆️
unit 85.74% <100.00%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
gitlab/base.py 100.00% <100.00%> (ø)
gitlab/cli.py 100.00% <100.00%> (ø)
gitlab/exceptions.py 100.00% <100.00%> (ø)
gitlab/mixins.py 92.24% <100.00%> (+0.08%) ⬆️
gitlab/types.py 98.11% <100.00%> (+0.03%) ⬆️
gitlab/v4/objects/artifacts.py 100.00% <100.00%> (ø)
gitlab/v4/objects/commits.py 95.06% <100.00%> (+0.18%) ⬆️
gitlab/v4/objects/container_registry.py 96.42% <100.00%> (+0.13%) ⬆️
gitlab/v4/objects/deploy_keys.py 96.55% <100.00%> (+0.12%) ⬆️
gitlab/v4/objects/files.py 100.00% <100.00%> (ø)
... and 7 more

@nejch nejch marked this pull request as ready for review May 1, 2022 19:20
@nejch nejch requested review from JohnVillalovos and max-wittig May 1, 2022 19:20
@nejch
Copy link
Member Author

nejch commented May 1, 2022

Incidentally this makes a few of the decorators a bit more readable.. and should be much more readable when I get to removing the @cli.register_custom_action somehow, to completely get rid of the CLI from the API client itself.

Copy link
Member

@JohnVillalovos JohnVillalovos left a comment

Choose a reason for hiding this comment

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

Sorry for the short review. I haven't yet read the whole PR but wanted to leave a couple comments.

@nejch nejch force-pushed the refactor/decouple-cli-from-custom-args branch from c8d6dcc to 8d3de21 Compare May 29, 2022 16:03
@nejch nejch force-pushed the refactor/decouple-cli-from-custom-args branch from 8d3de21 to 4561157 Compare June 6, 2022 08:34
@nejch nejch force-pushed the refactor/decouple-cli-from-custom-args branch from 4561157 to 5628004 Compare June 6, 2022 08:41
@nejch nejch requested a review from JohnVillalovos June 6, 2022 08:58
@nejch
Copy link
Member Author

nejch commented Jun 6, 2022

@JohnVillalovos this should be ready for another round I think. If the value of this PR isn't really clear I can add a draft PR built on top of it, where I start removing custom argument parsing from some of the custom methods to start demoing that, similar to what I did in https://github.com/python-gitlab/python-gitlab/pull/1985/files.

@@ -721,7 +720,8 @@ def time_stats(self, **kwargs: Any) -> Dict[str, Any]:
assert not isinstance(result, requests.Response)
return result

@cli.register_custom_action(("ProjectIssue", "ProjectMergeRequest"), ("duration",))
@cli.register_custom_action(("ProjectIssue", "ProjectMergeRequest"))
Copy link
Member

Choose a reason for hiding this comment

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

What happens if these two decorators are put in reverse order?

Does it work? My guess is no. If not, do we detect a problem? My guess is also no.

If my guesses are correct can we add a way to detect improper usage and make sure the unit tests or something else fails?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question.. the thing is that, as I said in the comment above #1999 (comment), @cli.register_custom_action is the very next thing we'd want to get rid of if we want to fully decouple the CLI from the client. :( So not sure we should invest time in that and then remove it right after. 🤔


My idea for that was, instead of manually assigning custom methods to classes at each method definition, simply collect all non-standard (create,..) public methods for each Manager and RESTObject in the CLI module, kind of how we already collect the classes for the CLI:
https://github.com/python-gitlab/python-gitlab/blob/main/gitlab/cli.py#L97

Let me check if I can do that in a clean way in a separate commit or follow-up PR, I'll mark this a draft until then.

Maybe it makes sense I open an issue with a mini roadmap to untangling the CLI from the API so we have clear steps on how to get there.

@JohnVillalovos
Copy link
Member

JohnVillalovos commented Jun 6, 2022

Thanks @nejch

Some quick comments

Can the commit message be improved? It seems to only have a subject line.

Am I correct in thinking (based on looking at https://github.com/python-gitlab/python-gitlab/pull/1985/files) that the _custom_attrs will be used to determine which values should be sent in the POST body versus in the URL string? If I am correct, would it make more sense to figure out what can not be in the POST body and put everything that can be in the POST body by default? For example sudo is something that has to be in the query-string (or header) but not in the POST body. Maybe there are a few others like that??

@nejch nejch marked this pull request as draft June 7, 2022 06:56
@nejch
Copy link
Member Author

nejch commented Aug 6, 2022

Closing this to reduce the number of drafts open - I'll keep the branch and reopen when ready.

@nejch nejch closed this Aug 6, 2022
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