Subscribe on changes!

Support py-script

avatar
May 3rd 2022

What problem does this feature solve?

py-script has been recently announced to work in the browser. See https://pyscript.net

I would like to propose to support tags inside Vue SFCs. It already works by setting the compilerOptions.isCustomElement. However, the Python syntax is sensitive to indentation.

As far as I can tell, the Vue compiler doesn't respect this (which is obvious for HTML).

What does the proposed API look like?

For instance, these two lines generates a SyntaxError: invalid syntax:

<py-script>
from astropy import time
print(time.Time('2451545', format='jd'))
</py-script>
avatar
May 3rd 2022

I don't see a valid use case for this, and you didn't provide one. I don'T think we should invest any resources in supporting this as it's a niche technology right now.

avatar
May 3rd 2022

I agree that I didn't provide any use case. And mine is probably small, I agree too. However, I don't think it is a niche technology. Given the activity in the academic community (and even outside), there will be IMHO a lot of Python people wanting to create scientific websites using their python code.

Being able to integrate sophisticated existing python code (even based on powerful libraries like numpy or pandas) inside Vue SFCs would be truly awesome, and opens a lot of possibilities for scientific websites.

That's the main reason for the absence of use case: there are too many possible. Moreover, the only suggestion I wanted to make was to respect the indentation inside these special tags. I have no idea how difficult it is, however.

avatar
May 4th 2022

I do agree to have this possibility would be just awesome, I love Vue and I love python, I tolerate JS, but just the idea of using python with Vue is exciting, it's a paradigm shift level idea, that will bring with it a huge mature community

avatar
May 6th 2022

Sorry but this is not something that Vue will support. Loading a 200kb file + interpreting python at runtime comes with huge performance overhead and you probably don't want to actually use it in anything but toy / personal projects.

The cost of supporting it requires the Vue compiler to be able to analyze python AST and replicate all current SFC script/template coupling logic for python, which is a lot of work for toy use cases. If someone wants to work on this a hobby, it could probably be done via custom block API of SFCs. I just don't see this happening in core.

avatar
May 6th 2022

Thanks @yyx990803 for your useful comment! Indeed Vue core may not be the place where to consider this integration. I will continue to investigate following the link you provide.

P.S. As you certainly know, personal projets can go a long way...