This repository has been archived by the owner on Oct 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 116
/
workers_requirements.py
74 lines (55 loc) · 1.84 KB
/
workers_requirements.py
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
71
72
73
74
import importlib
from pathlib import Path
import pkg_resources
import re
import os
import logger
_LOGGER = logger.get(__name__)
def configured_workers():
from config import settings
workers = settings['manager']['workers']
return _get_requirements(workers)
def all_workers():
workers = map(lambda x: x.stem, Path('./workers').glob('*.py'))
return _get_requirements(workers)
def verify():
requirements = configured_workers()
egg = re.compile(r'.+#egg=(.+)$')
distributions = []
for req in requirements:
try:
pkg_resources.Requirement.parse(req)
distributions.append(req)
except (pkg_resources.extern.packaging.requirements.InvalidRequirement,
pkg_resources.RequirementParseError):
match = egg.match(req)
if match:
distributions.append(match.group(1))
else:
raise
errors = []
for dist in distributions:
try:
pkg_resources.require(dist)
except pkg_resources.ResolutionError as e:
errors.append(e.report())
if errors:
_LOGGER.error('Error: unsatisfied requirements:')
for error in errors:
_LOGGER.error(' %s', error)
if os.geteuid() == 0:
prefix = " sudo"
else:
prefix = ""
_LOGGER.error('You may install those with pip: cd %s ; %s python3 -m pip install `./gateway.py -r configured`',
os.path.dirname(os.path.abspath(__file__)), prefix)
exit(1)
def _get_requirements(workers):
requirements = set()
for worker_name in workers:
module_obj = importlib.import_module("workers.%s" % worker_name)
try:
requirements.update(module_obj.REQUIREMENTS)
except AttributeError:
continue
return requirements