Skip to content

Commit 9f3ebd1

Browse files
authored
Merge pull request #2964 from parrt/multi-py-versions
allow multiple versions when locating python tool
2 parents 59c2469 + 537eca3 commit 9f3ebd1

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

runtime-testsuite/test/org/antlr/v4/test/runtime/python/BasePythonTest.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package org.antlr.v4.test.runtime.python;
77

8+
import com.sun.codemodel.internal.JForEach;
89
import org.antlr.v4.Tool;
910
import org.antlr.v4.automata.ATNFactory;
1011
import org.antlr.v4.automata.ATNPrinter;
@@ -513,31 +514,33 @@ public String execModule(String fileName) {
513514
return null;
514515
}
515516

516-
private String locateTool(String tool) {
517+
private String locateTool(List<String> tools) {
517518
String[] roots = {
518519
"/opt/local/bin", "/usr/bin/", "/usr/local/bin/",
519520
"/Users/"+System.getProperty("user.name")+"/anaconda3/bin/"
520521
};
521522
for(String root : roots) {
522-
if(new File(root + tool).exists()) {
523-
return root+tool;
523+
for (String tool : tools) {
524+
if ( new File(root+tool).exists() ) {
525+
return root+tool;
526+
}
524527
}
525528
}
526-
throw new RuntimeException("Could not locate " + tool);
529+
throw new RuntimeException("Could not locate " + tools);
527530
}
528531

529532
protected String locatePython() {
530533
String propName = getPropertyPrefix() + "-python";
531534
String prop = System.getProperty(propName);
532535
if(prop==null || prop.length()==0)
533-
prop = locateTool(getPythonExecutable());
536+
prop = locateTool(getPythonExecutables());
534537
File file = new File(prop);
535538
if(!file.exists())
536539
throw new RuntimeException("Missing system property:" + propName);
537540
return file.getAbsolutePath();
538541
}
539542

540-
protected abstract String getPythonExecutable();
543+
protected abstract List<String> getPythonExecutables();
541544

542545
protected String locateRuntime() { return locateRuntime(getLanguage()); }
543546

runtime-testsuite/test/org/antlr/v4/test/runtime/python2/BasePython2Test.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
import org.antlr.v4.test.runtime.python.BasePythonTest;
1010
import org.stringtemplate.v4.ST;
1111

12+
import java.util.ArrayList;
13+
import java.util.Collections;
14+
import java.util.List;
15+
1216
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
1317

1418
public class BasePython2Test extends BasePythonTest {
@@ -19,8 +23,8 @@ protected String getLanguage() {
1923
}
2024

2125
@Override
22-
protected String getPythonExecutable() {
23-
return "python2.7";
26+
protected List<String> getPythonExecutables() {
27+
return Collections.singletonList("python2.7");
2428
}
2529

2630
@Override

runtime-testsuite/test/org/antlr/v4/test/runtime/python3/BasePython3Test.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import org.antlr.v4.test.runtime.python.BasePythonTest;
99
import org.stringtemplate.v4.ST;
1010

11+
import java.util.Arrays;
12+
import java.util.List;
13+
1114
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
1215

1316
public class BasePython3Test extends BasePythonTest {
@@ -18,9 +21,9 @@ protected String getLanguage() {
1821
}
1922

2023
@Override
21-
protected String getPythonExecutable() {
22-
return "python3.7";
23-
} // force 3.7
24+
protected List<String> getPythonExecutables() {
25+
return Arrays.asList("python3.7", "python3.8");
26+
} // force 3.7 or 3.8
2427

2528
@Override
2629
protected void writeLexerTestFile(String lexerName, boolean showDFA) {

0 commit comments

Comments
 (0)