Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for embedding #516

Closed
9 tasks
Thrameos opened this issue Jul 23, 2019 · 1 comment
Closed
9 tasks

Support for embedding #516

Thrameos opened this issue Jul 23, 2019 · 1 comment
Assignees
Labels
enhancement Improvement in capability planned for future release
Projects

Comments

@Thrameos
Copy link
Contributor

I gave a shot at embedding JPype in a host JVM. The pattern for this was actually pretty easy. The good news is we already have 95% of the machinery required to make it work, so the delta from a Python host running an embedded Java to a Java host running an embedded Python is actually very small. I also poked at some of the existing embedded solutions such as jep. They are missing some of the finer points of interacting between Java like lifetime control and utf encoding, etc, so moving JPype in this direction will actually be a worthy improvement.

We just need to identify the location of the Python shared library from an external copy of the JPype jar. Then we add a few symbols to the shared library so that Java can successfully name bind. Drop in the routine to start CPython (with a PYTHONHOME set), call the JPype module init and we have an embedded copy of Python to bridge to.

Based on the preliminary work, here are the tasks required to complete it.

  • Wrap the object protocol in a Java object.
  • Set up the converse from a raw Python object to Java as a explicit conversion.
  • Complete a round trip with Python object.
  • Come up with a scheme to keep the JPype jar separated from the shared library (install scripts and bootloader)
  • Come up with a scheme to find the embedded info with the dll, (version of CPython, default location of home, name of JPype shared library).
  • Define a start up routine for the JPype module from within embedded.
  • Disable functions that do not apply in embedded context (startJVM, shutdownJVM)
  • Register our ScriptEngine with Java.
  • Add a test suite for embedded Python from Java.

Several of these tasks were already in the plans, so the delta for this feature is modest. Most of the work is going to be in the bootloader and test suite.

The one big difficulty is that if we are providing both directions to the bridge we end up in a very odd place in terms of our packaging system. When embedding Java we would need to look like a Python package for an installer for Pypi. But if we are providing embedded Python we would be best to look like a maven repo. I don't see how we can accomplish looking like both easily and maven is so picky about how it works in terms of structure it would force reorganization which we really do not want to do.

@Thrameos Thrameos self-assigned this Jul 23, 2019
@Thrameos Thrameos added this to To do in JPype 1.0 via automation Jul 23, 2019
@Thrameos Thrameos added the enhancement Improvement in capability planned for future release label Jul 23, 2019
@Thrameos
Copy link
Contributor Author

Closed due to JVM limitations. Will give another shot at this later.

JPype 1.0 automation moved this from To do to Done Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement in capability planned for future release
Projects
No open projects
JPype 1.0
  
Done
Development

No branches or pull requests

1 participant