Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
nejch merged 13 commits intopython-gitlab:mainfromTCatshoek:main
Jun 26, 2022

Conversation

TCatshoek
Copy link
Contributor

Allow access to the underlying response iterator when downloading in
streaming mode by specifying action="iterator"

Also update type annotations to support this change

@codecov-commenter
Copy link

codecov-commenter commentedMar 31, 2022
edited
Loading

Codecov Report

Merging#1956 (9f01ee5) intomain (f9b7c7b) willincrease coverage by0.00%.
The diff coverage is92.59%.

@@           Coverage Diff           @@##             main    #1956   +/-   ##=======================================  Coverage   94.72%   94.73%           =======================================  Files          78       78             Lines        5083     5087    +4     =======================================+ Hits         4815     4819    +4  Misses        268      268
FlagCoverage Δ
cli_func_v482.42% <66.66%> (-0.01%)⬇️
py_func_v481.14% <66.66%> (-0.03%)⬇️
unit85.80% <51.85%> (-0.03%)⬇️

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

Impacted FilesCoverage Δ
gitlab/v4/cli.py90.61% <ø> (ø)
gitlab/v4/objects/jobs.py77.27% <50.00%> (ø)
gitlab/mixins.py92.30% <100.00%> (ø)
gitlab/utils.py100.00% <100.00%> (ø)
gitlab/v4/objects/artifacts.py100.00% <100.00%> (ø)
gitlab/v4/objects/files.py100.00% <100.00%> (ø)
gitlab/v4/objects/packages.py96.29% <100.00%> (ø)
gitlab/v4/objects/projects.py90.00% <100.00%> (+0.03%)⬆️
gitlab/v4/objects/repositories.py83.07% <100.00%> (ø)
gitlab/v4/objects/snippets.py98.00% <100.00%> (ø)

@nejch
Copy link
Member

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 withaction="iterator" is fine but I can also poke around to see how other people might do this.

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:

deftest_download_generic_package(project):
package=project.generic_packages.download(
package_name=package_name,
package_version=package_version,
file_name=file_name,
)
assertisinstance(package,bytes)
assertpackage.decode("utf-8")==file_content
deftest_download_generic_package_to_file(tmp_path,project):
path=tmp_path/file_name
withopen(path,"wb")asf:
project.generic_packages.download(
package_name=package_name,
package_version=package_version,
file_name=file_name,
streamed=True,
action=f.write,
)
withopen(path,"r")asf:
assertf.read()==file_content

@TCatshoek
Copy link
ContributorAuthor

@nejch Awesome! I'll work on tests and docs as soon as I have some time.

In the meantime I managed to find a suitable, albeit kind of ugly workaround to get the behavior I want. I'll describe it in the issue I opened at#1955

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
@TCatshoek
Copy link
ContributorAuthor

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
@TCatshoekTCatshoek marked this pull request as ready for reviewApril 10, 2022 09:00
@TCatshoek
Copy link
ContributorAuthor

TCatshoek commentedApr 10, 2022
edited
Loading

Added tests and documentation too!

Copy link
Member

@nejchnejch left a 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 :)

@@ -1,2 +1,3 @@
requests==2.27.1
requests-toolbelt==0.9.1
typing_extensions; python_version<"3.8"
Copy link
Member

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)

Copy link
ContributorAuthor

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!

Copy link
ContributorAuthor

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?

Copy link
Member

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:

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.

Copy link
Member

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,

Copy link
ContributorAuthor

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 :)

Copy link
Member

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

TCatshoek reacted with thumbs up emoji
Co-authored-by: Nejc Habjan <hab.nejc@gmail.com>
@TCatshoek
Copy link
ContributorAuthor

Sorry, had to force push because the commit messages from accepting the suggested changes through the web interface were not accepted.

nejch reacted with thumbs up emoji

@nejch
Copy link
Member

Would you still be interested in adapting this foriterator=True@TCatshoek? If so we could merge it before the 28th when the next release is scheduled. :)

@TCatshoek
Copy link
ContributorAuthor

Yeah! I think I should have some time this weekend, I'll try to get it done before the 28th

nejch reacted with heart emoji

…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
@nejch
Copy link
Member

Thanks for all the work here@TCatshoek!

TCatshoek reacted with hooray emojiTCatshoek reacted with heart emoji

@nejchnejch merged commitb644721 intopython-gitlab:mainJun 26, 2022
@TCatshoek
Copy link
ContributorAuthor

@nejch Glad I could help! :D

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nejchnejchnejch approved these changes

Assignees

@TCatshoekTCatshoek

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@TCatshoek@codecov-commenter@nejch

[8]ページ先頭

©2009-2025 Movatter.jp