Skip to content

Commit 8d6b65a

Browse files
initial creation of conda-based python scripting repo
0 parents  commit 8d6b65a

File tree

7 files changed

+355
-0
lines changed

7 files changed

+355
-0
lines changed

LICENSE.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Copyright (c) 2014 - 2021, SciJava developers.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without modification,
5+
are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
2. Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24+
POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Python Scripting
2+
3+
Test repository for a [PyImageJ](https://github.com/imagej/pyimagej) based SciJava scripting language engine.

pom.xml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.scijava</groupId>
7+
<artifactId>pom-scijava</artifactId>
8+
<version>31.1.0</version>
9+
<relativePath />
10+
</parent>
11+
12+
<artifactId>scripting-python</artifactId>
13+
<version>0.1-SNAPSHOT</version>
14+
15+
<name>SciJava Scripting: Python</name>
16+
<description>Python scripting language plugin to be used with a conda environment.</description>
17+
<url>https://github.com/scijava/scripting-python</url>
18+
<inceptionYear>2021</inceptionYear>
19+
<organization>
20+
<name>SciJava</name>
21+
<url>https://scijava.org/</url>
22+
</organization>
23+
<licenses>
24+
<license>
25+
<name>Simplified BSD License</name>
26+
<distribution>repo</distribution>
27+
</license>
28+
</licenses>
29+
30+
<developers>
31+
<developer>
32+
<id>ctrueden</id>
33+
<name>Curtis Rueden</name>
34+
<url>https://imagej.net/User:Rueden</url>
35+
<roles>
36+
<role>founder</role>
37+
<role>lead</role>
38+
<role>developer</role>
39+
<role>debugger</role>
40+
<role>reviewer</role>
41+
<role>support</role>
42+
<role>maintainer</role>
43+
</roles>
44+
</developer>
45+
</developers>
46+
<contributors>
47+
<contributor>
48+
<name>Karl Duderstadt</name>
49+
<url>https://imagej.net/people/karlduderstadt</url>
50+
<properties><id>karlduderstadt</id></properties>
51+
</contributor>
52+
</contributors>
53+
54+
<mailingLists>
55+
<mailingList>
56+
<name>SciJava</name>
57+
<subscribe>https://groups.google.com/group/scijava</subscribe>
58+
<unsubscribe>https://groups.google.com/group/scijava</unsubscribe>
59+
<post>scijava@googlegroups.com</post>
60+
<archive>https://groups.google.com/group/scijava</archive>
61+
</mailingList>
62+
</mailingLists>
63+
64+
<scm>
65+
<connection>scm:git:https://github.com/scijava/scripting-python</connection>
66+
<developerConnection>scm:git:git@github.com:scijava/scripting-python</developerConnection>
67+
<tag>HEAD</tag>
68+
<url>https://github.com/scijava/scripting-python</url>
69+
</scm>
70+
<issueManagement>
71+
<system>GitHub Issues</system>
72+
<url>https://github.com/scijava/scripting-python/issues</url>
73+
</issueManagement>
74+
<ciManagement>
75+
<system>GitHub Actions</system>
76+
<url>https://github.com/scijava/scripting-python/actions</url>
77+
</ciManagement>
78+
79+
<properties>
80+
<package-name>org.scijava.plugins.scripting.python</package-name>
81+
<main-class>org.scijava.plugins.scripting.python.Main</main-class>
82+
83+
<license.licenseName>bsd_2</license.licenseName>
84+
<license.copyrightOwners>SciJava developers.</license.copyrightOwners>
85+
<license.excludes>**/script_templates/**</license.excludes>
86+
87+
<!-- NB: Deploy releases to the SciJava Maven repository. -->
88+
<releaseProfiles>sign,deploy-to-scijava</releaseProfiles>
89+
</properties>
90+
91+
<dependencies>
92+
<!-- SciJava dependencies -->
93+
<dependency>
94+
<groupId>org.scijava</groupId>
95+
<artifactId>scijava-common</artifactId>
96+
</dependency>
97+
98+
<!-- Third-party dependencies -->
99+
100+
<!-- Test dependencies -->
101+
<dependency>
102+
<groupId>junit</groupId>
103+
<artifactId>junit</artifactId>
104+
<scope>test</scope>
105+
</dependency>
106+
<dependency>
107+
<groupId>org.scijava</groupId>
108+
<artifactId>scijava-common</artifactId>
109+
<classifier>tests</classifier>
110+
<scope>test</scope>
111+
</dependency>
112+
</dependencies>
113+
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*-
2+
* #%L
3+
* JSR-223-compliant Groovy scripting language plugin.
4+
* %%
5+
* Copyright (C) 2014 - 2021 SciJava developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
package org.scijava.plugins.scripting.python;
30+
31+
import org.scijava.script.ScriptREPL;
32+
33+
public class Main {
34+
35+
public static void main(String... args) throws Exception {
36+
ScriptREPL.main(args);
37+
}
38+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* #%L
3+
* JSR-223-compliant Groovy scripting language plugin.
4+
* %%
5+
* Copyright (C) 2014 - 2021 SciJava developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
30+
package org.scijava.plugins.scripting.python;
31+
32+
import javax.script.ScriptException;
33+
import org.scijava.script.AbstractScriptEngine;
34+
import org.scijava.plugins.scripting.python.PythonScriptRunner;
35+
36+
/**
37+
* A script engine for conda-based python.
38+
*
39+
* @author Curtis Rueden
40+
* @author Karl Duderstadt
41+
* @see ScriptEngine
42+
*/
43+
public class PythonScriptEngine extends AbstractScriptEngine {
44+
45+
@Parameter
46+
ObjectService objectService;
47+
48+
public PythonScriptEngine(Context context) {
49+
context.inject(this);
50+
}
51+
52+
@Override
53+
public Object eval(String script) throws ScriptException {
54+
Map<String, Object> vars;
55+
//parse script parameters and build input map Map<String, Object> vars
56+
57+
return objectService.getObjects(PythonScriptRunner.class).stream().findAny().get().run(script, vars);
58+
}
59+
60+
@Override
61+
public Object eval(Reader reader) throws ScriptException {
62+
StringBuilder buf = new StringBuilder();
63+
char [] cbuf = new char [65536];
64+
while (true) {
65+
try {
66+
int nChars = reader.read(cbuf);
67+
if (nChars <= 0) break;
68+
buf.append(cbuf, 0, nChars);
69+
} catch (IOException e) {
70+
throw new ScriptException(e);
71+
}
72+
}
73+
return eval(buf.toString());
74+
}
75+
76+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* #%L
3+
* JSR-223-compliant Groovy scripting language plugin.
4+
* %%
5+
* Copyright (C) 2014 - 2021 SciJava developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
30+
package org.scijava.plugins.scripting.python;
31+
32+
import java.security.CodeSource;
33+
34+
import javax.script.CompiledScript;
35+
import javax.script.ScriptContext;
36+
import javax.script.ScriptEngine;
37+
import javax.script.ScriptException;
38+
39+
import org.scijava.Priority;
40+
import org.scijava.plugin.Plugin;
41+
import org.scijava.script.AdaptedScriptLanguage;
42+
import org.scijava.script.ScriptLanguage;
43+
import org.scijava.util.ClassUtils;
44+
import org.scijava.util.Types;
45+
46+
/**
47+
* An adapter for conda-based python to the SciJava scripting interface.
48+
*
49+
* @author Curtis Rueden
50+
* @author Karl Duderstadt
51+
* @see ScriptEngine
52+
*/
53+
@Plugin(type = ScriptLanguage.class, name = "Python 3", priority = Priority.HIGH)
54+
public class PythonScriptLanguage extends AdaptedScriptLanguage {
55+
56+
@Override
57+
public ScriptEngine getScriptEngine() {
58+
return new PythonScriptEngine(getContext());
59+
}
60+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* #%L
3+
* JSR-223-compliant Groovy scripting language plugin.
4+
* %%
5+
* Copyright (C) 2014 - 2021 SciJava developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
30+
package org.scijava.plugins.scripting.python;
31+
32+
/**
33+
* Interface for conda-based python script running implementations.
34+
*
35+
* @author Curtis Rueden
36+
* @author Karl Duderstadt
37+
* @see ScriptEngine
38+
*/
39+
public interface PythonScriptRunner {
40+
Object run(String script, Map<String, Object> vars);
41+
}

0 commit comments

Comments
 (0)