|
8 | 8 |
|
9 | 9 | from __future__ import print_function |
10 | 10 |
|
| 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 | + |
11 | 62 | import sys |
12 | 63 | from sys import platform |
13 | 64 | from os.path import (join, dirname, realpath, exists, expanduser) |
|
0 commit comments