Skip to content

Commit 95c1a41

Browse files
committed
Notify when attempting to overwrite active python
User is now notified if we are in python mode and try to build environment when targeting our active python directory. See related Fiji commit: fiji/fiji@f492fcb
1 parent ac9557d commit 95c1a41

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,24 @@ public class RebuildEnvironment implements Command {
7575
@Override
7676
public void run() {
7777
final File backupDir = new File(targetDir.getPath() + ".old");
78+
// Prevent rebuilding the environment currently in use by pyimagej
7879
if (targetDir.exists()) {
80+
String cfgPythonDir = System.getProperty("scijava.python.dir", "");
81+
if (cfgPythonDir != null && !cfgPythonDir.isEmpty()) {
82+
// Normalize both paths for comparison
83+
String targetPath = targetDir.getAbsolutePath().replace("\\", "/");
84+
String cfgPath = cfgPythonDir.replace("\\", "/");
85+
if (targetPath.endsWith(cfgPath)) {
86+
String msg = "You cannot rebuild the environment currently being used by pyimagej (" + cfgPythonDir + ").\n" +
87+
"Please select a different target directory, or restart in Java mode.";
88+
if (uiService != null) {
89+
uiService.showDialog(msg, "Cannot Rebuild Active Environment", DialogPrompt.MessageType.ERROR_MESSAGE);
90+
} else {
91+
log.error(msg);
92+
}
93+
return;
94+
}
95+
}
7996
boolean confirmed = true;
8097
if (uiService != null) {
8198
String msg =

0 commit comments

Comments
 (0)