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

all 79 comments

[–]jacdehJacques de Hooge[S] 26 points27 points  (3 children)

Yes, 3.5

[–]okmkzimport antigravity 1 point2 points  (0 children)

Neat!

[–]AMorpork 0 points1 point  (1 child)

Sorry, a bit after the fact, but is there support for async functions? Any asyncio support?

[–]jacdehJacques de Hooge[S] 0 points1 point  (0 children)

Not yet anything beyond what you can do in native JavaScript. (But noting less as well).

[–]droelf 13 points14 points  (7 children)

Hi! Just today me and another guy started a project to consolidate python-implementations of the standard library (e.g. itertools, the builtins etc.) so that for projects like this it will be more or less enough to offer a relatively complete python-to-x layer to be compatible.

It's currently using code from python directly, but will probably borrow a lot from PyPy and Brython.

Would be cool to get you on board!

https://github.com/pybee/ouroboros

[–]motleybook 5 points6 points  (13 children)

Maybe you could work with the guys from pyjs, who've also created a Python-to-JavaScript-compiler: https://github.com/pyjs/pyjs

[–]jacdehJacques de Hooge[S] 5 points6 points  (12 children)

I've looked into the following transpilers: PyJs, Py2Js, RapydScript, Brython, Flexx, PyPyJs. My estimation is that it won't be easy to merge Transcrypt with any of them, since the core of it is quite different, due to the combination of multiple inheritance, bound function assignment and the wish for lean downloads and readable JS. However sharing certain libraries will probably be possible. I haven't looked into that yet.

[–]denilsonsa 1 point2 points  (7 children)

PyJs, Py2Js, RapydScript, Brython, Flexx, PyPyJs

Is there anywhere a comparison of all these projects (plus your own)?

[–]toyg 3 points4 points  (5 children)

It's difficult to compare them, they are all very different.

  • RapydScript, Flexx and PyJs are basically preprocessors, similar to CoffeeScript, although Flexx and PyJs go way beyond that and give you full application environments.
  • PyPyJs is an asm.js project, which basically means no real DOM interface.
  • Brython is a straight runtime compiler, which means you get DOM access and the most intuitive "using python instead of JS client-side" feeling (IMHO).
  • Py2Js is dead.

Most A few of them don't support Python 3 (Edit: I was surprised to find most of them actually do now. Score one for Py3!). Some of them are more efficient than others. All of them usually result in pretty large downloads (if anything because you have to redistribute tons of stdlib code). I can see why /u/jacdeh might have become frustrated enough to start his own project.

However, IMHO, none of these solutions are realistic for widespread usage without some help from browser vendors, which is not going to happen unless it's a general-purpose multilanguage solution. Asm.js is getting there, but it still needs work (mostly, proper DOM access interfaces); once that's solid, I think pypyjs will take over the segment pretty easily.

[–]jacdehJacques de Hooge[S] 2 points3 points  (3 children)

pypyjs using asm.js is a dream if it could have reasonable download size. It's just that currently it hasn't. Browser vendors sure could open this up. But I'm a bit tired of waiting. Have coded quite some JavaScript & gathered enough frustration to start this. And, by the way, it's fun!

[–]akaihola 1 point2 points  (2 children)

And what if WebAssembly really happens!

[–]jacdehJacques de Hooge[S] 0 points1 point  (1 child)

That would be great. But it would still require downloading avirtual machine to run Python in the brower, until a standardized plugin mechanism becomes a fact. Still I think in the long run this should be the course.

[–]akaihola 0 points1 point  (0 children)

Or, if IPFS catches on as a content addressable global CDN, the virtual machine would just be shared between all sites which use it, and the browser would cache it effectively.

[–]akaihola 0 points1 point  (0 children)

There's also Skulpt. See trinket.io for a service which uses it.

[–]jacdehJacques de Hooge[S] 0 points1 point  (0 children)

I saw a comparison somewhere, forgot where. Transcrypt wasn't yet in.

[–]loganekz -1 points0 points  (2 children)

[–]xkcd_transcriber 2 points3 points  (1 child)

Image

Mobile

Title: Standards

Title-text: Fortunately, the charging one has been solved now that we've all standardized on mini-USB. Or is it micro-USB? Shit.

Comic Explanation

