Skip to content

Commit

Permalink
Better handle downloads
Browse files Browse the repository at this point in the history
Particularly failed ones - don't show indefinitely as pending
  • Loading branch information
petebankhead committed Nov 30, 2022
1 parent ab68e9b commit e2f6b9d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
with:
name: jar
path: build/libs
retention-days: 1
retention-days: 7
7 changes: 6 additions & 1 deletion .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ jobs:
arguments: publish -P release=true
env:
MAVEN_USER: ${{ secrets.MAVEN_USER }}
MAVEN_PASS: ${{ secrets.MAVEN_PASS }}
MAVEN_PASS: ${{ secrets.MAVEN_PASS }}
- uses: actions/upload-artifact@v3
with:
name: jar
path: build/libs
retention-days: 7
7 changes: 6 additions & 1 deletion .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ jobs:
arguments: publish
env:
MAVEN_USER: ${{ secrets.MAVEN_USER }}
MAVEN_PASS: ${{ secrets.MAVEN_PASS }}
MAVEN_PASS: ${{ secrets.MAVEN_PASS }}
- uses: actions/upload-artifact@v3
with:
name: jar
path: build/libs
retention-days: 7
56 changes: 39 additions & 17 deletions src/main/java/qupath/ext/djl/DjlEngineCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package qupath.ext.djl;

import java.io.File;
import java.nio.file.Files;
import java.util.Set;
import java.util.concurrent.Callable;
Expand Down Expand Up @@ -54,6 +55,7 @@
import qupath.lib.common.GeneralTools;
import qupath.lib.gui.QuPathGUI;
import qupath.lib.gui.dialogs.Dialogs;
import qupath.lib.gui.prefs.PathPrefs;
import qupath.lib.gui.tools.GuiTools;
import qupath.lib.gui.tools.PaneTools;

Expand Down Expand Up @@ -206,6 +208,28 @@ private void init() {
labelPathLabel.setLabelFor(labelPath);
labelPathLabel.setContentDisplay(ContentDisplay.LEFT);

var tip = new Tooltip();
status.addListener((v, o, n) -> {
if (Files.isDirectory(path)) {
tip.setText("Double-click to open engine path");
} else {
labelPath.setStyle("-fx-opacity: 0.5;");
tip.setText("Engine path does not exist");
}
});
labelPathLabel.setTooltip(tip);
labelPath.setOnMouseClicked(e -> {
if (e.getClickCount() == 2 && Files.isDirectory(path))
GuiTools.browseDirectory(path.toFile());
else
logger.debug("Cannot open {} - directory does not exist", path);
});
PaneTools.addGridRow(pane, row++, 0, null, labelPathLabel, labelPath);
PaneTools.addGridRow(pane, row++, 0, null, btnDownload, btnDownload);

PaneTools.setToExpandGridPaneWidth(labelName, labelPath, btnDownload);

// Finally, try to actually get the engine
Engine engine = null;
try {
engine = DjlTools.getEngine(name, false);
Expand All @@ -217,23 +241,6 @@ private void init() {
else {
status.set(EngineStatus.UNAVAILABLE);
}

if (Files.isDirectory(path)) {
tooltip = "Double-click to open engine path";
} else {
labelPath.setStyle("-fx-opacity: 0.5;");
tooltip = "Engine path does not exist - engine not downloaded";
}
labelPath.setOnMouseClicked(e -> {
if (e.getClickCount() == 2 && Files.isDirectory(path))
GuiTools.browseDirectory(path.toFile());
else
logger.debug("Cannot open {} - directory does not exist", path);
});
PaneTools.addGridRow(pane, row++, 0, tooltip, labelPathLabel, labelPath);
PaneTools.addGridRow(pane, row++, 0, tooltip, btnDownload, btnDownload);

PaneTools.setToExpandGridPaneWidth(labelName, labelPath, btnDownload);
}

stage = new Stage();
Expand Down Expand Up @@ -314,6 +321,21 @@ private Engine requestEngine(String name, ObjectProperty<EngineStatus> status) {
if (engine != null) {
updateStatus(status, EngineStatus.AVAILABLE);
Dialogs.showInfoNotification(TITLE, name + " is now available!");
} else {
updateStatus(status, EngineStatus.UNAVAILABLE);
// If we should have TensorFlow - but don't for some reason - then try to help
// (If we're running on a Mac, then warnings for the likely explanation have already been shown)
if (DjlTools.ENGINE_TENSORFLOW.equals(name) && DjlTools.hasEngine(DjlTools.ENGINE_TENSORFLOW) && !GeneralTools.isMac()) {
var pathConfig = PathPrefs.getConfigPath();
logger.warn("Unable to find TensorFlow - this might be a problem with the java.library.path or missing Visual Studio Redistributables.");
if (Files.exists(pathConfig)) {
logger.warn("To address a library path problem, you could try editing the config file at {}", pathConfig);
logger.warn("Update the java.library.path line to include the TensorFlow directory, e.g.");
var cachePath = Utils.getEngineCacheDir(name);
logger.warn(" java-options=-Djava.library.path=$APPDIR" + File.pathSeparator + "{}/subdirectory-for-tensorflow-version", cachePath.toString());
}
}
Dialogs.showWarningNotification(TITLE, "Unable to initialize " + name + ", sorry");
}
return engine;
} catch (EngineException e) {
Expand Down

0 comments on commit e2f6b9d

Please sign in to comment.