Skip to content

Commit 6427cde

Browse files
committed
Format code with mvn formatter:format
1 parent 6d9b831 commit 6427cde

File tree

6 files changed

+74
-66
lines changed

6 files changed

+74
-66
lines changed

src/main/java/org/scijava/plugins/scripting/python/Main.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
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
@@ -26,6 +26,7 @@
2626
* POSSIBILITY OF SUCH DAMAGE.
2727
* #L%
2828
*/
29+
2930
package org.scijava.plugins.scripting.python;
3031

3132
import org.scijava.script.ScriptREPL;

src/main/java/org/scijava/plugins/scripting/python/OptionsPython.java

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
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
@@ -29,6 +29,13 @@
2929

3030
package 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+
3239
import org.scijava.app.AppService;
3340
import org.scijava.command.CommandService;
3441
import org.scijava.launcher.Config;
@@ -40,25 +47,15 @@
4047
import org.scijava.plugin.Plugin;
4148
import 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), })
6259
public 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
}

src/main/java/org/scijava/plugins/scripting/python/PythonScriptEngine.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
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
@@ -61,10 +61,10 @@ public class PythonScriptEngine extends AbstractScriptEngine {
6161

6262
@Parameter
6363
private ObjectService objectService;
64-
64+
6565
@Parameter
6666
private LogService logService;
67-
67+
6868
public PythonScriptEngine(final Context context) {
6969
context.inject(this);
7070
setLogService(logService);
@@ -83,19 +83,21 @@ public Object eval(final String script) throws ScriptException {
8383
"Python script engine, you must call scyjava.enable_scijava_scripting(context)\n" +
8484
"with this script engine's associated SciJava context before using it.");
8585
}
86-
return pythonScriptRunner.get().apply(new Args(script, engineScopeBindings, scriptContext));
86+
return pythonScriptRunner.get().apply(new Args(script, engineScopeBindings,
87+
scriptContext));
8788
}
8889

8990
@Override
9091
public Object eval(Reader reader) throws ScriptException {
9192
StringBuilder buf = new StringBuilder();
92-
char [] cbuf = new char [65536];
93+
char[] cbuf = new char[65536];
9394
while (true) {
9495
try {
9596
int nChars = reader.read(cbuf);
9697
if (nChars <= 0) break;
9798
buf.append(cbuf, 0, nChars);
98-
} catch (IOException e) {
99+
}
100+
catch (IOException e) {
99101
throw new ScriptException(e);
100102
}
101103
}
@@ -106,8 +108,8 @@ public Object eval(Reader reader) throws ScriptException {
106108
public Bindings createBindings() {
107109
return new ScriptBindings();
108110
}
109-
110-
//Somehow just type casting did not work...
111+
112+
// Somehow just type casting did not work...
111113
private static class ScriptBindings implements Bindings {
112114

113115
private Map<String, Object> bindingsMap;
@@ -178,11 +180,14 @@ public Object remove(Object key) {
178180
}
179181

180182
private static class Args {
183+
181184
public final String script;
182185
public final Map<String, Object> vars;
183186
public final ScriptContext scriptContext;
184187

185-
public Args(final String script, final Map<String, Object> vars, final ScriptContext scriptContext) {
188+
public Args(final String script, final Map<String, Object> vars,
189+
final ScriptContext scriptContext)
190+
{
186191
this.script = script;
187192
this.vars = vars;
188193
this.scriptContext = scriptContext;

src/main/java/org/scijava/plugins/scripting/python/PythonScriptLanguage.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
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
@@ -46,7 +46,8 @@
4646
* @author Karl Duderstadt
4747
* @see ScriptEngine
4848
*/
49-
@Plugin(type = ScriptLanguage.class, name = "Python (pyimagej)", priority = Priority.VERY_LOW)
49+
@Plugin(type = ScriptLanguage.class, name = "Python (pyimagej)",
50+
priority = Priority.VERY_LOW)
5051
public class PythonScriptLanguage extends AbstractScriptLanguage {
5152

5253
@Override
@@ -63,5 +64,5 @@ public List<String> getExtensions() {
6364
public ScriptEngine getScriptEngine() {
6465
return new PythonScriptEngine(getContext());
6566
}
66-
67+
6768
}

src/main/java/org/scijava/plugins/scripting/python/PythonScriptSyntaxHighlighter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
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
@@ -40,7 +40,7 @@
4040
*/
4141
@Plugin(type = SyntaxHighlighter.class, name = "python-(pyimagej)")
4242
public class PythonScriptSyntaxHighlighter extends PythonTokenMaker implements
43-
SyntaxHighlighter
43+
SyntaxHighlighter
4444
{
4545
// Everything implemented in PythonTokenMaker
4646
}

src/main/java/org/scijava/plugins/scripting/python/RebuildEnvironment.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
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
@@ -29,6 +29,13 @@
2929

3030
package org.scijava.plugins.scripting.python;
3131

32+
import java.io.File;
33+
import java.io.IOException;
34+
import java.nio.file.Files;
35+
import java.nio.file.Path;
36+
import java.util.Comparator;
37+
import java.util.stream.Stream;
38+
3239
import org.apposed.appose.Appose;
3340
import org.apposed.appose.Builder;
3441
import org.scijava.app.AppService;
@@ -38,16 +45,9 @@
3845
import org.scijava.plugin.Parameter;
3946
import org.scijava.plugin.Plugin;
4047

41-
import java.io.File;
42-
import java.io.IOException;
43-
import java.nio.file.Files;
44-
import java.nio.file.Path;
45-
import java.util.Comparator;
46-
import java.util.stream.Stream;
47-
4848
/**
4949
* SciJava command wrapper to build a Python environment.
50-
*
50+
*
5151
* @author Curtis Rueden
5252
*/
5353
@Plugin(type = Command.class, label = "Rebuild Python environment")
@@ -90,12 +90,12 @@ public void run() {
9090
if (targetDir.exists()) targetDir.renameTo(backupDir);
9191
// Build the new environment.
9292
try {
93-
Builder builder = Appose
94-
.file(environmentYaml, "environment.yml")
95-
.subscribeOutput(this::report)
96-
.subscribeError(this::report)
97-
.subscribeProgress((msg, cur, max) -> Splash.update(msg, (double) cur / max));
98-
System.err.println("Building Python environment"); // HACK: stderr stream triggers console window show.
93+
Builder builder = Appose.file(environmentYaml, "environment.yml")
94+
.subscribeOutput(this::report).subscribeError(this::report)
95+
.subscribeProgress((msg, cur, max) -> Splash.update(msg, (double) cur /
96+
max));
97+
System.err.println("Building Python environment");
98+
// HACK: stderr stream triggers console window show.
9999
Splash.show();
100100
builder.build(targetDir);
101101
}

0 commit comments

Comments
 (0)