@@ -85,13 +85,6 @@ def get_gp():
85
85
86
86
return graalpy
87
87
88
- def replace_in_file (file , str , replace_str ):
89
- with open (file , "r" ) as f :
90
- contents = f .read ()
91
- assert str in contents
92
- with open (file , "w" ) as f :
93
- f .write (contents .replace (str , replace_str ))
94
-
95
88
def patch_properties_file (properties_file , distribution_url_override ):
96
89
if distribution_url_override :
97
90
new_lines = []
@@ -290,10 +283,10 @@ def test_gradle_generated_app_external_resources(self):
290
283
shutil .copyfile (os .path .join (target_dir , "src" , "main" , "resources" , "org.graalvm.python.vfs" , "src" , "hello.py" ), os .path .join (src_dir , "hello.py" ))
291
284
shutil .rmtree (os .path .join (target_dir , "src" , "main" , "resources" , "org.graalvm.python.vfs" ))
292
285
# patch GraalPy.java
293
- replace_in_file (os .path .join (target_dir , "src" , "main" , "java" , "org" , "example" , "GraalPy.java" ),
286
+ util . replace_in_file (os .path .join (target_dir , "src" , "main" , "java" , "org" , "example" , "GraalPy.java" ),
294
287
"package org.example;" ,
295
288
"package org.example;\n import java.nio.file.Path;" )
296
- replace_in_file (os .path .join (target_dir , "src" , "main" , "java" , "org" , "example" , "GraalPy.java" ),
289
+ util . replace_in_file (os .path .join (target_dir , "src" , "main" , "java" , "org" , "example" , "GraalPy.java" ),
297
290
"GraalPyResources.createContext()" ,
298
291
"GraalPyResources.contextBuilder(Path.of(\" python-resources\" )).build()" )
299
292
@@ -336,7 +329,7 @@ def test_gradle_fail_without_graalpy_dep(self):
336
329
337
330
gradle_cmd = util .get_gradle_wrapper (target_dir , self .env )
338
331
339
- replace_in_file (build_file ,
332
+ util . replace_in_file (build_file ,
340
333
"implementation(\" org.graalvm.python:python-community:24.2.0\" )" ,
341
334
"// implementation(\" org.graalvm.python:python-community:24.2.0\" )" )
342
335
@@ -498,9 +491,9 @@ def copy_build_files(self, target_dir):
498
491
mvn_repos = ""
499
492
for idx , custom_repo in enumerate (custom_repos .split ("," )):
500
493
mvn_repos += f"maven {{ url \" { custom_repo } \" }}\n "
501
- replace_in_file (build_file ,
494
+ util . replace_in_file (build_file ,
502
495
"repositories {" , f"repositories {{\n mavenLocal()\n { mvn_repos } " )
503
- replace_in_file (settings_file ,
496
+ util . replace_in_file (settings_file ,
504
497
"repositories {" , f"repositories {{\n { mvn_repos } " )
505
498
506
499
#print_file(build_file)
@@ -576,8 +569,8 @@ def copy_build_files(self, target_dir):
576
569
for idx , custom_repo in enumerate (custom_repos .split ("," )):
577
570
mvn_repos += f"maven(url=\" { custom_repo } \" )\n "
578
571
579
- replace_in_file (build_file , "repositories {" , f"repositories {{\n mavenLocal()\n { mvn_repos } " )
580
- replace_in_file (settings_file , "repositories {" , f"repositories {{\n { mvn_repos } " )
572
+ util . replace_in_file (build_file , "repositories {" , f"repositories {{\n mavenLocal()\n { mvn_repos } " )
573
+ util . replace_in_file (settings_file , "repositories {" , f"repositories {{\n { mvn_repos } " )
581
574
582
575
#print_file(build_file)
583
576
#print_file(settings_file)
@@ -727,15 +720,15 @@ def test_generated_app_external_resources(self):
727
720
shutil .copyfile (os .path .join (target_dir , "src" , "main" , "resources" , "org.graalvm.python.vfs" , "src" , "hello.py" ), os .path .join (src_dir , "hello.py" ))
728
721
shutil .rmtree (os .path .join (target_dir , "src" , "main" , "resources" , "org.graalvm.python.vfs" ))
729
722
# patch GraalPy.java
730
- replace_in_file (os .path .join (target_dir , "src" , "main" , "java" , "it" , "pkg" , "GraalPy.java" ),
723
+ util . replace_in_file (os .path .join (target_dir , "src" , "main" , "java" , "it" , "pkg" , "GraalPy.java" ),
731
724
"package it.pkg;" ,
732
725
"package it.pkg;\n import java.nio.file.Path;" )
733
- replace_in_file (os .path .join (target_dir , "src" , "main" , "java" , "it" , "pkg" , "GraalPy.java" ),
726
+ util . replace_in_file (os .path .join (target_dir , "src" , "main" , "java" , "it" , "pkg" , "GraalPy.java" ),
734
727
"GraalPyResources.createContext()" ,
735
728
"GraalPyResources.contextBuilder(Path.of(\" python-resources\" )).build()" )
736
729
737
730
# patch pom.xml
738
- replace_in_file (os .path .join (target_dir , "pom.xml" ),
731
+ util . replace_in_file (os .path .join (target_dir , "pom.xml" ),
739
732
"<packages>" ,
740
733
"<pythonResourcesDirectory>${project.basedir}/python-resources</pythonResourcesDirectory>\n <packages>" )
741
734
@@ -804,7 +797,7 @@ def test_gen_launcher_and_venv(self):
804
797
util .check_ouput ("termcolor" , out , False )
805
798
806
799
# remove ujson pkg from plugin config and check if unistalled
807
- replace_in_file (os .path .join (target_dir , "pom.xml" ), "<package>ujson</package>" , "" )
800
+ util . replace_in_file (os .path .join (target_dir , "pom.xml" ), "<package>ujson</package>" , "" )
808
801
809
802
cmd = mvnw_cmd + ["process-resources" ]
810
803
out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
@@ -847,15 +840,15 @@ def test_check_home(self):
847
840
# 2. process-resources with empty pythonHome includes and excludes
848
841
shutil .copyfile (pom_template , os .path .join (target_dir , "pom.xml" ))
849
842
util .patch_pom_repositories (os .path .join (target_dir , "pom.xml" ))
850
- replace_in_file (os .path .join (target_dir , "pom.xml" ), "</configuration>" , "<pythonHome></pythonHome></configuration>" )
843
+ util . replace_in_file (os .path .join (target_dir , "pom.xml" ), "</configuration>" , "<pythonHome></pythonHome></configuration>" )
851
844
out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir )
852
845
util .check_ouput ("BUILD SUCCESS" , out )
853
846
util .check_ouput ("Copying std lib to " , out , False )
854
847
self .check_tagfile (target_dir , [f'{ self .graalvmVersion } \n ' , 'include:.*\n ' ])
855
848
856
849
shutil .copyfile (pom_template , os .path .join (target_dir , "pom.xml" ))
857
850
util .patch_pom_repositories (os .path .join (target_dir , "pom.xml" ))
858
- replace_in_file (os .path .join (target_dir , "pom.xml" ), "</configuration>" , "<pythonHome><includes></includes><excludes></excludes></pythonHome></configuration>" )
851
+ util . replace_in_file (os .path .join (target_dir , "pom.xml" ), "</configuration>" , "<pythonHome><includes></includes><excludes></excludes></pythonHome></configuration>" )
859
852
out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir )
860
853
util .check_ouput ("BUILD SUCCESS" , out )
861
854
util .check_ouput ("Copying std lib to " , out , False )
@@ -875,7 +868,7 @@ def test_check_home(self):
875
868
</excludes>
876
869
</pythonHome>
877
870
"""
878
- replace_in_file (os .path .join (target_dir , "pom.xml" ), "</configuration>" , home_tag + "</configuration>" )
871
+ util . replace_in_file (os .path .join (target_dir , "pom.xml" ), "</configuration>" , home_tag + "</configuration>" )
879
872
out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir )
880
873
util .check_ouput ("BUILD SUCCESS" , out )
881
874
util .check_ouput ("Copying std lib to " , out , False )
@@ -892,7 +885,7 @@ def test_check_home(self):
892
885
</excludes>
893
886
</pythonHome>
894
887
"""
895
- replace_in_file (os .path .join (target_dir , "pom.xml" ), "</configuration>" , home_tag + "</configuration>" )
888
+ util . replace_in_file (os .path .join (target_dir , "pom.xml" ), "</configuration>" , home_tag + "</configuration>" )
896
889
out , return_code = util .run_cmd (process_resources_cmd , self .env , cwd = target_dir )
897
890
util .check_ouput ("BUILD SUCCESS" , out )
898
891
util .check_ouput ("Deleting GraalPy home due to changed includes or excludes" , out )
@@ -925,7 +918,7 @@ def test_empty_packages(self):
925
918
out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
926
919
util .check_ouput ("BUILD SUCCESS" , out )
927
920
928
- replace_in_file (os .path .join (target_dir , "pom.xml" ), "</packages>" , "<package></package><package> </package></packages>" )
921
+ util . replace_in_file (os .path .join (target_dir , "pom.xml" ), "</packages>" , "<package></package><package> </package></packages>" )
929
922
930
923
cmd = mvnw_cmd + ["process-resources" ]
931
924
out , return_code = util .run_cmd (cmd , self .env , cwd = target_dir )
0 commit comments