-
Notifications
You must be signed in to change notification settings - Fork 90
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
Convert python interface to jinja2 #2351
Conversation
This is nice, thanks! I wonder if we can go even further though and try to move as much code out of the generation loops as possible? For example, the different extension classes for the There's also places with loops that could be done in Python, e.g. : def _setmembers(self):
{% for f in "dx", "dy", "J", "Bxy", "g11", "g22", "g33", "g12", "g13", "g23", "g_11", "g_22", "g_33", "g_12", "g_13", "g_23", "G1_11", "G1_22", "G1_33", "G1_12", "G1_13", "G1_23", "G2_11", "G2_22", "G2_33", "G2_12", "G2_13", "G2_23", "G3_11", "G3_22", "G3_33", "G3_12", "G3_13", "G3_23", "G1", "G2", "G3", "ShiftTorsion", "IntShiftTorsion" %}
self.{{f}} = f2dFromPtr(&self.cobj.{{f}})
{% endfor %} could be something like def _setmembers(self):
for f in ["dx", "dy", "J", "Bxy", "g11", "g22", "g33", "g12", "g13", "g23", "g_11", "g_22", "g_33", "g_12", "g_13", "g_23", "G1_11", "G1_22", "G1_33", "G1_12", "G1_13", "G1_23", "G2_11", "G2_22", "G2_33", "G2_12", "G2_13", "G2_23", "G3_11", "G3_22", "G3_33", "G3_12", "G3_13", "G3_23", "G1", "G2", "G3", "ShiftTorsion", "IntShiftTorsion"]:
setattr(self, f) = f2dFromPtr(&getattr(self.cobj, f)) That's maybe not such a great example -- I'm not sure how the Cython syntax interacts with the Python there. The next step would be to pull out all the non-jinja parts into separate modules, so that they're even easier to work with. |
The Fields are But yes, I think splitting up the files, would already be nice, and then some parts wouldn't have to be jinja anyway. |
I don't see the advantage. I would rather have everything defined in one place. If black could handle plain |
3D fixes for the python interface
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.
Awesome, LGTM! The build is also now much less noisy, though I still see a couple of warnings:
[142/147] Cythonizing python interface
warning: resolve_enum.pxd:49:21: 'deflt' redeclared
warning: resolve_enum.pxd:189:24: 'Standard' redeclared
warning: resolve_enum.pxd:223:15: 'Standard' redeclared
It seems the namespace argument is not working as I hoped:
Looking at the generated C++ code, it seems all good, and the correct type is used:
I am thus inclined to just ignore it. Especially as the It might make sense to change If you think this is an issue I can open an issue with Cython, but I am inclined to ignore the warning. |
It would definitely be nice to not have the warnings, but we still have a bunch of other warnings to fix too. |
Should make it easier to work with the code.