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