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

Add version check caching, fix version comparison #1835

Conversation

olzhasar-reef
Copy link
Contributor

This PR introduces the following changes:

  1. Version checking cache:
    Currently, version checking works by making an HTTP request to PyPI on every call. To avoid repetitive network requests, we implement a caching mechanism using a local file, ensuring that requests are only made once a day at most.
  2. Improved version comparison:
    The current version comparison logic relies on integer comparisons, which do not support letters and may lead to errors in cases like "6.0.15" vs "6.1.0". The new comparison mechanism is more robust and powered by the version handling capabilities of the packaging library.
  3. Fix for version_checking silent failure issue:
    The CLI module includes logic for displaying an error message with a tip to disable version checking in case of a network request failure. However, this code is unreachable due to version checking failing silently.
    This PR introduces a new check_version function with a custom exception. The old behavior is retained with a display of a deprecation warning.
    The new function name should also be more descriptive to an end user.

@gus-opentensor
Copy link
Collaborator

@olzhasar-reef thank you for the contribution!

@gus-opentensor
Copy link
Collaborator

@ibraheem-opentensor do you mind testing this when you get a chance?

def test_get_and_save_latest_version_file_fresh_check(
mock_get_version_from_pypi: MagicMock, version_file_path: Path, elapsed: int
):
now = datetime.utcnow()
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for your contribution!

utcnow() is depreciated (link)
Maybe we can use datetime.now(timezone.utc)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, fixed

@ibraheem-opentensor
Copy link
Contributor

@gus-opentensor Lgtm!

@olzhasar-reef
Copy link
Contributor Author

@gus-opentensor I've merged recent changes from the staging branch addressing conflicts.
Let me know if there's anything else preventing from merging this PR.

@gus-opentensor gus-opentensor merged commit c2545bf into opentensor:staging May 14, 2024
12 checks passed
@gus-opentensor gus-opentensor mentioned this pull request May 17, 2024
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.

None yet

4 participants