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

CI Error on FutureWarning #787

Merged
merged 7 commits into from
Mar 24, 2022
Merged

CI Error on FutureWarning #787

merged 7 commits into from
Mar 24, 2022

Conversation

adrinjalali
Copy link
Contributor

This PR makes the CI to fail on FutureWarning so that our test suite won't use our own deprecated API and our codebase use new API from our dependencies.

@adrinjalali adrinjalali changed the title CI Error on FutureWarning [WIP] CI Error on FutureWarning Mar 22, 2022
@adrinjalali
Copy link
Contributor Author

Would be nice to have this in so that we can merge #745 after

@adrinjalali adrinjalali changed the title [WIP] CI Error on FutureWarning CI Error on FutureWarning Mar 23, 2022
Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

This looks good to me, thanks for working on it @adrinjalali!

pytest --log-cli-level=INFO -sv ./tests/test_repository.py -k RepositoryTest
pytest -Werror::FutureWarning --log-cli-level=INFO -sv ./tests/test_repository.py -k RepositoryTest
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 adding this.

Copy link
Contributor

@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.

Looks great, thanks for this change! I left a small question

@@ -27,7 +27,8 @@ def setUpClass(cls):
"""
Share this valid token in all tests below.
"""
cls._token = cls._api.login(username=USER, password=PASS)
cls._token = TOKEN
cls._api.set_access_token(TOKEN)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really want to do this? This means that if someone runs the test locally, they will be changing their credential store no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it does, but that's already the case (which I think shouldn't be). I'll open a separate issue to discuss that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that's true. login does not update the git credential store, it just gives you the token.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

login stores username and password, just not the token. I don't think either of them should: #796

    def login(self, username: str, password: str) -> str:
        """
        Call HF API to sign in a user and get a token if credentials are valid.

        Outputs: token if credentials are valid

        Throws: requests.exceptions.HTTPError if credentials are invalid
        """
        warnings.warn(
            "HfApi.login: This method is deprecated in favor of `set_access_token`"
            " and will be removed in v0.7.",
            FutureWarning,
        )
        path = f"{self.endpoint}/api/login"
        r = requests.post(path, json={"username": username, "password": password})
        r.raise_for_status()
        d = r.json()

        write_to_credential_store(username, password)
        return d["token"]

    def set_access_token(access_token: str):
        write_to_credential_store(USERNAME_PLACEHOLDER, access_token)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah thank you for pointing it out!

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.

3 participants