1515
1616parser = argparse .ArgumentParser (description = "Find equivalent files in cpython and rustpython" )
1717parser .add_argument ("--cpython" , type = pathlib .Path , required = True , help = "Path to cpython source code" )
18- parser .add_argument ("--updated-libs" , type = pathlib .Path , required = False ,
19- help = "Libraries that have been updated in RustPython" )
2018parser .add_argument ("--notes" , type = pathlib .Path , required = False , help = "Path to notes file" )
2119
2220args = parser .parse_args ()
2321
24- def check_pr (pr_id ) -> bool :
22+ def check_pr (pr_id : str ) -> bool :
2523 if pr_id .startswith ("#" ):
2624 pr_id = pr_id [1 :]
27- pr_id = int (pr_id )
28- req = f"https://api.github.com/repos/RustPython/RustPython/pulls/{ pr_id } "
25+ int_pr_id = int (pr_id )
26+ req = f"https://api.github.com/repos/RustPython/RustPython/pulls/{ int_pr_id } "
2927 response = requests .get (req ).json ()
3028 return response ["merged_at" ] is not None
3129
@@ -34,38 +32,37 @@ class LibUpdate:
3432 pr : Optional [str ] = None
3533 done : bool = True
3634
37- updated_libs = {}
38- if args .updated_libs :
39- # check if the file exists in the rustpython lib directory
40- updated_libs_path = args .updated_libs
41- if updated_libs_path .exists ():
42- with open (updated_libs_path ) as f :
43- for line in f :
44- line = line .strip ()
45- if not line .startswith ("//" ) and line :
46- line = line .split (" " )
47- if len (line ) == 2 :
48- is_done = True
49- try :
50- is_done = check_pr (line [1 ])
51- except Exception as e :
52- warnings .warn (f"Failed to check PR { line [1 ]} : { e } " )
53- updated_libs [line [0 ]] = LibUpdate (line [1 ])
54- elif len (line ) == 1 :
55- updated_libs [line [0 ]] = LibUpdate ()
56- else :
57- raise ValueError (f"Invalid line: { line } " )
35+ def parse_updated_lib_issue (issue_body : str ) -> dict [str , LibUpdate ]:
36+ lines = issue_body .splitlines ()
37+ updated_libs = {}
38+ for line in lines :
39+ if line .strip ().startswith ("- " ):
40+ line = line .strip ()[2 :]
41+ out = line .split (" " )
42+ out = [x for x in out if x ]
43+ assert len (out ) < 3
44+ if len (out ) == 1 :
45+ updated_libs [out [0 ]] = LibUpdate ()
46+ elif len (out ) == 2 :
47+ updated_libs [out [0 ]] = LibUpdate (out [1 ], check_pr (out [1 ]))
48+ return updated_libs
49+
50+ def get_updated_libs () -> dict [str , LibUpdate ]:
51+ issue_id = "5736"
52+ req = f"https://api.github.com/repos/RustPython/RustPython/issues/{ issue_id } "
53+ response = requests .get (req ).json ()
54+ return parse_updated_lib_issue (response ["body" ])
55+
56+ updated_libs = get_updated_libs ()
5857
59- else :
60- raise FileNotFoundError (f"Path { updated_libs_path } does not exist" )
6158if not args .cpython .exists ():
6259 raise FileNotFoundError (f"Path { args .cpython } does not exist" )
6360if not args .cpython .is_dir ():
6461 raise NotADirectoryError (f"Path { args .cpython } is not a directory" )
6562if not args .cpython .is_absolute ():
6663 args .cpython = args .cpython .resolve ()
6764
68- notes = {}
65+ notes : dict = {}
6966if args .notes :
7067 # check if the file exists in the rustpython lib directory
7168 notes_path = args .notes
@@ -74,13 +71,13 @@ class LibUpdate:
7471 for line in f :
7572 line = line .strip ()
7673 if not line .startswith ("//" ) and line :
77- line = line .split (" " )
78- if len (line ) > 1 :
79- rest = " " .join (line [1 :])
80- if line [0 ] in notes :
81- notes [line [0 ]].append (rest )
74+ line_split = line .split (" " )
75+ if len (line_split ) > 1 :
76+ rest = " " .join (line_split [1 :])
77+ if line_split [0 ] in notes :
78+ notes [line_split [0 ]].append (rest )
8279 else :
83- notes [line [0 ]] = [rest ]
80+ notes [line_split [0 ]] = [rest ]
8481 else :
8582 raise ValueError (f"Invalid note: { line } " )
8683
0 commit comments