-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
42 additions
and
103 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from __future__ import annotations | ||
|
||
__version__ = "7.71.0" | ||
__version__ = "7.71.1" | ||
|
||
__api_subversion__ = "20230101" |
This file contains 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 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 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 |
---|---|---|
@@ -1,89 +1,45 @@ | ||
from __future__ import annotations | ||
|
||
import argparse | ||
import functools | ||
import re | ||
import warnings | ||
from contextlib import suppress | ||
from threading import Thread | ||
|
||
import requests | ||
from packaging import version | ||
|
||
|
||
def check_if_version_exists(package_name: str, version: str) -> bool: | ||
versions = get_all_versions(package_name=package_name) | ||
return version in versions | ||
|
||
|
||
@functools.lru_cache(maxsize=1) | ||
def get_newest_version_in_major_release(package_name: str, version: str) -> str: | ||
major, minor, micro, pr_cycle, pr_version = _parse_version(version) | ||
versions = get_all_versions(package_name) | ||
for v in versions: | ||
if _is_newer_major(v, version): | ||
major, minor, micro, pr_cycle, pr_version = _parse_version(v) | ||
return _format_version(major, minor, micro, pr_cycle, pr_version) | ||
|
||
|
||
def get_all_versions(package_name: str) -> list[str]: | ||
def get_all_sdk_versions() -> list[version.Version]: | ||
from cognite.client.config import global_config | ||
|
||
verify_ssl = not global_config.disable_ssl | ||
res = requests.get(f"https://pypi.python.org/simple/{package_name}/#history", verify=verify_ssl, timeout=5) | ||
return re.findall(r"cognite-sdk-(\d+\.\d+.[\dabrc]+)", res.content.decode()) | ||
|
||
|
||
def _is_newer_major(version_a: str, version_b: str) -> bool: | ||
major_a, minor_a, micro_a, pr_cycle_a, pr_version_a = _parse_version(version_a) | ||
major_b, minor_b, micro_b, pr_cycle_b, pr_version_b = _parse_version(version_b) | ||
is_newer = False | ||
if major_a == major_b and minor_a >= minor_b and micro_a >= micro_b: | ||
if minor_a > minor_b: | ||
is_newer = True | ||
else: | ||
if micro_a > micro_b: | ||
is_newer = True | ||
else: | ||
is_newer = _is_newer_pre_release(pr_cycle_a, pr_version_a, pr_cycle_b, pr_version_b) | ||
return is_newer | ||
|
||
|
||
def _is_newer_pre_release( | ||
pr_cycle_a: str | None, pr_v_a: int | None, pr_cycle_b: str | None, pr_v_b: int | None | ||
) -> bool: | ||
cycles = ["a", "b", "rc", None] | ||
if pr_cycle_a not in cycles: | ||
raise RuntimeError(f"pr_cycle_a must be one of '{pr_cycle_a}', not '{cycles}'.") | ||
if pr_cycle_b not in cycles: | ||
raise RuntimeError(f"pr_cycle_a must be one of '{pr_cycle_b}', not '{cycles}'.") | ||
is_newer = False | ||
if cycles.index(pr_cycle_a) > cycles.index(pr_cycle_b): | ||
is_newer = True | ||
elif cycles.index(pr_cycle_a) == cycles.index(pr_cycle_b): | ||
if pr_v_a is not None and pr_v_b is not None and pr_v_a > pr_v_b: | ||
is_newer = True | ||
return is_newer | ||
|
||
res = requests.get("https://pypi.org/simple/cognite-sdk/", verify=verify_ssl, timeout=5) | ||
return list(map(version.parse, re.findall(r"cognite[_-]sdk-(\d+\.\d+.[\dabrc]+)", res.text))) | ||
|
||
def _parse_version(version: str) -> tuple[int, int, int, str, int | None]: | ||
pattern = r"(\d+)\.(\d+)\.(\d+)(?:([abrc]+)(\d+))?" | ||
match = re.match(pattern, version) | ||
if not match: | ||
raise ValueError(f"Could not parse version {version}") | ||
major, minor, micro, pr_cycle, pr_version = match.groups() | ||
return int(major), int(minor), int(micro), pr_cycle, int(pr_version) if pr_version else None | ||
|
||
def get_latest_released_stable_version() -> version.Version: | ||
# Filter only stable versions (no pre-releases or dev releases, but post-releases are ok) | ||
return max(v for v in get_all_sdk_versions() if not v.is_prerelease) | ||
|
||
def _format_version(major: int, minor: int, micro: int, pr_cycle: str | None, pr_version: int | None) -> str: | ||
return f"{major}.{minor}.{micro}{pr_cycle or ''}{pr_version or ''}" | ||
|
||
# Wrap in a cache to ensure we only ever run the version check once. | ||
@functools.cache | ||
def check_client_is_running_latest_version() -> None: | ||
def run() -> None: | ||
from packaging import version | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-p", "--package", required=True) | ||
parser.add_argument("-v", "--version", required=True) | ||
args = parser.parse_args() | ||
from cognite.client import __version__ | ||
|
||
version_exists = check_if_version_exists(args.package, args.version) | ||
with suppress(Exception): # PyPI might be unreachable, if so, skip version check | ||
newest_version = get_latest_released_stable_version() | ||
if version.parse(__version__) < newest_version: | ||
warnings.warn( | ||
f"You are using version={__version__!r} of the SDK, however version={newest_version.public!r} is " | ||
"available. To suppress this warning, either upgrade or do the following:\n" | ||
">>> from cognite.client.config import global_config\n" | ||
">>> global_config.disable_pypi_version_check = True", | ||
stacklevel=3, | ||
) | ||
|
||
if version_exists: | ||
print("yes") # noqa: T201 | ||
else: | ||
print("no") # noqa: T201 | ||
Thread(target=run, daemon=True).start() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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