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(files): allow decoding project files directly to string#2396

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

Open
nejch wants to merge1 commit intomain
base:main
Choose a base branch
Loading
fromfeat/decode-to-string

Conversation

nejch
Copy link
Member

Provides a slightly less clunky interface so people don't need to dof.decode.().decode("utf-8") in user code.

@codecov-commenter
Copy link

Codecov Report

Merging#2396 (8751402) intomain (0ecf3bb) willdecrease coverage by0.04%.
The diff coverage is76.92%.

@@            Coverage Diff             @@##             main    #2396      +/-   ##==========================================- Coverage   95.97%   95.92%   -0.05%==========================================  Files          80       80                Lines        5342     5354      +12     ==========================================+ Hits         5127     5136       +9- Misses        215      218       +3
FlagCoverage Δ
api_func_v483.71% <76.92%> (-0.02%)⬇️
cli_func_v482.31% <46.15%> (-0.08%)⬇️
unit87.67% <46.15%> (-0.09%)⬇️

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

Impacted FilesCoverage Δ
gitlab/v4/objects/files.py96.70% <76.92%> (-3.30%)⬇️

@nejchnejch marked this pull request as ready for reviewNovember 26, 2022 15:38
@gdubicki
Copy link

Hi! Sorry if I am oversharing here, especially as I don't know this project and its conventions well (yet!).

While this is definitely an improvement from the previous syntax I feel that this could and maybe should be even simpler.

Because people mostly store source code in git then the most popular use-case here will probably be getting the content of the file asUTF-8 text.

So I propose to add a methodf.text(encoding='UTF-8') (similar toRequests'st.text) so you could change the encoding but most users could just dof.text().

For bytes I would personally prefer havingf.bytes() methods to avoid usingdecode keyword as for me it's almost never clear what it does as it depends on the context. Especially in GitLab Files API, where we have double encoding, first with base64 and then with a text encoding likeUTF-8.

For completeness I would addf.base64(). This way you can have a single call to any form of the underlying file.

PS I've never usedencoding = 'text' in GitLab Files API so I don't know - doesn't it cause the file to be stored without base64? If so, we should make sure that our helper functions deal with those 2 cases, base64-encoded files and not.

@nejchnejch assignednejch and unassignedmax-wittigDec 4, 2022
@nejch
Copy link
MemberAuthor

nejch commentedDec 4, 2022
edited
Loading

@gdubicki thanks for the feedback! I'll take another look at what wording makes the most sense, especially when compared torequests/httpx and similar underlying libraries.

For context, thisdecode() method is one of the few public methods in python-gitlab that are completely custom (i.e. not implementing an API endpoint) and here for the user's convenience rather than to mirror API functionality (this one introduced by the original author in2eac071).

In most other cases we do not add more higher-level convenience and instead keep it a thin wrapper, so I'd be wary of introducing more methods but if we do already provide some decoding then it probably makes sense to make itactually convenient for the user ;) I agreedecode() isn't that clear though.

Edit: theencoding arg on POST shouldn't have an effect on this, from what I can tell it's to indicate to GitLab the encoding of the content that is being sent in the payload. See discussion in#427.

@nejch
Copy link
MemberAuthor

nejch commentedFeb 7, 2023
edited
Loading

Maybe an additional.text() really is more explicit. It's 2 totally different kinds ofdecodes we're calling so maybe we shouldn't mix them. I'll rework this a bit :)

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

@nejchnejch

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@nejch@codecov-commenter@gdubicki@max-wittig

[8]ページ先頭

©2009-2025 Movatter.jp