-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_version.py
More file actions
executable file
·47 lines (36 loc) · 1.16 KB
/
check_version.py
File metadata and controls
executable file
·47 lines (36 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env -S python3 -I
# -*- coding: utf-8 -*-
#
# check_version.py
"""Prints the local py2048 version iff it's greater than the installed
py2048 version.
* IMPORTANT *
Run this as:
>>> python3 -I check_version.py
The -I flag keeps Python from adding the current directory to sys.path:
we want to import the installed version of py2048, not the local one.
https://docs.python.org/3/using/cmdline.html#id2
"""
import os
import sys
from py2048 import __version__ as global_version, APPNAME
def get_local_version():
version_line = None
path = os.path.join(APPNAME, "__init__.py")
with open(path) as init:
for line in init:
if line.startswith("__version__"):
version_line = line
break
if not version_line:
sys.exit(f"Couldn't find '__version__'; aborting.")
return eval(version_line.split("=")[-1].strip())
def main() -> None:
if not sys.flags.isolated:
my_name = sys.argv[0]
sys.exit(f"{my_name} must be run with the '-I' flag; aborting.")
local = get_local_version()
if local > global_version:
print(local, end="")
if __name__ == "__main__":
main()