-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtransfer-requirements-git-urls
More file actions
executable file
·73 lines (57 loc) · 1.9 KB
/
transfer-requirements-git-urls
File metadata and controls
executable file
·73 lines (57 loc) · 1.9 KB
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
#! /usr/bin/env python3
import sys
import pathlib
import re
vcs_url_re = re.compile(
r"(git\+[a-z]+://[-_a-zA-Z0-9./]+)"
"((?:@[-_a-zA-Z0-9]+)?)"
r"\#egg=([-a-zA-Z0-9_.]+)"
)
def main():
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("from_file", metavar="FROM_REQ.TXT")
parser.add_argument("to_file", metavar="TO_REQ.TXT")
args = parser.parse_args()
pkg_to_url_branch = {}
with pathlib.Path(args.from_file).open() as req_txt:
for ln in req_txt:
ln = ln.strip()
if not ln:
continue
if ln.startswith("#"):
continue
match = vcs_url_re.search(ln)
if not match:
continue
branch = match.group(2)
if branch:
assert branch.startswith("@")
branch = branch[1:]
pkg_to_url_branch[match.group(3)] = (
match.group(1),
branch,
)
with pathlib.Path(args.to_file).open() as req_txt:
result = []
for ln in req_txt:
lnread = ln.strip()
if not lnread:
result.append(ln)
if lnread.startswith("#"):
result.append(ln)
match = vcs_url_re.search(lnread)
if match and match.group(3) in pkg_to_url_branch:
projname = match.group(3)
base_url, branch = pkg_to_url_branch[projname]
pkgspec = f"{base_url}"
if branch:
pkgspec += f"@{branch}"
pkgspec += f"#egg={projname}"
result.append(vcs_url_re.sub(pkgspec, ln))
else:
result.append(ln)
with pathlib.Path(args.to_file).open("w") as req_txt:
req_txt.write("".join(result))
if __name__ == "__main__":
main()