|
13 | 13 | # Note 1: added since, despite the (minimum) requirements during install, packages can be downgraded or removed later |
14 | 14 | # Note 2: deliberately not in a separate module, since this is the entry point of the package and dependencies already be used after |
15 | 15 | # |
16 | | -from os.path import join, dirname, abspath |
17 | | -from configparser import ConfigParser |
18 | | -from importlib.metadata import version, PackageNotFoundError |
| 16 | +from importlib.metadata import version, PackageNotFoundError, requires |
19 | 17 | from re import sub as re_sub, split as re_split |
20 | 18 | def normalize_version(v): |
21 | 19 | return [int(x) for x in re_sub(r'(\.0+)*$','', v).split(".")] |
22 | 20 |
|
23 | | -cf = ConfigParser() |
24 | | -cf.read(join(dirname(abspath(__file__)), '..', 'setup.cfg')) |
25 | | -require_lines = [x for x in cf.get('options', 'install_requires').strip().splitlines()] |
26 | | - |
27 | | -for req_line in require_lines: |
28 | | - for req_line_part in req_line.split(','): |
29 | | - req_args = re_split('>=|==', req_line_part.strip()) |
30 | | - if len(req_args) == 2: |
31 | | - req_args[0] = req_args[0].strip() |
32 | | - req_args[1] = req_args[1].strip() |
33 | | - try: |
34 | | - current_version = version(req_args[0]) |
35 | | - if normalize_version(current_version) < normalize_version(req_args[1]): |
36 | | - sys.exit('Dependency \'' + req_args[0] + '\' is installed but outdated: the current version is \'' + current_version + '\', while version ' + req_args[1] + ' or higher is required.\n' |
37 | | - 'Execute \'pip install --upgrade ' + req_args[0] + '\' in the command-line prompt/terminal to update the package\n') |
38 | | - except PackageNotFoundError as err: |
39 | | - sys.exit('Dependency \'' + req_args[0] + '\' is required but not installed.\n' |
40 | | - 'Execute \'pip install ' + req_args[0] + '\' in the command-line prompt/terminal to install the package\n') |
| 21 | +try: |
| 22 | + require_lines = [p for p in requires('erdetect')] |
| 23 | + for req_line in require_lines: |
| 24 | + for req_line_part in req_line.split(','): |
| 25 | + req_args = re_split('>=|==', req_line_part.strip()) |
| 26 | + if len(req_args) == 2: |
| 27 | + req_args[0] = req_args[0].strip() |
| 28 | + req_args[1] = req_args[1].strip() |
| 29 | + try: |
| 30 | + current_version = version(req_args[0]) |
| 31 | + if normalize_version(current_version) < normalize_version(req_args[1]): |
| 32 | + sys.exit('Dependency \'' + req_args[0] + '\' is installed but outdated: the current version is \'' + current_version + '\', while version ' + req_args[1] + ' or higher is required.\n' |
| 33 | + 'Execute \'pip install --upgrade ' + req_args[0] + '\' in the command-line prompt/terminal to update the package\n') |
| 34 | + except PackageNotFoundError as err: |
| 35 | + sys.exit('Dependency \'' + req_args[0] + '\' is required but not installed.\n' |
| 36 | + 'Execute \'pip install ' + req_args[0] + '\' in the command-line prompt/terminal to install the package\n') |
| 37 | +except PackageNotFoundError as err: |
| 38 | + # not running a distribution, skip checks |
| 39 | + pass |
41 | 40 |
|
42 | 41 |
|
43 | 42 | # |
|
0 commit comments