diff --git a/build.gradle b/build.gradle index 1e1966c76474bac25d12f4650bfe50b797e6a202..54c56ee0bb33796efc7f372485634e352a37e750 100644 --- a/build.gradle +++ b/build.gradle @@ -76,6 +76,6 @@ task createKernelSpec(type: JavaExec) { task installKernelSpec(type: Exec) { dependsOn = [createKernelSpec] - executable = project.hasProperty("pythonInterpreter") ? project.pythonInterpreter : "python3" - args = ["-m", "jupyter", "kernelspec", "install", "--sys-prefix", "--name=prob2", KERNEL_SPEC_OUTPUT_PATH.toString()] + executable = project.hasProperty("jupyterCommand") ? project.jupyterCommand : "jupyter" + args = ["kernelspec", "install", "--sys-prefix", "--name=prob2", KERNEL_SPEC_OUTPUT_PATH.toString()] } diff --git a/src/main/java/de/prob2/jupyter/Main.java b/src/main/java/de/prob2/jupyter/Main.java index c0aa3115ebeec6b2640f184620bf04b3dea39a70..fcdc13c7c6d838a92036d7d7f03e27e3750087d4 100644 --- a/src/main/java/de/prob2/jupyter/Main.java +++ b/src/main/java/de/prob2/jupyter/Main.java @@ -124,11 +124,11 @@ public final class Main { System.out.println("Kernel spec created"); } - private static void installKernelSpec(final Path pythonInterpreter, final Path kernelSpecDir) { + private static void installKernelSpec(final String jupyterCommand, final Path kernelSpecDir) { System.out.println("Installing kernel spec..."); - System.out.println("Python interpreter: " + pythonInterpreter); + System.out.println("Jupyter command: " + jupyterCommand); System.out.println("Kernel spec directory: " + kernelSpecDir); - final ProcessBuilder pb = new ProcessBuilder(pythonInterpreter.toString(), "-m", "jupyter", "kernelspec", "install", "--sys-prefix", "--name=prob2", kernelSpecDir.toString()); + final ProcessBuilder pb = new ProcessBuilder(jupyterCommand, "kernelspec", "install", "--sys-prefix", "--name=prob2", kernelSpecDir.toString()); pb.redirectInput(ProcessBuilder.Redirect.INHERIT); pb.redirectOutput(ProcessBuilder.Redirect.INHERIT); pb.redirectError(ProcessBuilder.Redirect.INHERIT); @@ -156,14 +156,14 @@ public final class Main { System.out.println("Kernel spec installed"); } - private static void install(final Path pythonInterpreter) { + private static void install(final String jupyterCommand) { final Path jarPath = getJarPath(); final Path destPath = getDestPath(jarPath); copyJar(jarPath, destPath); try { final Path kernelSpecDir = Files.createTempDirectory("prob2kernelspec"); createKernelSpec(destPath, kernelSpecDir); - installKernelSpec(pythonInterpreter, kernelSpecDir); + installKernelSpec(jupyterCommand, kernelSpecDir); try (final Stream<Path> contents = Files.list(kernelSpecDir)) { contents.forEach(path -> { try { @@ -199,10 +199,10 @@ public final class Main { public static void main(final String[] args) throws IOException, InvalidKeyException, NoSuchAlgorithmException { if (args.length < 1 || args.length == 1 && "--help".equals(args[0])) { - System.err.println("Usage: java -jar prob2-jupyter-kernel-all.jar [--help | install PYTHONINTERPRETER | createKernelSpec KERNELSPECDIR | run CONNECTIONFILE]"); + System.err.println("Usage: java -jar prob2-jupyter-kernel-all.jar [--help | install [JUPYTER] | createKernelSpec KERNELSPECDIR | run CONNECTIONFILE]"); System.err.println("--help: Prints this information."); - System.err.println("install: Copies the kernel into the ProB home directory, and installs the kernel in the given Python interpreter."); - System.err.println("\tIf you're not sure which Python interpreter is used by your Jupyter installation, open a Python notebook and run \"import sys; print(sys.executable)\"."); + System.err.println("install: Copies the kernel into the ProB home directory, and installs the kernel in Jupyter."); + System.err.println("\tBy default the command \"jupyter\" is used to install the kernel. If the kernel should be installed in a different Jupyter installation, a different Jupyter command can be passed as an argument to the install command."); System.err.println("createKernelSpec: Creates a Jupyter kernel spec for this jar file at the given location."); System.err.println("\tThis option is for advanced users or developers, who don't want the jar file to be copied, or who want to install the kernel spec manually."); System.err.println("run: Runs the kernel using the given connection file."); @@ -211,12 +211,12 @@ public final class Main { } switch (args[0]) { case "install": - if (args.length != 2) { - System.err.println("install expects exactly one argument, not " + (args.length-1)); + if (args.length > 2) { + System.err.println("install expects at most one argument, not " + (args.length-1)); System.err.println("Use --help for more info."); throw die(2); } - install(Paths.get(args[1])); + install(args.length > 1 ? args[1] : "jupyter"); break; case "createKernelSpec":