-
Notifications
You must be signed in to change notification settings - Fork 80
feat: add support to disable external version checks #737
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
Open
sanggusti
wants to merge
14
commits into
Lightning-AI:main
Choose a base branch
from
sanggusti:feat/disable-external-version-checks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
da40de6
Feat: Add mechanism to disable external version checks (PyPI API call…
sanggusti 73b67d5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2942a28
Add changelog
sanggusti 1dcffbd
Fix: Adjusted by comments and request
sanggusti c521eb5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7eb5a18
Fix: remove redundant of `_LITDATA_DISABLE_VERSION` at `_check_versio…
sanggusti 3d4f46e
Update src/litdata/helpers.py by merging condition of disable version…
sanggusti ef4f28c
Update src/litdata/CHANGELOG.md
sanggusti fa06333
Feat: use monkeypatch for setting environment variable
sanggusti e6c65e6
Update src/litdata/CHANGELOG.md
deependujha e153a79
Update src/litdata/constants.py
deependujha 0da4297
update
deependujha 0701f3b
update
deependujha 50a9c46
Merge branch 'main' into feat/disable-external-version-checks
deependujha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import importlib | ||
import sys | ||
import warnings | ||
from unittest.mock import Mock, patch | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize("disable_version_check", ["1", "0", None]) | ||
def test_get_newer_version_respects_env_flag(monkeypatch, disable_version_check): | ||
"""Verify that _get_newer_version respects LITDATA_DISABLE_VERSION_CHECK and skips requests when disabled.""" | ||
monkeypatch.delenv("LITDATA_DISABLE_VERSION_CHECK", raising=False) | ||
|
||
if disable_version_check is not None: | ||
monkeypatch.setenv("LITDATA_DISABLE_VERSION_CHECK", disable_version_check) | ||
|
||
# Reload both modules so constants re-evaluate environment variables | ||
sys.modules.pop("litdata.constants", None) | ||
sys.modules.pop("litdata.helpers", None) | ||
importlib.import_module("litdata.helpers") | ||
from litdata import helpers | ||
bhimrazy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
# Mock requests.get | ||
mock_get = Mock() | ||
mock_get.return_value.json.return_value = { | ||
"releases": {"0.2.50": [], "2.51.0": []}, | ||
"info": {"version": "2.51.0", "yanked": False}, | ||
} | ||
|
||
monkeypatch.setattr("litdata.helpers.requests.get", mock_get) | ||
|
||
# Clear cached function results | ||
helpers._get_newer_version.cache_clear() | ||
|
||
result = helpers._get_newer_version("0.2.50") | ||
|
||
if disable_version_check == "1": | ||
assert result is None | ||
mock_get.assert_not_called() | ||
else: | ||
assert result == "2.51.0" | ||
mock_get.assert_called_once_with("https://pypi.org/pypi/litdata/json", timeout=30) | ||
|
||
|
||
@patch("litdata.helpers._get_newer_version") | ||
def test_check_version_default_behavior_warning(mock_get_newer, monkeypatch): | ||
"""Test default behavior: calls _get_newer_version and warns if newer version exists.""" | ||
mock_get_newer.return_value = "0.2.58" | ||
|
||
from litdata.helpers import _check_version_and_prompt_upgrade | ||
|
||
with warnings.catch_warnings(record=True) as w: | ||
warnings.simplefilter("always") | ||
_check_version_and_prompt_upgrade("0.2.50") | ||
assert len(w) == 1 | ||
assert f"A newer version of litdata is available ({mock_get_newer.return_value})" in str(w[0].message) | ||
mock_get_newer.assert_called_once_with("0.2.50") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.