Skip to content

Commit ed530a4

Browse files
Display warning message when importing outdated versions (#757)
1 parent 57d596a commit ed530a4

File tree

5 files changed

+77
-1
lines changed

5 files changed

+77
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ You can check your current version with the following command:
3030

3131
For more information, see [UP42 Python package description](https://pypi.org/project/up42-py/).
3232

33+
### 2.4.0a4
34+
**July 16, 2025**
35+
- Display warning when importing outdated versions
36+
3337
### 2.4.0a3
3438
**July 15, 2025**
3539
- Deprecated the `webhooks` module and the `base::get_credits_balance` function

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "up42-py"
3-
version = "2.4.0a3"
3+
version = "2.4.0a4"
44
description = "Python SDK for UP42, the geospatial marketplace and developer platform."
55
authors = ["UP42 GmbH <[email protected]>"]
66
license = "https://github.com/up42/up42-py/blob/master/LICENSE"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import random
2+
3+
import mock
4+
import requests_mock as req_mock
5+
from packaging import version
6+
7+
from up42.version import version_control
8+
9+
fake_latest_version = "10.0.0"
10+
fake_installed_version = "1.0.0"
11+
12+
13+
class TestBuildMessage:
14+
def test_should_build_warn_message(self):
15+
assert (
16+
version_control.build_outdated_version_message(fake_installed_version, fake_latest_version)
17+
== f"You're using an outdated version of the UP42 Python SDK: v{fake_installed_version}. A newer version is available: v{fake_latest_version}.\nPlease upgrade to the latest version using **pip install --upgrade up42-py** or conda **conda update -c conda-forge up42-py**." # pylint: disable=line-too-long # noqa: E501
18+
)
19+
20+
21+
class TestCheckLatestVersion:
22+
def test_should_warn_if_not_latest_version(
23+
self,
24+
requests_mock: req_mock.Mocker,
25+
):
26+
warn = mock.MagicMock()
27+
requests_mock.get(url="https://pypi.org/pypi/up42-py/json", json={"info": {"version": fake_latest_version}})
28+
message = "not latest version"
29+
build_warning_message = mock.MagicMock(return_value=message)
30+
version_control.check_is_latest_version(fake_installed_version, warn, build_warning_message)
31+
build_warning_message.assert_called_with(fake_installed_version, version.Version(fake_latest_version))
32+
warn.assert_called_with(message)
33+
34+
def test_should_ignore_http_error_exception(
35+
self,
36+
requests_mock: req_mock.Mocker,
37+
):
38+
requests_mock.get(url="https://pypi.org/pypi/up42-py/json", status_code=random.randint(400, 599))
39+
unused = mock.MagicMock()
40+
version_control.check_is_latest_version(fake_installed_version, unused, unused)
41+
unused.assert_not_called()

up42/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@
3939
from up42.tasking import FeasibilityStudy, FeasibilityStudySorting, Quotation, QuotationSorting, Tasking
4040
from up42.tools import get_example_aoi, read_vector_file
4141
from up42.utils import get_up42_py_version
42+
from up42.version import version_control
4243
from up42.webhooks import Webhook
4344

4445
stac_extend()
4546

4647
__version__ = get_up42_py_version()
48+
version_control.check_is_latest_version(__version__)
49+
4750
__all__ = [
4851
cast(
4952
Union[Type, Callable],

up42/version/version_control.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import warnings
2+
3+
import requests
4+
from packaging import version
5+
from requests import exceptions
6+
7+
8+
def _get_latest_version():
9+
response = requests.get("https://pypi.org/pypi/up42-py/json", timeout=2)
10+
response.raise_for_status()
11+
return version.parse(response.json()["info"]["version"])
12+
13+
14+
def build_outdated_version_message(installed_version, latest_version):
15+
return f"You're using an outdated version of the UP42 Python SDK: v{installed_version}. A newer version is available: v{latest_version}.\nPlease upgrade to the latest version using **pip install --upgrade up42-py** or conda **conda update -c conda-forge up42-py**." # pylint: disable=line-too-long # noqa: E501
16+
17+
18+
def check_is_latest_version(
19+
installed_version: str,
20+
warn=warnings.warn,
21+
build_warning_message=build_outdated_version_message,
22+
):
23+
try:
24+
latest_version = _get_latest_version()
25+
if version.Version(installed_version) < latest_version:
26+
warn(build_warning_message(installed_version, latest_version))
27+
except exceptions.HTTPError:
28+
pass

0 commit comments

Comments
 (0)