Skip to content

Commit

Permalink
adds option to run though Python Executable
Browse files Browse the repository at this point in the history
  • Loading branch information
lacan committed Jun 23, 2022
1 parent 8c0f9fa commit 8786d4e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ext.moduleName = 'qupath.extension.cellpose'

description = 'QuPath extension to use Cellpose'

version = "0.3.6"
version = "0.3.7"

dependencies {
def qupathVersion = "0.3.2" // For now
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/qupath/ext/biop/cmd/VirtualEnvironmentRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
* A wrapper to run python virtualenvs, that tries to figure out the commands to run based on the environment type
Expand All @@ -33,6 +34,7 @@ public class VirtualEnvironmentRunner {
public enum EnvType {
CONDA("Anaconda or Miniconda", "If you need to start your virtual environment with 'conda activate' then this is the type for you"),
VENV( "Python venv", "If you use 'myenv/Scripts/activate' to call your virtual environment, then use this environment type"),
EXE("Python Executable", "Use this if you'd like to call the python executable directly. Can be useful in case you have issues with conda."),
OTHER("Other (Unsupported)", "Currently only conda and venv are supported.");

private final String description;
Expand Down Expand Up @@ -94,6 +96,9 @@ private List<String> getActivationCommand() {
break;
}
break;
case EXE:
cmd.add(environmentNameOrPath);
break;
case OTHER:
return null;
}
Expand Down Expand Up @@ -135,7 +140,16 @@ public String[] runCommand() throws IOException, InterruptedException {
case OSX:
shell.addAll(Arrays.asList("bash", "-c"));

// If there are spaces, then we should encapsulate the command with quotes
command = command.stream().map(s -> {
if (s.trim().contains(" "))
return "\"" + s.trim() + "\"";
return s;
}).collect(Collectors.toList());

// The last part needs to be sent as a single string, otherwise it does not run
String cmdString = command.toString().replace(",","");

shell.add(cmdString.substring(1, cmdString.length()-1));
break;

Expand Down

0 comments on commit 8786d4e

Please sign in to comment.