Skip to content

Commit d26adb3

Browse files
committed
update 1.8.1
1 parent b587def commit d26adb3

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

src/xulbux/cli/help.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,50 @@
33
from ..format_codes import FormatCodes
44
from ..console import Console
55

6+
from urllib.error import HTTPError
7+
from typing import Optional
8+
import urllib.request as _request
9+
import json as _json
610

11+
12+
def get_latest_version() -> Optional[str]:
13+
with _request.urlopen(URL) as response:
14+
if response.status == 200:
15+
data = _json.load(response)
16+
return data["info"]["version"]
17+
else:
18+
raise HTTPError(URL, response.status, "Failed to fetch latest version info", response.headers, None)
19+
20+
21+
def is_latest_version() -> Optional[bool]:
22+
try:
23+
latest = get_latest_version()
24+
if latest in ("", None): return None
25+
latest_v_parts = tuple(int(part) for part in latest.lower().lstrip("v").split('.'))
26+
installed_v_parts = tuple(int(part) for part in __version__.lower().lstrip("v").split('.'))
27+
return latest_v_parts <= installed_v_parts
28+
except Exception:
29+
return None
30+
31+
32+
URL = "https://pypi.org/pypi/xulbux/json"
33+
IS_LATEST_VERSION = is_latest_version()
734
CLR = {
835
"class": COLOR.TANGERINE,
36+
"code_border": COLOR.GRAY,
937
"const": COLOR.RED,
1038
"func": COLOR.CYAN,
1139
"import": COLOR.NEON_GREEN,
1240
"lib": COLOR.ORANGE,
41+
"notice": COLOR.YELLOW,
1342
"punctuators": COLOR.DARK_GRAY,
14-
"code_border": COLOR.GRAY,
1543
}
1644
HELP = FormatCodes.to_ansi(
1745
rf""" [_|b|#7075FF] __ __
1846
[b|#7075FF] _ __ __ __/ / / /_ __ ___ __
1947
[b|#7075FF] | |/ // / / / / / __ \/ / / | |/ /
2048
[b|#7075FF] > , </ /_/ / /_/ /_/ / /_/ /> , <
21-
[b|#7075FF]/_/|_|\____/\__/\____/\____//_/|_| [*|BG:{COLOR.GRAY}|#000] v[b]{__version__} [*]
49+
[b|#7075FF]/_/|_|\____/\__/\____/\____//_/|_| [*|BG:{COLOR.GRAY}|#000] v[b]{__version__} [*|dim|{CLR['notice']}]({'' if IS_LATEST_VERSION else ' (newer available)'})[*]
2250
2351
[i|{COLOR.CORAL}]A TON OF COOL FUNCTIONS, YOU NEED![*]
2452

0 commit comments

Comments
 (0)