forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaddle_pip_check.py
64 lines (59 loc) · 2.12 KB
/
paddle_pip_check.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
import pkg_resources
import re
import sys
import os
req_file=sys.argv[1]
constraints = {}
constraints_path = []
requirements = []
# read requirements and find constraints file
with open(req_file) as f:
raw_requirements = f.readlines()
for line in raw_requirements:
if line.startswith("-c"):
constraints_path.append(os.path.join(os.path.dirname(req_file), line.split(' ')[1][:-1]))
# read constraints if they exist
if constraints_path:
for constraint_path in constraints_path:
with open(constraint_path) as f:
raw_constraints = f.readlines()
for line in raw_constraints:
if line.startswith("#") or line=="\n":
continue
line = line.replace("\n", "")
package, delimiter, constraint = re.split("(~|=|<|>|;)", line, maxsplit=1)
if constraints.get(package) is None:
constraints[package] = [delimiter + constraint]
else:
constraints[package].extend([delimiter + constraint])
for line in raw_requirements:
if line.startswith(("#", "-c")):
continue
line = line.replace("\n", "")
if re.search("(~|=|<|>|;)", line):
requirements.append(line)
else:
constraint = constraints.get(line)
if constraint:
for marker in constraint:
requirements.append(line+marker)
else:
requirements.append(line)
else:
requirements = raw_requirements
try:
pkg_resources.require(requirements)
except Exception as inst:
pattern = re.compile(
r"protobuf .*, Requirement.parse\('protobuf<=3\.20\.0,>=3\.1\.0'\), {'paddlepaddle'}"
)
result = pattern.findall(str(inst))
if len(result) == 0:
raise inst
else:
env = pkg_resources.Environment()
env['protobuf'].clear()
env.add(pkg_resources.DistInfoDistribution(project_name="protobuf", version="3.20.0"))
ws = pkg_resources.working_set
reqs = pkg_resources.parse_requirements(open(req_file, mode='r'))
dists = ws.resolve(reqs, env, replace_conflicting=True)