forked from kivy/python-for-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckdependencies.py
More file actions
70 lines (58 loc) · 2.04 KB
/
checkdependencies.py
File metadata and controls
70 lines (58 loc) · 2.04 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from importlib import import_module
from os import environ
import sys
from packaging.version import Version
from pythonforandroid.prerequisites import (
check_and_install_default_prerequisites,
)
def check_python_dependencies():
"""
Check if the Python requirements are installed. This must appears
before other imports because otherwise they're imported elsewhere.
Using the ok check instead of failing immediately so that all
errors are printed at once.
"""
ok = True
modules = [("colorama", "0.3.3"), "appdirs", ("sh", "1.10"), "jinja2"]
for module in modules:
if isinstance(module, tuple):
module, version = module
else:
version = None
try:
import_module(module)
except ImportError:
if version is None:
print(
"ERROR: The {} Python module could not be found, please "
"install it.".format(module)
)
ok = False
else:
print(
"ERROR: The {} Python module could not be found, "
"please install version {} or higher".format(
module, version
)
)
ok = False
else:
if version is None:
continue
try:
cur_ver = sys.modules[module].__version__
except AttributeError: # this is sometimes not available
continue
if Version(cur_ver) < Version(version):
print(
"ERROR: {} version is {}, but python-for-android needs "
"at least {}.".format(module, cur_ver, version)
)
ok = False
if not ok:
print("python-for-android is exiting due to the errors logged above")
exit(1)
def check():
if not environ.get("SKIP_PREREQUISITES_CHECK", "0") == "1":
check_and_install_default_prerequisites()
check_python_dependencies()