Skip to content

Commit 209c49f

Browse files
authored
Merge pull request kivy#794 from inclement/py_modules_check
Added python modules check
2 parents 70d5f07 + 968880b commit 209c49f

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

pythonforandroid/toolchain.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,57 @@
88

99
from __future__ import print_function
1010

11+
12+
def check_python_dependencies():
13+
# Check if the Python requirements are installed. This appears
14+
# before the imports because otherwise they're imported elsewhere.
15+
16+
# Using the ok check instead of failing immediately so that all
17+
# errors are printed at once
18+
19+
from distutils.version import LooseVersion
20+
from importlib import import_module
21+
import sys
22+
23+
ok = True
24+
25+
modules = [('colorama', '0.3.3'), 'appdirs', ('sh', '1.10'), 'jinja2',
26+
'argparse', 'six']
27+
28+
for module in modules:
29+
if isinstance(module, tuple):
30+
module, version = module
31+
else:
32+
version = None
33+
34+
try:
35+
import_module(module)
36+
except ImportError:
37+
if version is None:
38+
print('ERROR: The {} module could not be found, please '
39+
'install it.'.format(module))
40+
ok = False
41+
else:
42+
print('ERROR: The {} module could not be found, please install '
43+
'version {} or higher'.format(module, version))
44+
ok = False
45+
else:
46+
if version is None:
47+
continue
48+
cur_ver = sys.modules[module].__version__
49+
if LooseVersion(cur_ver) < LooseVersion(version):
50+
print('ERROR: {} version is {}, but python-for-android needs '
51+
'at least {}.'.format(module, cur_ver, version))
52+
ok = False
53+
54+
55+
if not ok:
56+
print('python-for-android is exiting due to the errors above.')
57+
exit(1)
58+
59+
check_python_dependencies()
60+
61+
1162
import sys
1263
from sys import platform
1364
from os.path import (join, dirname, realpath, exists, expanduser)

0 commit comments

Comments
 (0)