-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpatch_imports.py
More file actions
executable file
·49 lines (37 loc) · 1.1 KB
/
patch_imports.py
File metadata and controls
executable file
·49 lines (37 loc) · 1.1 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
#!/usr/bin/env python3
"""Script for rewriting imports from github.com/biogo -> github.com/grailbio/hts.
Usage:
cd $GRAIL/go/srcgitthub.com/grailbio/hts
./patch_imports.py
"""
import os
import logging
import re
from typing import List
def patch(path: str) -> None:
"""Patch the import lines of the given python. It updates the file in place."""
changed = False
lines: List[str] = []
with open(path) as fd:
for line in fd.readlines():
new_line = re.sub(
r'"github.com/biogo/hts', '"github.com/grailbio/hts', line
)
if new_line != line:
line = new_line
changed = True
lines.append(line)
if not changed:
return
logging.info("Patching %s", path)
with open(path, "w") as fd:
for line in lines:
fd.write(line)
def main() -> None:
"""Entry point"""
logging.basicConfig(level=logging.DEBUG)
for root, _, files in os.walk("."):
for path in files:
if path.endswith(".go"):
patch(os.path.join(root, path))
main()