|
8 | 8 | * it under the terms of the GNU General Public License as |
9 | 9 | * published by the Free Software Foundation, either version 3 of the |
10 | 10 | * License, or (at your option) any later version. |
11 | | - * |
| 11 | + * |
12 | 12 | * This program is distributed in the hope that it will be useful, |
13 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | 15 | * GNU General Public License for more details. |
16 | | - * |
| 16 | + * |
17 | 17 | * You should have received a copy of the GNU General Public |
18 | 18 | * License along with this program. If not, see |
19 | 19 | * <http://www.gnu.org/licenses/gpl-3.0.html>. |
20 | 20 | * #L% |
21 | 21 | */ |
22 | 22 | package fiji.plugin.trackmate.util.cli; |
23 | 23 |
|
24 | | -import java.io.IOException; |
25 | 24 | import java.util.ArrayList; |
26 | 25 | import java.util.Arrays; |
27 | 26 | import java.util.List; |
28 | 27 |
|
29 | | -import ij.IJ; |
30 | | - |
31 | 28 | public abstract class CondaCLIConfigurator extends CLIConfigurator |
32 | 29 | { |
33 | 30 |
|
@@ -127,55 +124,41 @@ protected CondaCLIConfigurator() |
127 | 124 | setCommandTranslator( condaEnv, s -> { |
128 | 125 | final List< String > cmd = new ArrayList<>(); |
129 | 126 | final String condaPath = CLIUtils.getCondaPath(); |
130 | | - // Conda and executable stuff. |
131 | | - final String envname = ( String ) s; |
132 | | - if ( IJ.isWindows() ) |
| 127 | + final String os = System.getProperty( "os.name" ).toLowerCase(); |
| 128 | + if ( os.contains( "win" ) ) |
133 | 129 | { |
134 | | - /* |
135 | | - * In Windows: Launch a shell, change the conda environment, |
136 | | - * runs the command in this environment. |
137 | | - */ |
| 130 | + // In Windows: Launch a cmd.exe shell. |
138 | 131 | cmd.addAll( Arrays.asList( "cmd.exe", "/c" ) ); |
139 | | - cmd.addAll( Arrays.asList( condaPath, "activate", envname ) ); |
140 | | - cmd.add( "&" ); |
141 | 132 | } |
142 | 133 | else |
143 | 134 | { |
144 | | - /* |
145 | | - * On Mac: we cannot change the conda environment in the process |
146 | | - * builder (I tried very hard). So we use the environment to |
147 | | - * retrieve what is the path of the Python executable of this |
148 | | - * env, and runs the tool as a module. It won't work if the tool |
149 | | - * cannot be run as a module. No escape yet. |
150 | | - * |
151 | | - * Unsure whether this works in Linux. |
152 | | - */ |
153 | | - try |
154 | | - { |
155 | | - final String pythonPath = CLIUtils.getEnvMap().get( envname ); |
156 | | - cmd.add( pythonPath ); |
157 | | - cmd.add( "-m" ); |
158 | | - } |
159 | | - catch ( final IOException e ) |
160 | | - { |
161 | | - System.err.println( "Could not find the conda executable or change the conda environment.\n" |
162 | | - + "Please configure the path to your conda executable in Edit > Options > Configure TrackMate Conda path..." ); |
163 | | - e.printStackTrace(); |
164 | | - } |
165 | | - catch ( final Exception e ) |
166 | | - { |
167 | | - System.err.println( "Error running the conda executable:\n" ); |
168 | | - e.printStackTrace(); |
169 | | - } |
| 135 | + // On Mac or Linux. |
| 136 | + } |
| 137 | + // Call conda run. |
| 138 | + cmd.add( condaPath ); |
| 139 | + cmd.add( "run" ); |
| 140 | + cmd.add( "-n" ); |
| 141 | + // The executable stuff. |
| 142 | + final String envname = ( String ) s; |
| 143 | + cmd.add( envname ); |
| 144 | + // Only add these flags for conda/mamba, NOT for micromamba |
| 145 | + if ( !isMicromamba( condaPath ) ) |
| 146 | + { |
| 147 | + cmd.add( "--no-capture-output" ); |
170 | 148 | } |
171 | | - // Split by spaces |
| 149 | + // The rest of the command, split by spaces. |
172 | 150 | final String executableCommand = getCommand(); |
173 | 151 | final String[] split = executableCommand.split( " " ); |
174 | 152 | cmd.addAll( Arrays.asList( split ) ); |
175 | 153 | return cmd; |
176 | 154 | } ); |
177 | 155 | } |
178 | 156 |
|
| 157 | + private static boolean isMicromamba( final String path ) |
| 158 | + { |
| 159 | + return path != null && path.toLowerCase().contains( "micromamba" ); |
| 160 | + } |
| 161 | + |
179 | 162 | @Override |
180 | 163 | public CondaEnvironmentCommand getCommandArg() |
181 | 164 | { |
|
0 commit comments