Skip to content

Commit 0ff4d19

Browse files
committed
Fix dependencies check for distribution
1 parent 9f73a9e commit 0ff4d19

1 file changed

Lines changed: 20 additions & 21 deletions

File tree

erdetect/__init__.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,30 @@
1313
# Note 1: added since, despite the (minimum) requirements during install, packages can be downgraded or removed later
1414
# Note 2: deliberately not in a separate module, since this is the entry point of the package and dependencies already be used after
1515
#
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
1917
from re import sub as re_sub, split as re_split
2018
def normalize_version(v):
2119
return [int(x) for x in re_sub(r'(\.0+)*$','', v).split(".")]
2220

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
4140

4241

4342
#

0 commit comments

Comments
 (0)