Merge pull request #2964 from parrt/multi-py-versions

allow multiple versions when locating python tool
This commit is contained in:
Terence Parr 2020-11-24 12:37:07 -08:00 committed by GitHub
commit 9f3ebd1667
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 11 deletions

View File

@ -5,6 +5,7 @@
*/
package org.antlr.v4.test.runtime.python;
import com.sun.codemodel.internal.JForEach;
import org.antlr.v4.Tool;
import org.antlr.v4.automata.ATNFactory;
import org.antlr.v4.automata.ATNPrinter;
@ -513,31 +514,33 @@ public abstract class BasePythonTest implements RuntimeTestSupport {
return null;
}
private String locateTool(String tool) {
private String locateTool(List<String> tools) {
String[] roots = {
"/opt/local/bin", "/usr/bin/", "/usr/local/bin/",
"/Users/"+System.getProperty("user.name")+"/anaconda3/bin/"
};
for(String root : roots) {
if(new File(root + tool).exists()) {
return root+tool;
for (String tool : tools) {
if ( new File(root+tool).exists() ) {
return root+tool;
}
}
}
throw new RuntimeException("Could not locate " + tool);
throw new RuntimeException("Could not locate " + tools);
}
protected String locatePython() {
String propName = getPropertyPrefix() + "-python";
String prop = System.getProperty(propName);
if(prop==null || prop.length()==0)
prop = locateTool(getPythonExecutable());
prop = locateTool(getPythonExecutables());
File file = new File(prop);
if(!file.exists())
throw new RuntimeException("Missing system property:" + propName);
return file.getAbsolutePath();
}
protected abstract String getPythonExecutable();
protected abstract List<String> getPythonExecutables();
protected String locateRuntime() { return locateRuntime(getLanguage()); }

View File

@ -9,6 +9,10 @@ package org.antlr.v4.test.runtime.python2;
import org.antlr.v4.test.runtime.python.BasePythonTest;
import org.stringtemplate.v4.ST;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
public class BasePython2Test extends BasePythonTest {
@ -19,8 +23,8 @@ public class BasePython2Test extends BasePythonTest {
}
@Override
protected String getPythonExecutable() {
return "python2.7";
protected List<String> getPythonExecutables() {
return Collections.singletonList("python2.7");
}
@Override

View File

@ -8,6 +8,9 @@ package org.antlr.v4.test.runtime.python3;
import org.antlr.v4.test.runtime.python.BasePythonTest;
import org.stringtemplate.v4.ST;
import java.util.Arrays;
import java.util.List;
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
public class BasePython3Test extends BasePythonTest {
@ -18,9 +21,9 @@ public class BasePython3Test extends BasePythonTest {
}
@Override
protected String getPythonExecutable() {
return "python3.7";
} // force 3.7
protected List<String> getPythonExecutables() {
return Arrays.asList("python3.7", "python3.8");
} // force 3.7 or 3.8
@Override
protected void writeLexerTestFile(String lexerName, boolean showDFA) {