-
Notifications
You must be signed in to change notification settings - Fork 17
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
Jython 2.7 compatibility #250
base: master
Are you sure you want to change the base?
Jython 2.7 compatibility #250
Conversation
// use this import to provide a toolkit directly into the script | ||
_python.exec("from nodetoolkit import *"); | ||
|
||
if (((PyInteger) _python.eval("'nodetoolkit' in dir(__import__('sys'))")).asInt() > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's maybe a nicer way of getting a boolean back from the interpreter but AFAICT this works.
Hey @tomgilligan, nice one. I look forward to checking out what you've done and building the code. It was a very very long time ago when I think I attempted something similar as a side project. I'm trying to remember exactly what the issue was, but there was one sticking point related to ... ummm I think, callbacks (function references) and them being implemented with Weak referencing in that version of Jython. It would manifest itself as callbacks basically just going silent over a long period of time. Anyway, it'd be good for you to run with it an see how long term tests go. Oh yes, one other thing I noticed was it took MUCH longer to instantiate interpreter instances and deal with higher quantities of nodes. So test for that too i.e. node count > 50, and see how it goes verses 2.5.4. (@scroix FYI) |
Hey @tomgilligan, I was expecting more affected files than just the PyNode.java file. I thought this branch would be where Jython 2.7 itself is swapped in and gradle files would be affected, etc. Is any of that work available too? |
Sorry, I really didn't word PR very well. I was kind of thinking of this as an opt-in change because I'm not sure how it would affect existing deployments. Maybe this is something that doesn't make sense to worry about depending on how much Nodel deployments get updated once they are in production. I will change it to default to 2.7.2.
I'll try and get some testing done this week. |
I gave the binary a whirl. It looks like the toolkit is unavailable.
It looks like it is there e.g. You can manually import it, but the "injection" seems to of broken.
As opposed to standard toolkit usage.
|
There's a fix for the injection of the toolkit sitting in (tommy-gilligan#1) which I've been testing and noticed our first of presumably many issues. In Jython 2.5, if you tried to access a missing key in a java.util.LinkedHashMap object, it would return None. However, in Jython 2.7, accessing a missing key in a LinkedHashMap object will raise a KeyError exception, just like in a regular Python dictionary. from java.util import LinkedHashMap
m = LinkedHashMap()
m.put("a", 1)
print(m.get("b"))
This behaviour occurs in the Calendar recipe as it parses members ( For example, it appears that In Jython 2.5, the string representation of a LinkedHashMap object used the {key=value} format, while in Jython 2.7, the string representation uses the {'key': 'value'} format. |
Hey @scroix , that dictionary behaviour is one I've thought about for a while and would be nice to address. But as you say, it's a definite possible breaking change for existing recipes that have coding not expecting But regarding 2.7 vs 2.5, have you done any benchmarks regarding load and compile time for the same set of nodes? I started doing that but then got side-tracked. Loading / compiling times aside and a few class behaviour issues, have you noticed anything else? |
Currently Nodel runs on Jython 2.5.4-rc1. This is a bit limiting when you try to use 3rd party code in your recipe.
These changes make it possible to use Jython 2.7 instead (expanding what is possible in your recipes).
Leaving it as something to opt-in to for now: you can use Jython 2.5.4-rc1 or Jython 2.7 with these changes in place.
This means there is a bit of branching to do the right thing depending on which version of Jython you are trying to use. This is maybe not such a huge problem going forward because it doesn't look like there'll be a newer version of Jython any time soon.