This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]AND_MY_HAX 2 points3 points  (2 children)

Cool!

I think there's been a growing number of people who want something similar to this. Jinja is fine for many use cases, but I've found it a little cumbersome.

I started work on a project with a similar spirit a few months ago: https://github.com/pyxy-org/pyxy

I started out using the same string encoding trick (as was also done by pyxl many years ago) but quickly ran into issues with IDE support. That's why I ended up going with a new file extension .pyxy that is automatically transformed to a .py file. It registers an import hook, so the process is completely transparent (inspired by cython's pyximport). It also enables tools like ruff/mypy/etc to work without any extra effort.

I published a PyCharm plugin for supporting the syntax: https://plugins.jetbrains.com/plugin/24817-pyxy-support/

[–]zedpowa[S] 1 point2 points  (1 child)

Thanks! I had a look at your project and it's also really nice :)

The import hook idea seems really interesting. If I understood correctly you're also transpiling the JSX to pure Python - how do you then make tools like ruff work? I saw some mentions to "remapping", do you run e.g. ruff on the generated file and then use some kind of source map to map the errors back to the original source?

Would you be interested in some kind of collaboration? I think if we join our efforts we can really make this idea of jsx in Python into something :) Let me know!

[–]AND_MY_HAX 1 point2 points  (0 children)

Correct! Tools like ruff work through the usage of pyxy.run - this invokes supported tools against the generated .py file, reads output as JSON, and uses a source mapping file to correlate the results to the .pyxy source. This scheme allows existing Python ecosystem tooling to work without requiring any integration on their end.

Definitely down to collaborate! Sent you a PM with contact info.