Skip to content

Commit 4aeeca4

Browse files
committed
Add a script for launching SciJava REPL via Python
1 parent cb3ec00 commit 4aeeca4

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

repl.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/sh
2+
set -e
3+
cd "$(dirname "$0")"
4+
python -c '
5+
import os.path
6+
import xml.etree.ElementTree as ET
7+
import scyjava
8+
import subprocess
9+
from pathlib import Path
10+
11+
def exec(cmd):
12+
try:
13+
args = cmd.split(" ")
14+
subprocess.check_output(cmd.split(" "))
15+
except subprocess.CalledProcessError as e:
16+
print("== OPERATION FAILED ==")
17+
print(e.stdout.decode())
18+
print(e.stderr.decode())
19+
raise e
20+
21+
pom = ET.parse("pom.xml")
22+
artifactId = pom.find("{http://maven.apache.org/POM/4.0.0}artifactId").text
23+
version = pom.find("{http://maven.apache.org/POM/4.0.0}version").text
24+
jar = Path(f"target/{artifactId}-{version}.jar")
25+
if not jar.exists():
26+
print("Building JAR file...")
27+
exec("mvn -Denforcer.skip -Dmaven.test.skip clean package")
28+
deps_dir = Path("target/dependency")
29+
if not deps_dir.exists():
30+
print("Copying dependencies...")
31+
exec("mvn -DincludeScope=runtime dependency:copy-dependencies")
32+
33+
scyjava.config.add_option("-Djava.awt.headless=true")
34+
scyjava.config.add_classpath(jar.absolute())
35+
deps = scyjava.config.find_jars(deps_dir.absolute())
36+
scyjava.config.add_classpath(*deps)
37+
Context = scyjava.jimport("org.scijava.Context")
38+
context = Context(False)
39+
print(f"Context created with {context.getServiceIndex().size()} services.")
40+
scyjava.enable_python_scripting(context)
41+
ScriptREPL = scyjava.jimport("org.scijava.script.ScriptREPL")
42+
repl = ScriptREPL(context, "Python")
43+
repl.loop()
44+
context.dispose()
45+
'

0 commit comments

Comments
 (0)