packed
packed copied to clipboard
Investigate providing codec for automatic syntax translation
As suggested in the /u/malinoff's reddit comment:
Decorators are good, and -m is useful, but sometimes I don't want to wrap every single function in your decorator. I think it would be useful to also provide custom codec - so your preprocessor will do the job on import time without any decorators (it should also work on module scope, not only on something that can be decorated). Here is an example of mypy custom codec: https://github.com/JukkaL/mypy/tree/master/mypy/codec
This should allow for using the syntax in a normal .py file and having the translation done on import so there is no need for separate .pyx and .py files and a compilation step.
Another way would be to use an import hook (eliminates the need for compilation step but you still keep separate extension, which imho is a good thing).
Cheers for the suggestion. I've used import hooks before but not in this way. Do you have any examples of it being used like that? I also wonder about how usable import hooks are. The codec thing seems pretty ideal but maybe the separate extension is a good thing.
PEP302 is a good source of information about import hooks. They don't have any hooks for implementing custom module types - it was meant mostly for zip imports (path hooks) and module freezing (meta hooks). But it's possible to implement this with meta hook, it'll just require some additional code for finding modules (I think hook will probably have to handle compilation to bytecode too).
The py.test assertion rewriter might help with ideas
Cheers for the suggestions. Much appreciated. I'll have to find some time to look into it.
Seems that dropbox has something similar and they went with custom codec: https://github.com/dropbox/pyxl
Ah, I'd forgotten that it all came from XHP. I had previously searched for 'JSX & Python' to see if it had been done before but not XHP. It seems there is another project as well: https://github.com/candu/xhpy
This project is possibly completely unnecessary :) Though still fun to have done.
Thanks for sharing it.
I like packed better. It's more sane. Naming classes like :ui:foo(:x:element) or x_my_custom_element is crazy.
Sorry for the slow response.
To clarify, you prefer do you prefer packed over dropbox's pxyl? I'd agree that xhpy looks a little too much for me but pyxl looks quite reasonable. This project isn't a high priority but whenever I return to Django templates from React components I find myself really wanting something like this. I'm tempted to play around with pxyl as it seems fairly similar and is probably well tested and more secure.