summaryrefslogtreecommitdiff
path: root/bin/merge-driver-ekeyword
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gentoo.org>2021-03-11 21:24:29 -0500
committerMatt Turner <mattst88@gentoo.org>2021-03-11 21:31:16 -0500
commit273b4530ebb098fa140614d72532e5c6cb277df2 (patch)
tree46a662526042852c7871f51a59fc4be19dc92c27 /bin/merge-driver-ekeyword
parent548c180f92cd4adfd42c2403e61629267fa32b73 (diff)
downloadgentoolkit-273b4530ebb098fa140614d72532e5c6cb277df2.tar.gz
bin: Fix type annotations
Signed-off-by: Matt Turner <mattst88@gentoo.org>
Diffstat (limited to 'bin/merge-driver-ekeyword')
-rwxr-xr-xbin/merge-driver-ekeyword21
1 files changed, 10 insertions, 11 deletions
diff --git a/bin/merge-driver-ekeyword b/bin/merge-driver-ekeyword
index d24aaf9..7f4a10b 100755
--- a/bin/merge-driver-ekeyword
+++ b/bin/merge-driver-ekeyword
@@ -14,11 +14,13 @@ import os
import sys
import tempfile
-from typing import List, Optional, Tuple
+from typing import List, Optional, Sequence, Tuple
from gentoolkit.ekeyword import ekeyword
+KeywordChanges = List[Tuple[Optional[List[str]], Optional[List[str]]]]
+
def keyword_array(keyword_line: str) -> List[str]:
# Find indices of string inside the double-quotes
i1: int = keyword_line.find('"') + 1
@@ -28,14 +30,13 @@ def keyword_array(keyword_line: str) -> List[str]:
return keyword_line[i1:i2].split(' ')
-def keyword_line_changes(old: str, new: str) -> List[Tuple[Optional[str],
- Optional[str]]]:
+def keyword_line_changes(old: str, new: str) -> KeywordChanges:
a: List[str] = keyword_array(old)
b: List[str] = keyword_array(new)
s = difflib.SequenceMatcher(a=a, b=b)
- changes = []
+ changes: KeywordChanges = []
for tag, i1, i2, j1, j2 in s.get_opcodes():
if tag == 'replace':
changes.append((a[i1:i2], b[j1:j2]),)
@@ -48,8 +49,7 @@ def keyword_line_changes(old: str, new: str) -> List[Tuple[Optional[str],
return changes
-def keyword_changes(ebuild1: str, ebuild2: str) -> List[Tuple[Optional[str],
- Optional[str]]]:
+def keyword_changes(ebuild1: str, ebuild2: str) -> Optional[KeywordChanges]:
with open(ebuild1) as e1, open(ebuild2) as e2:
lines1 = e1.readlines()
lines2 = e2.readlines()
@@ -82,8 +82,7 @@ def keyword_changes(ebuild1: str, ebuild2: str) -> List[Tuple[Optional[str],
def apply_keyword_changes(ebuild: str, pathname: str,
- changes: List[Tuple[Optional[str],
- Optional[str]]]) -> int:
+ changes: KeywordChanges) -> int:
result: int = 0
with tempfile.TemporaryDirectory() as tmpdir:
@@ -109,7 +108,7 @@ def apply_keyword_changes(ebuild: str, pathname: str,
return result
-def main(argv):
+def main(argv: Sequence[str]) -> int:
if len(argv) != 5:
sys.exit(-1)
@@ -122,10 +121,10 @@ def main(argv):
changes = keyword_changes(O, B)
if changes:
# Apply O -> B changes to A
- result: int = apply_keyword_changes(A, P, changes)
+ result = apply_keyword_changes(A, P, changes)
sys.exit(result)
else:
- result: int = os.system(f"git merge-file -L HEAD -L base -L ours {A} {O} {B}")
+ result = os.system(f"git merge-file -L HEAD -L base -L ours {A} {O} {B}")
sys.exit(0 if result == 0 else -1)