-
Notifications
You must be signed in to change notification settings - Fork 275
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
Ngclient api polish #1604
Ngclient api polish #1604
Conversation
I think this would be a good change. It's good to have the API versatility to download targets to different locations, but I think downloading all targets to the same location is a common enough pattern that this optional constructor argument makes sense. |
It sounds good but does the API need to be that flexible, giving the option to set the
|
Good point! If we could drop the directory argument completely from the actual
(I'm just assuming refresh() is not required in these examples)
I think nothing prevents target_dir from being a modifiable public attribute that client could change if need be |
And we can escape the mutually exclusive directory<->filepath parameters! I think I'm convinced. |
fe8bfb0
to
9bb0acd
Compare
Pull Request Test Coverage Report for Build 1367591861Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
3870e46
to
b984ec5
Compare
I have incorporated the suggestions and am quite happy with the results (the PR message is also updated so check the current status there): The test code looks a lot more readable so we may be on the right track here. The only thing I don't particularly like is the constructor with 4 or even five arguments but it seems a like a good compromise I believe the PR is ready for real review. This will definitely conflict with #1591 : I would expect that one to merge first so I'll clean up afterwards |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no objections here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I like the changes.
I have only two small comments.
tuf/ngclient/updater.py
Outdated
If the ``target_dir`` argument was given to constructor, ``filepath`` | ||
argument is not required here: in this case a filename will be | ||
generated based on the target path like in ``download_target()`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will happen if target_dir is set and filepath is given?
From the code, I see that filepath is with higher priority and will be used.
Do we need to document that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense to document what the arguments default value does at least... I think that (and the text you quote) should cover all the cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove the "like in download_target()
" part. The reader of this docstring might not (and does not need to) know about download_target
when reading this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think the text could be misinterpreted that a previously set target_dir
has precedence over a passed filepath
, or that they are somehow used together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a slightly more detailed filepath
arg description would eliminate the need for this paragraph here? See below for a suggestion.
b984ec5
to
b56c363
Compare
Updated docstrings and comments based on feedback (only "ngclient: Simplify caching" (d717775) has changes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
1a88493
to
3077e15
Compare
CI failure handled in #1628 |
3077e15
to
f6c10ad
Compare
rebased to current develop to get tests passing again |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work, @jku et al.! I'm just catching up on the new client and I like it lot. Here are a few comments from reading through ngclient/updater.py
line by line.
(Haven't looked at the tests yet)
tuf/ngclient/updater.py
Outdated
If the ``target_dir`` argument was given to constructor, ``filepath`` | ||
argument is not required here: in this case a filename will be | ||
generated based on the target path like in ``download_target()`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove the "like in download_target()
" part. The reader of this docstring might not (and does not need to) know about download_target
when reading this.
tuf/ngclient/updater.py
Outdated
If the ``target_dir`` argument was given to constructor, ``filepath`` | ||
argument is not required here: in this case a filename will be | ||
generated based on the target path like in ``download_target()`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think the text could be misinterpreted that a previously set target_dir
has precedence over a passed filepath
, or that they are somehow used together.
tuf/ngclient/updater.py
Outdated
If the ``target_dir`` argument was given to constructor, ``filepath`` | ||
argument is not required here: in this case a filename will be | ||
generated based on the target path like in ``download_target()`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a slightly more detailed filepath
arg description would eliminate the need for this paragraph here? See below for a suggestion.
Otherwise absolutely everything is split on multiple lines. Signed-off-by: Jussi Kukkonen <[email protected]>
Remove updated_targets() as it doesn't fit the rest of the API. In its stead add find_cached_target() which has a similar signature as download_target(): both accept an optional local filepath as argument and return full local filepath. In the find_cached_target() case None is returned if the local file is not the correct target file. Updater constructor gets a new optional target_dir argument: This means client can avoid giving a local filepath as an argument to find_cached_target()/download_target() -- Updater will then generate a filename within targets_dir. A reasonable use pattern (when targets_dir is set in constructor): info = updater.get_one_valid_targetinfo("targetname") path = updater.find_cached_target(info) if path is None: path = updater.download_target(info) Signed-off-by: Jussi Kukkonen <[email protected]>
This is slightly cosmetic but rename get_one_valid_targetinfo to get_targetinfo: * The function name is long without any reason: "one" and "valid" are always implicit * shortening makes code (incl. our examples and tests) easier to read * We're also already changing updater API (compared to legacy) so this alone does not break things -- it's also not a difficult "port". Signed-off-by: Jussi Kukkonen <[email protected]>
f6c10ad
to
b3dc21e
Compare
Also tweak the docstrings: the "caching" target_dir usage is presented in the module doc example: there should be no need for additional comments in the methods themselves as long as the argument docs are readable. Signed-off-by: Jussi Kukkonen <[email protected]>
b3dc21e
to
6aaa1ea
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: This PR including the description has been updated based on initial comments: this means the first comments look a bit strange now...
This is part 2 of #1580 (ngclient API tweaks): originally I thought we could just replicate old client API but the more I've used it, the more I've wanted to change it. So here's my proposal.
The PR contains a couple of semi-related changes:
get_one_valid_targetinfo()
toget_targetinfo()
updated_targets()
withfind_cached_target()
which operates almost exactly likedownload_target()
but looks at local disk only.target_dir
constructor argument that bothfind_cached_target()
anddownload_target()
can use: this lets Updater choose the file name. Both methods also take an optional filepath so clients can control the filename & path.So the two ways of using the API are:
Based on how much better the test code now looks, I think we're approaching the correct design here...