Commit 667aacaa authored by Christopher Jan-Steffen Brix's avatar Christopher Jan-Steffen Brix
Browse files

Added command line option to set the python path

parent 570a0db1
......@@ -105,7 +105,7 @@ public class EMADLGenerator {
return emamGen;
}
public void generate(String modelPath, String qualifiedName, String forced) throws IOException, TemplateException {
public void generate(String modelPath, String qualifiedName, String pythonPath, String forced) throws IOException, TemplateException {
setModelsPath( modelPath );
TaggingResolver symtab = EMADLAbstractSymtab.createSymTabAndTaggingResolver(getModelsPath());
ComponentSymbol component = symtab.<ComponentSymbol>resolve(qualifiedName, ComponentSymbol.KIND).orElse(null);
......@@ -122,7 +122,7 @@ public class EMADLGenerator {
ExpandedComponentInstanceSymbol instance = component.getEnclosingScope().<ExpandedComponentInstanceSymbol>resolve(instanceName, ExpandedComponentInstanceSymbol.KIND).get();
generateFiles(symtab, instance, symtab, forced);
generateFiles(symtab, instance, symtab, pythonPath, forced);
try{
executeCommands();
}catch(Exception e){
......@@ -184,7 +184,7 @@ public class EMADLGenerator {
}
}
public void generateFiles(TaggingResolver taggingResolver, ExpandedComponentInstanceSymbol componentSymbol, Scope symtab, String forced) throws IOException {
public void generateFiles(TaggingResolver taggingResolver, ExpandedComponentInstanceSymbol componentSymbol, Scope symtab, String pythonPath, String forced) throws IOException {
Set<ExpandedComponentInstanceSymbol> allInstances = new HashSet<>();
List<FileContent> fileContents = generateStrings(taggingResolver, componentSymbol, symtab, allInstances, forced);
......@@ -234,9 +234,8 @@ public class EMADLGenerator {
String parsedFullName = componentInstance.getFullName().substring(0, 1).toLowerCase() + componentInstance.getFullName().substring(1).replaceAll("\\.", "_");
String trainerScriptName = "CNNTrainer_" + parsedFullName + ".py";
String trainingPath = getGenerationTargetPath() + trainerScriptName;
String pythonExe = "/usr/bin/python";
if(Files.exists(Paths.get(trainingPath))){
ProcessBuilder pb = new ProcessBuilder(Arrays.asList(pythonExe, trainingPath)).inheritIO();
ProcessBuilder pb = new ProcessBuilder(Arrays.asList(pythonPath, trainingPath)).inheritIO();
Process p = pb.start();
int exitCode = 0;
......
......@@ -56,15 +56,20 @@ public class EMADLGeneratorCli {
.hasArg(true)
.required(false)
.build();
/**/
public static final Option OPTION_TRAINING_PYTHON_PATH = Option.builder("p")
.longOpt("python")
.desc("path to python. Default is /usr/bin/python")
.hasArg(true)
.required(false)
.build();
public static final Option OPTION_RESTRAINED_TRAINING = Option.builder("f")
.longOpt("forced")
.desc("no training or a forced training. Options: y (a forced training), n (no training)")
.hasArg(true)
.required(false)
.build();
.build();
private EMADLGeneratorCli() {
......@@ -86,6 +91,7 @@ public class EMADLGeneratorCli {
options.addOption(OPTION_OUTPUT_PATH);
options.addOption(OPTION_BACKEND);
options.addOption(OPTION_RESTRAINED_TRAINING);
options.addOption(OPTION_TRAINING_PYTHON_PATH);
return options;
}
......@@ -106,6 +112,7 @@ public class EMADLGeneratorCli {
String outputPath = cliArgs.getOptionValue(OPTION_OUTPUT_PATH.getOpt());
String backendString = cliArgs.getOptionValue(OPTION_BACKEND.getOpt());
String forced = cliArgs.getOptionValue(OPTION_RESTRAINED_TRAINING.getOpt());
String pythonPath = cliArgs.getOptionValue(OPTION_TRAINING_PYTHON_PATH.getOpt());
final String DEFAULT_BACKEND = "MXNET";
final String DEFAULT_FORCED = "UNSET";
......@@ -120,6 +127,9 @@ public class EMADLGeneratorCli {
backend = Backend.getBackendFromString(DEFAULT_BACKEND);
}
if(pythonPath == null) {
pythonPath = "/usr/bin/python";
}
if (forced == null) {
Log.warn("forced not specified. forced set to default value" + DEFAULT_FORCED);
......@@ -139,7 +149,7 @@ public class EMADLGeneratorCli {
generator.setGenerationTargetPath(outputPath);
}
try{
generator.generate(cliArgs.getOptionValue(OPTION_MODELS_PATH.getOpt()), rootModelName, forced);
generator.generate(cliArgs.getOptionValue(OPTION_MODELS_PATH.getOpt()), rootModelName, pythonPath, forced);
}
catch (IOException e){
Log.error("io error during generation", e);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment