-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgen_requirements_ci.py
38 lines (34 loc) · 1.33 KB
/
gen_requirements_ci.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
import argparse
def parse_args():
parser = argparse.ArgumentParser(
description='Generate requirements_ci.txt.')
# first read latest requirements file.
req = open('requirements.txt').read().splitlines()
# package:version
req = {line.split("==")[0]: line.split("==")[1] for line in req}
for pkg, pkg_version in req.items():
parser.add_argument('--' + pkg, type=str, default=pkg_version,
help=pkg + ' version')
parser.add_argument('--skip', type=str, nargs='+')
args, unknown = parser.parse_known_args()
for arg in unknown:
if arg.startswith(("-", "--")):
parser.add_argument(arg, type=str)
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
# find packages to be skipped
skip_pkgs = {}
if args.skip is not None:
skip_pkgs = set(args.skip)
# generate requirements_ci.txt
with open('requirements_ci.txt', 'w') as f:
total = len(args.__dict__) - len(skip_pkgs) - 1
count = 1
for pkg, pkg_version in args.__dict__.items():
if pkg not in skip_pkgs and pkg != "skip":
if (count == total):
f.write(pkg + '==' + pkg_version)
else:
f.write(pkg + '==' + pkg_version + '\n')
count += 1