77import csv
88from collections import OrderedDict
99from pathlib import Path
10+ import subprocess
1011
1112SCRIPT_DIR = Path (__file__ ).parent
13+
14+ _DIFF_TOOLS_REPO_URL = "https://github.com/approvals/DiffTools"
15+
1216PROJECT_ROOT = SCRIPT_DIR .parent
13- CSV_PATH = PROJECT_ROOT / 'approvaltests' / 'DiffTools' / 'diff_reporters.csv'
17+ _DIFF_TOOLS_DIR = PROJECT_ROOT / '.ignore/DiffTools'
18+ CSV_PATH = _DIFF_TOOLS_DIR / 'diff_reporters.csv'
1419BASE_OUTPUT = (PROJECT_ROOT / 'approvaltests' / 'src' / 'main' / 'java'
1520 / 'org' / 'approvaltests' / 'reporters' )
1621
@@ -232,6 +237,22 @@ def generate_os_aggregator(os_name, os_rows):
232237 lines .append ('' )
233238 write_java (BASE_OUTPUT / os_pkg / f'{ cls } .java' , '\n ' .join (lines ))
234239
240+ def clone_and_update_diff_tools () -> None :
241+ if not _DIFF_TOOLS_DIR .exists ():
242+ subprocess .run (
243+ ["git" , "clone" , _DIFF_TOOLS_REPO_URL , _DIFF_TOOLS_DIR .as_posix ()],
244+ check = True ,
245+ )
246+ return
247+
248+ if not _DIFF_TOOLS_DIR .joinpath (".git" ).exists ():
249+ raise RuntimeError (f"{ _DIFF_TOOLS_DIR } exists but is not a git repository" )
250+
251+ subprocess .run (
252+ ["git" , "-C" , _DIFF_TOOLS_DIR .as_posix (), "pull" , "--ff-only" ],
253+ check = True ,
254+ )
255+
235256
236257# ---------------------------------------------------------------------------
237258# Main
@@ -241,6 +262,8 @@ def main():
241262 print ('Generating diff reporter classes from diff_reporters.csv...' )
242263 print ()
243264
265+ clone_and_update_diff_tools ()
266+
244267 with open (CSV_PATH , newline = '' , encoding = 'utf-8' ) as f :
245268 rows = list (csv .DictReader (f ))
246269
0 commit comments