-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sub-class for CLIConfigurator that specializes in conda Python tools.
For many tools we want to integrate are Python tools that can be run from a specific conda environment. If the implementing CLI config knows already what is the Python command, the user should just have to specify in what conda env it is installed. It is more convenient than to browse to a Python executable and less prone to error.
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/main/java/fiji/plugin/trackmate/util/cli/CondaCLIConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package fiji.plugin.trackmate.util.cli; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class CondaCLIConfigurator extends CLIConfigurator | ||
{ | ||
|
||
public static final String KEY_CONDA_ENV = "CONDA_ENV"; | ||
|
||
private final ChoiceArgument condaEnv; | ||
|
||
protected CondaCLIConfigurator() | ||
{ | ||
super(); | ||
|
||
// Make a UI-only arg configuring the conda env. | ||
// Default is last one (base is not interesting as a default). | ||
final List< String > envList = CLIUtils.getEnvList(); | ||
this.condaEnv = addChoiceArgument() | ||
.name( "Conda environment" ) | ||
.help( "In what conda environment is the tool installed." ) | ||
.addChoiceAll( envList ) | ||
.defaultValue( envList.get( envList.size() - 1 ) ) | ||
.key( KEY_CONDA_ENV ) | ||
.visible( true ) | ||
.inCLI( false ) | ||
.get(); | ||
|
||
// Don't show the executable arg in the UI: must be set by subclass, and | ||
// only conda env required configurating. | ||
getExecutableArg().visible( false ); | ||
|
||
// Add the translator to make a proper cmd line calling conda first. | ||
setTranslator( getExecutableArg(), s -> { | ||
final String executableName = ( String ) s; | ||
// Split by spaces | ||
final String[] split = executableName.split( " " ); | ||
final List< String > cmd = new ArrayList<>(); | ||
final String envname = condaEnv.getValue(); | ||
cmd.addAll( Arrays.asList( "cmd.exe", "/c", "conda", "activate", envname ) ); | ||
cmd.add( "&" ); | ||
cmd.addAll( Arrays.asList( split ) ); | ||
return cmd; | ||
} ); | ||
} | ||
|
||
public ChoiceArgument getCondaEnv() | ||
{ | ||
return condaEnv; | ||
} | ||
|
||
@Override | ||
public String check() | ||
{ | ||
return checkArguments(); | ||
} | ||
} |