3939INIT_PY_END = "# END OF CONNECTION WRAPPER"
4040
4141# Read the JSON file
42- with open (WRAPPER_JSON_PATH ) as json_file :
43- wrapper_methods = json .load (json_file )
42+ wrapper_methods = json .loads (Path (WRAPPER_JSON_PATH ).read_text ())
4443
4544# On DuckDBPyConnection these are read_only_properties, they're basically functions without requiring () to invoke
4645# that's not possible on 'duckdb' so it becomes a function call with no arguments (i.e duckdb.description())
@@ -96,20 +95,17 @@ def remove_section(content, start_marker, end_marker) -> tuple[list[str], list[s
9695
9796def generate ():
9897 # Read the DUCKDB_PYTHON_SOURCE file
99- with open (DUCKDB_PYTHON_SOURCE ) as source_file :
100- source_code = source_file .readlines ()
98+ source_code = Path (DUCKDB_PYTHON_SOURCE ).read_text ().splitlines ()
10199 start_section , end_section = remove_section (source_code , START_MARKER , END_MARKER )
102100
103101 # Read the DUCKDB_INIT_FILE file
104- with open (DUCKDB_INIT_FILE ) as source_file :
105- source_code = source_file .readlines ()
102+ source_code = Path (DUCKDB_INIT_FILE ).read_text ().splitlines ()
106103 py_start , py_end = remove_section (source_code , INIT_PY_START , INIT_PY_END )
107104
108105 # ---- Generate the definition code from the json ----
109106
110107 # Read the JSON file
111- with open (JSON_PATH ) as json_file :
112- connection_methods = json .load (json_file )
108+ connection_methods = json .loads (Path (JSON_PATH ).read_text ())
113109
114110 # Collect the definitions from the pyconnection.hpp header
115111
@@ -241,8 +237,7 @@ def create_definition(name, method, lambda_def) -> str:
241237 # Recreate the file content by concatenating all the pieces together
242238 new_content = start_section + with_newlines + end_section
243239 # Write out the modified DUCKDB_PYTHON_SOURCE file
244- with open (DUCKDB_PYTHON_SOURCE , "w" ) as source_file :
245- source_file .write ("" .join (new_content ))
240+ Path (DUCKDB_PYTHON_SOURCE ).write_text ("" .join (new_content ))
246241
247242 item_list = "\n " .join ([f"\t { name } ," for name in all_names ])
248243 str_item_list = "\n " .join ([f"\t '{ name } '," for name in all_names ])
@@ -251,8 +246,7 @@ def create_definition(name, method, lambda_def) -> str:
251246
252247 init_py_content = py_start + imports + py_end
253248 # Write out the modified DUCKDB_INIT_FILE file
254- with open (DUCKDB_INIT_FILE , "w" ) as source_file :
255- source_file .write ("" .join (init_py_content ))
249+ Path (DUCKDB_INIT_FILE ).write_text ("" .join (init_py_content ))
256250
257251
258252if __name__ == "__main__" :
0 commit comments