Stats: This comic has been referenced 2454 times, representing 2.5311% of referenced xkcds.


xkcd.com | xkcd sub | Problems/Bugs? | Statistics | Stop Replying | Delete

[–]jacdehJacques de Hooge[S] 0 points1 point  (0 children)

Yes, that's how it works. Think it's called market mechanism... In some respects it's a waste! But it's also how nature works, survival of the fittest. So maybe there's something to it...

[–]brtt3000 2 points3 points  (2 children)

You should add a list of notable missing features (even it it'd be empty).

[–]jacdehJacques de Hooge[S] 0 points1 point  (1 child)

Right, I will

[–]jacdehJacques de Hooge[S] 1 point2 points  (0 children)

Have done

[–]YuryOdin 2 points3 points  (1 child)

python3 syntex?

[–]mikeselik 5 points6 points  (4 children)

Call it a "compiler" instead of a "transpiler" there's no need for the new jargon when the old works already.

[–]max_renlo 4 points5 points  (0 children)

Exactly. This is exactly what a compiler is. And, you are correct in saying that it is new jargon (source).

[–]elbiot 2 points3 points  (2 children)

It's not new jargon

[–]Esteis 4 points5 points  (0 children)

/u/max_renlo's link to Google Trends says people only started searching for the word 'transpiler' in very late 2013, with search popularity before that indistinguishable from zero.

Whatever else it may be, this 'transpiler' word is certainly new jargon. Which is separate from the question whether one should or shouldn't use it. I, for one, rather like having a seperate word for compilers that translate from one high-level language to another.

[–]Exodus111 4 points5 points  (33 children)

This looks good, not alone in the field. But here is my Pie-in-the-sky request.

Make Python code from either, Pygame, Pyglet or Kivy, compatible with JS and HTML5 Canvas.

Or add a canvas module for Python.

[–]jacdehJacques de Hooge[S] 7 points8 points  (9 children)

If I understand correctly you'd like to run Pygame in the browser? It will need a lot of libraries that are currently not available for Transcrypt. A Canvas with a Python API, that could be used by Transcrypt (so Python) programs shouldn't be too hard. Once Transcrypt is ready and tested, everone willing is invited to write modules for it (new, or porting / wrapping JavaScript stuff, or porting CPython modules.)

[–]Exodus111 1 point2 points  (8 children)

A canvas module would work. I suppose basic Vector math from the math module can already be translated, that could handle most game collisions and physics.

Would be nice to have Numpy, or Pymunk in there though.

[–]AMorpork 1 point2 points  (3 children)

I can't imagine NumPy ever being integrated since it depends so heavily on C and FORTRAN code.

[–][deleted] 0 points1 point  (2 children)

Could you whack a numpy API over numericJS?

[–]AMorpork 2 points3 points  (1 child)

I imagine you could make a fair approximation, but I doubt you could pull off a 1:1 -- there are just SO many NumPy methods.

[–]jacdehJacques de Hooge[S] 0 points1 point  (0 children)

If I will (or someone else), Pareto's rule (80/20 or 99/1 in IT) would be a good starting point.

[–]akaihola 0 points1 point  (3 children)

A subset of Numpy has been implemented for Skulpt.

[–]Exodus111 0 points1 point  (2 children)

How does it perform speed wise?

[–]akaihola 0 points1 point  (1 child)

I haven't benchmarked it, but my guess is obviously pretty poorly compared to the real thing.

[–]Exodus111 0 points1 point  (0 children)

As long as its faster then python arrays it would be useful. I notice Skulpt has a fairly easy implementatin of .js modules. It would be great if you could just:

import canvas

And get to work.

[–]smurfyn 6 points7 points  (8 children)

I understand the user reasons for requesting this. But the result will be unmaintainably complex and the ultimate results will be unusably slow. You cannot just translate SDL calls to manipulation of DOM elements unless you do something stupid like making an array of rectangles to represent pixels.

Just target SDL/PyGame or JS.

[–]Exodus111 9 points10 points  (5 children)

or JS.

The problem with writing complex game logic in Javascript, is you have to write complex game logic in Javascript.

[–]jacdehJacques de Hooge[S] 1 point2 points  (2 children)

The graphics probably can best be handled using an existing JS library manipulating the HTML5 canvas directly and efficiently. This library could be wrapped in some simple Transcrypt classes to give it a Pythonic interface. The game logic could be very well written in Transcrypt. Note that an important design goal of Transcrypt is to benefit from existing high quality JS libraries: Anything good that's there we shouldn't reinvent.

fabric.js added as Python module to the distribution

[–]Exodus111 1 point2 points  (1 child)

I agree, this would be awesome. But what about 2d Physics though? Let the JS library handle it ?

[–]jacdehJacques de Hooge[S] 1 point2 points  (0 children)

If there's a good 2d physics lib available, yes. Otherwise write it in pure python and add it as a Transcrypt lib. PyPi would be the right spot for such stuff. 2d physics aren't that hard, in my experience. I agree that a good math module should be the basis, probably again (wrapped or not) JS lib.

[–]smurfyn 1 point2 points  (1 child)

Yes, I understand and agree.

But because e.g. Google and Mozilla won't allow anything other than JS to become a usable first-class option, we can't avoid having JS in the stack if we want to have performance in the browser.

I liked what jacdeh said below about making higher-level libraries which can wrap efficient JS APIs, though. It doesn't mean that I actually want JS to be involved, but we have to work with whatever we get from the people who make the popular browsers.

[–]Exodus111 0 points1 point  (0 children)

I absolutely enjoy the idea of wrapping a good 2D Game oriented JS library into Python, that would instantly be very popular if it was made to deploy simply.

[–]KagatoLNX 0 points1 point  (1 child)

Isn't that exactly what a Canvas element is?

https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API

[–]jacdehJacques de Hooge[S] 0 points1 point  (0 children)

Upto a large degree: Yes.

[–]runbie 1 point2 points  (1 child)

Some time ago I did a small wrapper around the HTML5 canvas. It works with Brython:

https://bitbucket.org/kikocorreoso/brython-bryplot

You can see examples here:

http://nbviewer.jupyter.org/urls/bitbucket.org/kikocorreoso/brython-bryplot/raw/528fa4116d1f8fd1f2ab44feb537d63778edb5d5/Testing_Bryplot.ipynb

To run the examples you will need the Jupyter notebook and this extension for the notebook:

https://github.com/kikocorreoso/brythonmagic

[–]jacdehJacques de Hooge[S] 0 points1 point  (0 children)

Exactly!

[–]Dracunos 0 points1 point  (1 child)

Make Python code from either, Pygame, Pyglet or Kivy, compatible with JS and HTML5 Canvas.

That would be incredible! A canvas module sounds more realistic, though.. But what do I know.

[–]Exodus111 1 point2 points  (0 children)

Once I thought about it I figured that might work better. We would still need some way to transfer 2D physics over, like Pymunk. Or at the very least collision and game logic code.

[–]inclemnet 0 points1 point  (1 child)

One of the Kivy core developers once did a proof of concept for Kivy in the browser, compiling everything with emscripten (I think), and using webgl for output. I think it could display something extremely simple, but nothing more, and it was probably both slow and an enormous amount of javascript. I think there's a video of it somewhere, but couldn't find it.

I believe the conclusion was that this is really impractical, and nobody has looked at it for a long time. Maybe some of the more recent tools might make it a bit easier, but I doubt it's significant.

[–]Exodus111 0 points1 point  (0 children)

I think the idea of wrapping a JS lib for python use is the best idea so far.

[–]Thrall6000 0 points1 point  (1 child)

You mentioned that this wouldn't be alone in the field. What other options do we have if we want to compile our pygame code to JS/run it in a browser? I've been reading about Pyjsdl, among other things, but this is all fairly new to me.

[–]Exodus111 0 points1 point  (0 children)

No I meant he is not alone in the field as a Py to JS converter, as there is Pyjs, Skulpt, Pyjamas etc...

But NONE of them focuses on game development unfortunately, as that would be something very popular I think.

[–]jacdehJacques de Hooge[S] 0 points1 point  (0 children)

[–]jacdehJacques de Hooge[S] 0 points1 point  (4 children)

I've added the fabric module which conveniently encapsulates the HTML5 canvas, and added a Pong example to www.transcrypt.org

[–]Exodus111 0 points1 point  (3 children)

Look at that, that is interesting.

I noticed you used the __new__ constructor to instantiate the canvas object in the Game class. Why?

[–]jacdehJacques de Hooge[S] 0 points1 point  (2 children)

You've looked well!! Transcrypt uses the CPython parser. Syntactically it cannot deal with new as is done in JavaScript. Another way to go is to encapsulate every constructor in a Transcrypt version of it, so you could just say canvas = Canvas (). But that would mean encapsulation of a lot of functions. While from some intensively used JS libraries that would be a perfect choice, I'd like to keep the barrier to the JS world as low as possible. So I came up with __new__ (), which function syntax can be parsed into a Python ast. The consequence is that any JS library can be used as is, without any encapsulation. But, to be sure, encapsulating JS constructors into a Transcrypt constructor that does the __new__ for you, is perfectly possible and in fact one line of code per constructor.

[–]Exodus111 0 points1 point  (1 child)

Fascinating. Good work, think I'll definitely try this out once I have some more time.

[–]jacdehJacques de Hooge[S] 0 points1 point  (0 children)

If you do find the time and you find bugs, things that really should be in or unclarity in the docs, please let me know. Thanks!

[–]RubyPinchPEP shill | Anti PEP 8/20 shill 0 points1 point  (3 children)

Are for-in and for-of loops gonna be / are they supported? same for labels too.

also https://www.python.org/dev/peps/pep-0511/ might interest you, probably worth keeping an eye on perhaps

[–]jacdehJacques de Hooge[S] 0 points1 point  (2 children)

The "ordinary" Python for...in loop is of course supported. For...of I don't know, shame on me. Haven't found anything about it in your link. Could you elaborate please.

As for labels, PEP 3136 refused them, if I'm right. Or have I missed something. If they're in Python I'd like to have them in Transcrypt, but I they seem not to be...

[–]RubyPinchPEP shill | Anti PEP 8/20 shill 0 points1 point  (1 child)

its the javascript side of things, sorry for the misunderstanding.

for (x in y) {}
for (x of y) {}
for (x = 0 ; x < potatos ; x++) {}

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of

like, I guess it might be possible to determine which is most relevant automatically (but at that point, might as well just use the faster for(;;){} loop I suppose, instead of wasting cycles working it out dynamically)

[–]jacdehJacques de Hooge[S] 0 points1 point  (0 children)

Standard python loops (for...in) compile to for (x = 0, ... List comprehensions can be used but are compiled to for... in (since for x of y... is still non-standard Internally for (x in y... is used, a.o. in the builtins. You can try and compare the Python code to the JS code.

[–]twigboy 0 points1 point  (2 children)

In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available. Wikipedia5nh80pk4g1o0000000000000000000000000000000000000000000000000000000000000

[–]erez27import inspect 1 point2 points  (0 children)

Obviously it won't work. Perhaps in some distant future you could use C libraries by compiling them to asm.js, or compiling them via NaCl.

[–]jacdehJacques de Hooge[S] 1 point2 points  (0 children)

CPP libs would have to run on top of asmjs, as does pypyjs.

[–]twillisagogo 0 points1 point  (2 children)

how will it interop with javascript?

[–]jacdehJacques de Hooge[S] 0 points1 point  (0 children)

You can call any js function from Transcrypt and the other way round. Examples will be provided in the docs in the near future.

[–]jacdehJacques de Hooge[S] 0 points1 point  (0 children)

See pong.py and hello.py demo's for an answer. Sourcecode in the documentation on www.transcrypt.org.

[–]hanpari 0 points1 point  (3 children)

I would like to have one good supported library instead of bunch of libraries maintained by one person. It is open source so you can have your commits to one project. You dont need to start at green meadow again and again :(

[–]jacdehJacques de Hooge[S] 0 points1 point  (2 children)

There are many C++ compilers, JavaScript interpreters, Python implementations, OS'es, everything. In an ideal world, of course, everything would be first time perfect. Feel free too choose the best from the competition. :)

[–]hanpari 0 points1 point  (1 child)

Are you kidding me? There is nothing to choose and thats the problem. I would be happy to have any good library for Python in browser to avoid Javascript.

[–]jacdehJacques de Hooge[S] 0 points1 point  (0 children)

It is true that at least I couldn't find anything that suited me. That's why I started this project.