Skip to content
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

Return more information in create_commit output #1066

Merged
merged 10 commits into from
Sep 23, 2022

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Sep 20, 2022

Fix #1037.

Now create_commit returns a CommitInfo data structure containing commit hash, commit url, commit message, commit description and eventually pr url. This way the return type is more consistent than returning only pr_url (string) or None depending on the create_pr parameter.

⚠️⚠️⚠️ This is a breaking change compared to previous behavior ⚠️⚠️⚠️
The hope is that create_commit is already used in downstream libraries but the return value is not. Better to change it now than later.
@sgugger there is one implication in transformers here. It only changes a logger message so it's not critical and can be quite easily changed.

Note: upload_file, upload_folder and push_to_hub return types have not been changed as they were not returning the pr_url but a URL to either a file or a folder.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Sep 20, 2022

The documentation is not available anymore as the PR was closed or merged.

Copy link
Contributor

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, just left a few comments on docstrings/type hints.

On the breaking change, we can leave with it in Transformers. I'd be more concerned about downstream libraries that may be using this function already. It's quite new, so one can argue it's still experimental, but that may still affect users negatively (and we do know from experience that some do not put pins in their setup.py)

Would be keen to hear other's thoughts!

src/huggingface_hub/hf_api.py Outdated Show resolved Hide resolved
src/huggingface_hub/hf_api.py Outdated Show resolved Hide resolved
src/huggingface_hub/utils/_validators.py Outdated Show resolved Hide resolved
@Wauplin
Copy link
Contributor Author

Wauplin commented Sep 20, 2022

FYI, this PR follows an internal discussion we had (see on slack -private internal link-).

The hope is that the return value is never used but I guess we'll see

@codecov
Copy link

codecov bot commented Sep 20, 2022

Codecov Report

Base: 84.16% // Head: 84.23% // Increases project coverage by +0.06% 🎉

Coverage data is based on head (2d459ec) compared to base (35033f3).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1066      +/-   ##
==========================================
+ Coverage   84.16%   84.23%   +0.06%     
==========================================
  Files          40       40              
  Lines        4087     4105      +18     
==========================================
+ Hits         3440     3458      +18     
  Misses        647      647              
Impacted Files Coverage Δ
src/huggingface_hub/__init__.py 75.75% <ø> (ø)
src/huggingface_hub/hf_api.py 86.85% <100.00%> (+0.28%) ⬆️
src/huggingface_hub/keras_mixin.py 90.47% <100.00%> (ø)
src/huggingface_hub/utils/_validators.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@sgugger
Copy link
Contributor

sgugger commented Sep 20, 2022

The slack link does not open anywhere for me FYI. There is really no need to tag me in a PR if my input is unwanted and the discussion is held privately without me, I am very happy to leave the maintenance of the integration of the Hub in Transformers to someone who has a seat at the table of those discussions instead :-)

@julien-c
Copy link
Member

we can share the main parts of the brainstorming convo with you @sgugger (or directly here) but rest assured it was not deliberate to exclude you, quite the contrary 😂

@Wauplin Wauplin added this to the v0.10 milestone Sep 21, 2022
Copy link
Member

@osanseviero osanseviero left a comment

Choose a reason for hiding this comment

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

Very nice!

revision = self.pr_revision
if revision is not None:
return int(revision.split("/")[-1])

Copy link
Member

Choose a reason for hiding this comment

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

Nit: Maybe consider adding a __str__ method for a nice string representation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@osanseviero Thanks for the comment , I discovered that a good way to handle properties in dataclasses is to use the __post_init__ method and field(init=False) in attribute definition. This way we don't use @property and the dataclass is fully aware of the computed attributes as if they were normal attributes.

See https://docs.python.org/3.10/library/dataclasses.html#post-init-processing and 475336f.

tests/test_hf_api.py Outdated Show resolved Hide resolved
tests/test_hf_api.py Outdated Show resolved Hide resolved
@Wauplin Wauplin merged commit 5958f17 into main Sep 23, 2022
@Wauplin Wauplin deleted the 1037-update-create-commit-output-type branch September 23, 2022 12:37
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.

Update create_commit output type to return something even when no PR is created
5 participants