6262 mnemonic = 'o' ), @ Menu (label = "Python..." , weight = 10 ), })
6363public class OptionsPython extends OptionsPlugin {
6464
65+ // -- Dependency constants and fields --
66+ private static final String DEFAULT_PYIMAGEJ = "pyimagej>=1.7.0" ;
67+ private static final String DEFAULT_APPOSE_PYTHON =
68+ "git+https://github.com/apposed/appose-python.git@efe6dadb2242ca45820fcbb7aeea2096f99f9cb2" ;
69+
6570 @ Parameter
6671 private AppService appService ;
6772
@@ -92,6 +97,12 @@ public class OptionsPython extends OptionsPlugin {
9297 @ Parameter (required = false )
9398 private UIService uiService ;
9499
100+ // -- Private fields --
101+
102+ // These hold the parsed or user-specified values, or null if not found
103+ private String pyimagejDependency ;
104+ private String apposePythonDependency ;
105+
95106 private boolean initialPythonMode = false ;
96107 private String initialCondaDependencies ;
97108 private String initialPipDependencies ;
@@ -158,6 +169,8 @@ public void load() {
158169 // Populate condaDependencies and pipDependencies from environment.yml
159170 condaDependencies = "" ;
160171 pipDependencies = "" ;
172+ pyimagejDependency = null ;
173+ apposePythonDependency = null ;
161174 java .util .Set <String > pipBlacklist = new java .util .HashSet <>();
162175 pipBlacklist .add ("appose-python" );
163176 pipBlacklist .add ("pyimagej" );
@@ -190,14 +203,19 @@ public void load() {
190203 }
191204 if (inPip && trimmed .startsWith ("- " )) {
192205 String pipDep = trimmed .substring (2 ).trim ();
193- boolean blacklisted = false ;
194- for (String bad : pipBlacklist ) {
195- if (pipDep .contains (bad )) {
196- blacklisted = true ;
197- break ;
206+ if (pipDep .startsWith ("pyimagej" )) pyimagejDependency = pipDep ;
207+ else if (pipDep .contains ("appose-python" )) apposePythonDependency =
208+ pipDep ;
209+ else {
210+ boolean blacklisted = false ;
211+ for (String bad : pipBlacklist ) {
212+ if (pipDep .contains (bad )) {
213+ blacklisted = true ;
214+ break ;
215+ }
198216 }
217+ if (!blacklisted ) pipDeps .add (pipDep );
199218 }
200- if (!blacklisted ) pipDeps .add (pipDep );
201219 continue ;
202220 }
203221 if (inDeps && !trimmed .startsWith ("- " ) && !trimmed .isEmpty ())
@@ -297,9 +315,6 @@ private File writeEnvironmentYaml() {
297315 try {
298316 String name = "fiji" ;
299317 String [] channels = { "conda-forge" };
300- String pyimagej = "pyimagej>=1.7.0" ;
301- String apposePython =
302- "git+https://github.com/apposed/appose-python.git@efe6dadb2242ca45820fcbb7aeea2096f99f9cb2" ;
303318 StringBuilder yml = new StringBuilder ();
304319 yml .append ("name: " ).append (name ).append ("\n channels:\n " );
305320 for (String ch : channels )
@@ -311,14 +326,30 @@ private File writeEnvironmentYaml() {
311326 }
312327 yml .append (" - pip\n " );
313328 yml .append (" - pip:\n " );
329+ boolean foundPyimagej = false , foundAppose = false ;
314330 for (String dep : pipDependencies .split ("\n " )) {
315331 String trimmed = dep .trim ();
316- if (!trimmed .isEmpty ()) yml .append (" - " ).append (trimmed ).append (
317- "\n " );
332+ if (!trimmed .isEmpty ()) {
333+ if (trimmed .startsWith ("pyimagej" )) foundPyimagej = true ;
334+ if (trimmed .contains ("appose-python" )) foundAppose = true ;
335+ yml .append (" - " ).append (trimmed ).append ("\n " );
336+ }
337+ }
338+ // Append pyimagej if not found
339+ if (!foundPyimagej ) {
340+ String pyimagej = pyimagejDependency != null ? pyimagejDependency
341+ : DEFAULT_PYIMAGEJ ;
342+ yml .append (" - " ).append (pyimagej ).append ("\n " );
343+ }
344+ // Append appose-python if not found
345+ if (!foundAppose ) {
346+ String apposePython = apposePythonDependency != null
347+ ? apposePythonDependency : DEFAULT_APPOSE_PYTHON ;
348+ yml .append (" - " ).append (apposePython ).append ("\n " );
318349 }
319- yml .append (" - " ).append (pyimagej ).append ("\n " );
320- yml .append (" - " ).append (apposePython ).append ("\n " );
321350 java .nio .file .Files .write (envFile .toPath (), yml .toString ().getBytes ());
351+ pyimagejDependency = null ;
352+ apposePythonDependency = null ;
322353 }
323354 catch (Exception e ) {
324355 log .debug ("Could not write environment.yml: " + e .getMessage ());
0 commit comments