- Notifications
You must be signed in to change notification settings - Fork673
feat(downloads): allow streaming downloads access to response iterator#1956
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
codecov-commenter commentedMar 31, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report
@@ Coverage Diff @@## main #1956 +/- ##======================================= Coverage 94.72% 94.73% ======================================= Files 78 78 Lines 5083 5087 +4 =======================================+ Hits 4815 4819 +4 Misses 268 268
Flags with carried forward coverage won't be shown.Click here to find out more.
|
Thank you for all the work here@TCatshoek! For this to work with typing on 3.7, we'll need to add a conditional dependency onhttps://pypi.org/project/typing-extensions/. It would also be great to document this a little and if you could maybe add a specific use case there (e.g. from your issue) a bit to give context :) I think doing this with As a bonus, if you have the energy, it'd be great if we could maybe also do a functional test for this. I know we don't have any targeted tests for this but perhaps down here: python-gitlab/tests/functional/api/test_packages.py Lines 38 to 62 in5a1678f
|
Allow access to the underlying response iterator when downloading instreaming mode by specifying action="iterator"Update type annotations to support this change
This supports commitc76b3b1 and makessure it works on python 3.7 as well.
This is used to support Literal from typing on python < 3.8
I added the conditional dependency on typing_extensions for python 3.7. Had to shuffle some imports around to make the linter happy, I hope it is ok like this! |
Document the usage of the action="iterator" option when downloadingartifacts
Tests for the functionality implemented in4f9807f
TCatshoek commentedApr 10, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Added tests and documentation too! |
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.
Just a few suggestions for the docs@TCatshoek and I'll just check if it makes more sense to add another argument, I'll get back to you ASAP. Thanks :)
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
requirements.txt Outdated
@@ -1,2 +1,3 @@ | |||
requests==2.27.1 | |||
requests-toolbelt==0.9.1 | |||
typing_extensions; python_version<"3.8" |
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.
This works in testing, but I assume we'd also need this insetup.py
for the installed package for users.
However, let me just take another look because if we're only doing this forLiteral
, it might make more sense to add a separate argument in addition toaction
, to keep typing clearer. (Also we'd need to change the docstrings otherwise)
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.
Ah yes, you're right. Let me know what you decide and I will update things accordingly!
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.
@nejch Any news on 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.
Thanks for your patience@TCatshoek!
I just took another look at this and I feel we should maybe leaveaction
a Callable only because we do this later:
Lines 44 to 46 in792cee9
forchunkinresponse.iter_content(chunk_size=chunk_size): | |
ifchunk: | |
action(chunk) |
So I think that might be a bit confusing. How about an explicititerator: bool = False
argument that would follow thestreamed
logic a bit more? This would also get rid of the typing dependency we discussed as I see some people don't like having even the tiniest extra dependencies.. :)
Thanks again for working on this! Let me know what you think.
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.
Just had some discussion with@JohnVillalovos and we're thinking of intruducing aniterator=True
for ourlist()
calls where we currently useas_list=False
(which is kind of unclear in what it really does currently), so this would then make it a consistent interfaces as well. So I think a bool withiterator
is the way to go,
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.
Sounds good! I'll get to it asap, work has been keeping me busy :)
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.
Cool! No rush. FYI, the list iterator argument has been merged:
#2032
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Nejc Habjan <hab.nejc@gmail.com>
Sorry, had to force push because the commit messages from accepting the suggested changes through the web interface were not accepted. |
Would you still be interested in adapting this for |
Yeah! I think I should have some time this weekend, I'll try to get it done before the 28th |
…thon 3.7"This reverts commitefd8b48.
… iterator"This reverts commit4f9807f.
…r downloadsInstead of having action="iterator", we can now do iterator=True to get the underlying response iterator when downloading things.
Adapted the existing tests for the new iterator=True argument
Adapted the example for the new iterator=True argument
Thanks for all the work here@TCatshoek! |
@nejch Glad I could help! :D |
Allow access to the underlying response iterator when downloading in
streaming mode by specifying action="iterator"
Also update type annotations to support this change