66 * %%
77 * Redistribution and use in source and binary forms, with or without
88 * modification, are permitted provided that the following conditions are met:
9- *
9+ *
1010 * 1. Redistributions of source code must retain the above copyright notice,
1111 * this list of conditions and the following disclaimer.
1212 * 2. Redistributions in binary form must reproduce the above copyright notice,
1313 * this list of conditions and the following disclaimer in the documentation
1414 * and/or other materials provided with the distribution.
15- *
15+ *
1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1818 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2929
3030package org .scijava .plugins .scripting .python ;
3131
32+ import java .io .File ;
33+ import java .io .IOException ;
34+ import java .nio .file .Path ;
35+ import java .nio .file .Paths ;
36+ import java .util .LinkedHashMap ;
37+ import java .util .Map ;
38+
3239import org .scijava .app .AppService ;
3340import org .scijava .command .CommandService ;
3441import org .scijava .launcher .Config ;
4047import org .scijava .plugin .Plugin ;
4148import org .scijava .widget .Button ;
4249
43- import java .io .File ;
44- import java .io .IOException ;
45- import java .nio .file .Path ;
46- import java .nio .file .Paths ;
47- import java .util .LinkedHashMap ;
48- import java .util .Map ;
49-
5050/**
5151 * Options for configuring the Python environment.
52- *
52+ *
5353 * @author Curtis Rueden
5454 */
55- @ Plugin (type = OptionsPlugin .class , menu = {
56- @ Menu (label = MenuConstants .EDIT_LABEL ,
57- weight = MenuConstants .EDIT_WEIGHT ,
58- mnemonic = MenuConstants .EDIT_MNEMONIC ),
59- @ Menu (label = "Options" , mnemonic = 'o' ),
60- @ Menu (label = "Python..." , weight = 10 ),
61- })
55+ @ Plugin (type = OptionsPlugin .class , menu = { @ Menu (
56+ label = MenuConstants .EDIT_LABEL , weight = MenuConstants .EDIT_WEIGHT ,
57+ mnemonic = MenuConstants .EDIT_MNEMONIC ), @ Menu (label = "Options" ,
58+ mnemonic = 'o' ), @ Menu (label = "Python..." , weight = 10 ), })
6259public class OptionsPython extends OptionsPlugin {
6360
6461 @ Parameter
@@ -76,7 +73,8 @@ public class OptionsPython extends OptionsPlugin {
7673 @ Parameter (label = "Rebuild Python environment" , callback = "rebuildEnv" )
7774 private Button rebuildEnvironment ;
7875
79- @ Parameter (label = "Launch in Python mode" , callback = "updatePythonConfig" , persist = false )
76+ @ Parameter (label = "Launch in Python mode" , callback = "updatePythonConfig" ,
77+ persist = false )
8078 private boolean pythonMode ;
8179
8280 // -- OptionsPython methods --
@@ -124,28 +122,31 @@ public void load() {
124122 }
125123
126124 if (pythonDir == null ) {
127- // For the default Python directory, try to match the platform string used for Java installations.
128- final String javaPlatform = System .getProperty ("scijava.app.java-platform" );
129- final String platform = javaPlatform != null ? javaPlatform :
130- System .getProperty ("os.name" ) + "-" + System .getProperty ("os.arch" );
131- final Path pythonPath = appService .getApp ().getBaseDirectory ().toPath ().resolve ("python" ).resolve (platform );
125+ // For the default Python directory, try to match the platform
126+ // string used for Java installations.
127+ final String javaPlatform = System .getProperty (
128+ "scijava.app.java-platform" );
129+ final String platform = javaPlatform != null ? javaPlatform : System
130+ .getProperty ("os.name" ) + "-" + System .getProperty ("os.arch" );
131+ final Path pythonPath = appService .getApp ().getBaseDirectory ().toPath ()
132+ .resolve ("python" ).resolve (platform );
132133 pythonDir = pythonPath .toFile ();
133134 }
134135 }
135136
136137 public void rebuildEnv () {
137138 // Use scijava.app.python-env-file system property if present.
138139 final Path appPath = appService .getApp ().getBaseDirectory ().toPath ();
139- File environmentYaml = appPath .resolve ("config" ).resolve ("environment.yml" ).toFile ();
140- final String pythonEnvFileProp = System .getProperty ("scijava.app.python-env-file" );
140+ File environmentYaml = appPath .resolve ("config" ).resolve ("environment.yml" )
141+ .toFile ();
142+ final String pythonEnvFileProp = System .getProperty (
143+ "scijava.app.python-env-file" );
141144 if (pythonEnvFileProp != null ) {
142145 environmentYaml = OptionsPython .stringToFile (appPath , pythonEnvFileProp );
143146 }
144147
145- commandService .run (RebuildEnvironment .class , true ,
146- "environmentYaml" , environmentYaml ,
147- "targetDir" , pythonDir
148- );
148+ commandService .run (RebuildEnvironment .class , true , "environmentYaml" ,
149+ environmentYaml , "targetDir" , pythonDir );
149150 }
150151
151152 @ Override
@@ -195,8 +196,8 @@ static File stringToFile(Path baseDir, String value) {
195196 */
196197 static String fileToString (Path baseDir , File file ) {
197198 Path filePath = file .toPath ();
198- Path relPath = filePath .startsWith (baseDir ) ?
199- baseDir . relativize ( filePath ) : filePath .toAbsolutePath ();
199+ Path relPath = filePath .startsWith (baseDir ) ? baseDir . relativize ( filePath )
200+ : filePath .toAbsolutePath ();
200201 return relPath .toString ();
201202 }
202203}
0 commit comments