Skip to content

timfel/graalpy-jbang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Use GraalPy in a Java embedding with JBang

This repository makes it easy to create a JBang app that uses GraalPy & Java.

See our example graalpy.java for a template. You can use PIP comments to add packages. Native image builds should just work. Modify the main method to suit your use case, the other two classes in the file are just helpers that you should be able to ignore.

Simple example to get started

//DEPS org.graalvm.python:python-language:23.1.0
//DEPS org.graalvm.python:python-resources:23.1.0
//DEPS org.graalvm.python:python-launcher:23.1.0
//DEPS https://github.com/timfel/graalpy-jbang/tree/main#:SNAPSHOT
//PIP termcolor
public class graalpy {
public static void main(String[] args) {
try (Context context = VirtualGraalPyContext.getContext()) {
switch (args.length) {
case 0:
context.eval("python", "import site; site._script()");
break;
case 1:
context.eval("python", args[0]);
break;
default:
throw new IllegalArgumentException("The main() helper only takes 0-1 arguments.");
}
} catch (PolyglotException e) {
if (e.isExit()) {
System.exit(e.getExitStatus());
} else {
throw e;
}
}
}
}

More interesting example "application"

JBang❤️Pygal

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Languages