Skip to content
This repository was archived by the owner on Sep 24, 2025. It is now read-only.

Commit b288d37

Browse files
author
platipusica
committed
version check added
1 parent 6c17337 commit b288d37

File tree

3 files changed

+119
-2
lines changed

3 files changed

+119
-2
lines changed

builder/server.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,47 @@
11
#!/usr/bin/env python
2+
print("User Guide: https://jampy-docs-v7.readthedocs.io/")
3+
4+
import sys
5+
import urllib.request
6+
import json
7+
8+
try:
9+
# Python 3.8+
10+
from importlib.metadata import version, PackageNotFoundError
11+
except ImportError:
12+
# Fallback for Python <3.8
13+
from importlib_metadata import version, PackageNotFoundError
14+
15+
16+
def check_for_new_version(package: str):
17+
try:
18+
current_version = version(package)
19+
with urllib.request.urlopen(f"https://pypi.org/pypi/{package}/json", timeout=2) as resp:
20+
data = json.load(resp)
21+
latest_version = data["info"]["version"]
22+
23+
if current_version != latest_version:
24+
print(
25+
f"\nA new version of {package} is available: "
26+
f"{current_version}{latest_version}\n"
27+
)
28+
else:
29+
print(f"{package} is up-to-date ({current_version})")
30+
31+
except PackageNotFoundError:
32+
print(f"{package} is not installed in this environment.")
33+
except Exception as e:
34+
print(f"Version check skipped, no network.")
35+
236

337
if __name__ == '__main__':
38+
# --- version check at startup ---
39+
check_for_new_version("jam-py-v7")
40+
41+
# --- Jam.py startup ---
442
from jam.wsgi import create_application
543
from jam.wsgi_server import run
644

745
application = create_application(__file__)
846
run(application)
47+

demo/server.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,47 @@
11
#!/usr/bin/env python
2-
print(f"User Guide: https://jampy-docs-v7.readthedocs.io/")
2+
print("User Guide: https://jampy-docs-v7.readthedocs.io/")
3+
4+
import sys
5+
import urllib.request
6+
import json
7+
8+
try:
9+
# Python 3.8+
10+
from importlib.metadata import version, PackageNotFoundError
11+
except ImportError:
12+
# Fallback for Python <3.8
13+
from importlib_metadata import version, PackageNotFoundError
14+
15+
16+
def check_for_new_version(package: str):
17+
try:
18+
current_version = version(package)
19+
with urllib.request.urlopen(f"https://pypi.org/pypi/{package}/json", timeout=2) as resp:
20+
data = json.load(resp)
21+
latest_version = data["info"]["version"]
22+
23+
if current_version != latest_version:
24+
print(
25+
f"\nA new version of {package} is available: "
26+
f"{current_version}{latest_version}\n"
27+
)
28+
else:
29+
print(f"{package} is up-to-date ({current_version})")
30+
31+
except PackageNotFoundError:
32+
print(f"{package} is not installed in this environment.")
33+
except Exception as e:
34+
print(f"Version check skipped, no network.")
35+
36+
337
if __name__ == '__main__':
38+
# --- version check at startup ---
39+
check_for_new_version("jam-py-v7")
40+
41+
# --- Jam.py startup ---
442
from jam.wsgi import create_application
543
from jam.wsgi_server import run
644

745
application = create_application(__file__)
846
run(application)
47+

jam/project/server.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,47 @@
11
#!/usr/bin/env python
2-
print(f"User Guide: https://jampy-docs-v7.readthedocs.io/")
2+
print("User Guide: https://jampy-docs-v7.readthedocs.io/")
3+
4+
import sys
5+
import urllib.request
6+
import json
7+
8+
try:
9+
# Python 3.8+
10+
from importlib.metadata import version, PackageNotFoundError
11+
except ImportError:
12+
# Fallback for Python <3.8
13+
from importlib_metadata import version, PackageNotFoundError
14+
15+
16+
def check_for_new_version(package: str):
17+
try:
18+
current_version = version(package)
19+
with urllib.request.urlopen(f"https://pypi.org/pypi/{package}/json", timeout=2) as resp:
20+
data = json.load(resp)
21+
latest_version = data["info"]["version"]
22+
23+
if current_version != latest_version:
24+
print(
25+
f"\nA new version of {package} is available: "
26+
f"{current_version}{latest_version}\n"
27+
)
28+
else:
29+
print(f"{package} is up-to-date ({current_version})")
30+
31+
except PackageNotFoundError:
32+
print(f"{package} is not installed in this environment.")
33+
except Exception as e:
34+
print(f"Version check skipped, no network.")
35+
36+
337
if __name__ == '__main__':
38+
# --- version check at startup ---
39+
check_for_new_version("jam-py-v7")
40+
41+
# --- Jam.py startup ---
442
from jam.wsgi import create_application
543
from jam.wsgi_server import run
644

745
application = create_application(__file__)
846
run(application)
47+

0 commit comments

Comments
 (0)