From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 5D3AF1382C5 for ; Fri, 12 Mar 2021 02:31:30 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 76B58E083D; Fri, 12 Mar 2021 02:31:29 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 5D1A0E083D for ; Fri, 12 Mar 2021 02:31:29 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 294D033BEF2 for ; Fri, 12 Mar 2021 02:31:28 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 56A7B58C for ; Fri, 12 Mar 2021 02:31:26 +0000 (UTC) From: "Matt Turner" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Matt Turner" Message-ID: <1615516276.273b4530ebb098fa140614d72532e5c6cb277df2.mattst88@gentoo> Subject: [gentoo-commits] proj/gentoolkit:master commit in: bin/ X-VCS-Repository: proj/gentoolkit X-VCS-Files: bin/merge-driver-ekeyword X-VCS-Directories: bin/ X-VCS-Committer: mattst88 X-VCS-Committer-Name: Matt Turner X-VCS-Revision: 273b4530ebb098fa140614d72532e5c6cb277df2 X-VCS-Branch: master Date: Fri, 12 Mar 2021 02:31:26 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 1b39d74f-36d2-490d-b8dd-63611b7dcc21 X-Archives-Hash: 67b06a2cb2ac2cc3d113d0db1ce0ca34 commit: 273b4530ebb098fa140614d72532e5c6cb277df2 Author: Matt Turner gentoo org> AuthorDate: Fri Mar 12 02:24:29 2021 +0000 Commit: Matt Turner gentoo org> CommitDate: Fri Mar 12 02:31:16 2021 +0000 URL: https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=273b4530 bin: Fix type annotations Signed-off-by: Matt Turner gentoo.org> bin/merge-driver-ekeyword | 21 ++++++++++----------- 1 file 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)