Whoa, didn't realize this project existed

48 views
Skip to first unread message

Alexander Tsepkov

unread,
Oct 23, 2011, 3:17:06 AM10/23/11
to py2js mailinglist
Hey guys,

I've been a member of Pyjamas community for almost 2 years now,
developing my entire web app using Pyjamas and web2py with a friend
(for those interested, the app is a "smart" drawing application based
on gesture recognition located at grafpad.com). As my app started
pushing the limits of what Pyjamas could do, I had to start writing my
own wrappers for every JS I wanted to use (like HTML5 canvas) and JS
methods that hooked into Pyjamas to fake/trigger the functionality
that Pyjamas didn't support (like touch events). Over the last couple
months it started getting really annoying (combined with the fact that
my web app was 3.5 MB and 80k lines of code after compilation, almost
10x as much code as the Python version), and I started looking at
other incomplete/abandoned frameworks I could leverage to make a
compiler that was more light-weight. I've looked at PyvaScript, PyCow,
and PYXC-JS, and started writing my own by leveraging PYXC and PyCow
after spending multiple weeks searching for other Python->JS compiler
solutions (I found no trace of py2js, oddly enough it's not publicized
anywhere).

Ironically, last night while browsing the web, I stumbled upon some
blog talking about py2py, which claimed to be based on py2js. So I
searched for py2js to see what it was, and my first find was Niall
McCarroll's 2008 version. While the project was old and didn't support
many Python features, the structure appealed to me a lot more than the
other compilers, it had a clean separation between input and output
(essentially allowing to translate to/from additional languages, as
long as they can be made to work with the same AST tree structure
(which I know is a big "if", considering it's Python's AST)) and the
ability to map Python calls to JS equivalents without having to create
function aliases using the hashmap. So I spent a whole day happily
hacking together that project (added decorator support for functions,
did some debugging since the ast version it used was outdated, beefed
up its debug mode (listing line-by-line Python code in the compiled
JS), and added a bit of basic missing stdlib functionality (zfill,
print, is/is not, join, etc.)). Before going to bed, however, I
figured I'd take a look online again, to see if anyone else has forked
the project. All of a sudden I found this version, which from looking
at it seems to have almost complete Python stdlib and implements just
about everything.

If this compiler+library is really as complete as it seems, with a
much lighter footprint than Pyjamas (the examples seem to all compile
to under 12KB), I think it would be a very good idea to port my
grafpad project to it. From looking at the example source code, it
looks like it doesn't require wrappers to communicate to JS, so it
automatically supports all JS functionality, is that correct? I'm
considering using it in combination with a JS selector engine, like
Sizzle, to manipulate the DOM, would the 2 have any trouble working
together? Are there any limitations in terms of being able to use this
on the same page as another JS framework, like jQuery (not that I'm
planning to bloat up my page with multiple frameworks, but it's nice
to have that option :) ). Is this still based on Niall's version of
py2js, since I see the structure between the two seems very different
now? If so, what made you guys decide to go away from the detached
input/output setup, were there issues with it? If not, would you guys
mind if I branched/forked your version to see if I can make a detached
input/output setup that could eventually allow other languages to be
supported as input/output plugins? Also, what is your stance on
widgets? If I decided to slap together some widgets like custom
SelectBox and PopupPanel similar to the ones in jQuery and MooTools,
would you rather have them be a separate project or part of this one?

Thanks
Alex

Ondřej Čertík

unread,
Oct 23, 2011, 11:33:58 AM10/23/11
to py...@googlegroups.com
Hi Alex!

It doesn't implement everything so far. For example Python modules are
still missing, that is a very important feature.

>
> If this compiler+library is really as complete as it seems, with a
> much lighter footprint than Pyjamas (the examples seem to all compile
> to under 12KB), I think it would be a very good idea to port my
> grafpad project to it. From looking at the example source code, it
> looks like it doesn't require wrappers to communicate to JS, so it
> automatically supports all JS functionality, is that correct? I'm

I think it does, or could be easily tweaked to do.

> considering using it in combination with a JS selector engine, like
> Sizzle, to manipulate the DOM, would the 2 have any trouble working
> together? Are there any limitations in terms of being able to use this
> on the same page as another JS framework, like jQuery (not that I'm
> planning to bloat up my page with multiple frameworks, but it's nice
> to have that option :) ). Is this still based on Niall's version of

As far as I know, it should work just fine with anything.

> py2js, since I see the structure between the two seems very different
> now? If so, what made you guys decide to go away from the detached
> input/output setup, were there issues with it? If not, would you guys

We wrote it from scratch with Mateusz, and then Sam and Christian
contributed significant code as well.

> mind if I branched/forked your version to see if I can make a detached
> input/output setup that could eventually allow other languages to be
> supported as input/output plugins? Also, what is your stance on

Absolutely, go ahead. Sam and Christian are also maintaining a fork,
I am not sure what the status of it is. If you want to contribute back,
just send us a pull request.

> widgets? If I decided to slap together some widgets like custom
> SelectBox and PopupPanel similar to the ones in jQuery and MooTools,
> would you rather have them be a separate project or part of this one?

Why not to use some javascript library for it?

However, I don't see any problem, why it couldn't be in some
additional module inside py2js.

Ondrej

Alexander Tsepkov

unread,
Oct 23, 2011, 12:15:58 PM10/23/11
to py2js mailinglist
You mean importing of modules? It seems to complain about ImportFrom
visitor node not being handled when I run using pyjs.py, but not when
using "python examples/gol.py > examples/gol.html", not sure how it
manages to resolve that when ran the second way, are you relying on
Python to cache the imported module instead of traversing its AST?
Also, I'm not quite sure how your math library setup works, I only see
sqrt() in math.js, are the rest of the methods coming from somewhere
else or it hasn't yet been populated yet (if so, can I just implement
the rest in the same file, mapping them to equivalent Math modules in
JS?)
>
>
> > If this compiler+library is really as complete as it seems, with a
> > much lighter footprint than Pyjamas (the examples seem to all compile
> > to under 12KB), I think it would be a very good idea to port my
> > grafpad project to it. From looking at the example source code, it
> > looks like it doesn't require wrappers to communicate to JS, so it
> > automatically supports all JS functionality, is that correct? I'm
>
> I think it does, or could be easily tweaked to do.
>
Reading through older posts, I found one that suggests creating a
__js__ module and treating all imports from it as native JS. How hard
would it be to implement that based on current project structure, this
seems like a very clean solution that would trump all other frameworks
that require JS("""...""") hacks.

> > considering using it in combination with a JS selector engine, like
> > Sizzle, to manipulate the DOM, would the 2 have any trouble working
> > together? Are there any limitations in terms of being able to use this
> > on the same page as another JS framework, like jQuery (not that I'm
> > planning to bloat up my page with multiple frameworks, but it's nice
> > to have that option :) ). Is this still based on Niall's version of
>
> As far as I know, it should work just fine with anything.
>
> > py2js, since I see the structure between the two seems very different
> > now? If so, what made you guys decide to go away from the detached
> > input/output setup, were there issues with it? If not, would you guys
>
> We wrote it from scratch with Mateusz, and then Sam and Christian
> contributed significant code as well.
>
So it sounds like the libraries just happen to be named the same,
ironic.

> > mind if I branched/forked your version to see if I can make a detached
> > input/output setup that could eventually allow other languages to be
> > supported as input/output plugins? Also, what is your stance on
>
> Absolutely, go ahead. Sam and Christian are also maintaining a fork,
> I am not sure what the status of it is. If you want to contribute back,
> just send us a pull request.
>
> > widgets? If I decided to slap together some widgets like custom
> > SelectBox and PopupPanel similar to the ones in jQuery and MooTools,
> > would you rather have them be a separate project or part of this one?
>
> Why not to use some javascript library for it?
>
> However, I don't see any problem, why it couldn't be in some
> additional module inside py2js.
>
While JS widgets will probably have a smaller footprint and most
people will probably use those, there could be some advantages to
Python widgets too. Being written in Python, they could be easier to
tweak/enhance/inherit for people wishing to expand the functionality,
but not wanting to learn JS. Additionally, these widgets can be
written to include methods/interfaces similar to those of other Python
ui libraries to allow for easier porting of Python apps to the web.
Imagine matplotlib implemented using canvas, for example.

> Ondrej

Samuel Ytterbrink

unread,
Oct 23, 2011, 12:26:28 PM10/23/11
to py...@googlegroups.com


2011/10/23 Alexander Tsepkov <atse...@gmail.com>
Right now you can use java code with python syntax.

def main():
  alert("hello world")
 
should call the javascript function alert if you call main. This should work with all functions that doesn't  have the same name as any in the python std-lib. there have bean a discussion on using the eval statment.

eval("//jscode gose here!")

cause it would actually translate to the javascript eval function, so it should work from th box right now.

> > considering using it in combination with a JS selector engine, like
> > Sizzle, to manipulate the DOM, would the 2 have any trouble working
> > together? Are there any limitations in terms of being able to use this
> > on the same page as another JS framework, like jQuery (not that I'm
> > planning to bloat up my page with multiple frameworks, but it's nice
> > to have that option :) ). Is this still based on Niall's version of
>
> As far as I know, it should work just fine with anything.
>
> > py2js, since I see the structure between the two seems very different
> > now? If so, what made you guys decide to go away from the detached
> > input/output setup, were there issues with it? If not, would you guys
>
> We wrote it from scratch with Mateusz, and then Sam and Christian
> contributed significant code as well.
>
So it sounds like the libraries just happen to be named the same,
ironic.

Im sad to hear you say this Ondrej, cause actually this is not true if you look into the git logs... alot of the tests are from the old py2js wich is what you have found.


> > mind if I branched/forked your version to see if I can make a detached
> > input/output setup that could eventually allow other languages to be
> > supported as input/output plugins? Also, what is your stance on
>
> Absolutely, go ahead. Sam and Christian are also maintaining a fork,
> I am not sure what the status of it is. If you want to contribute back,
> just send us a pull request.
>
> > widgets? If I decided to slap together some widgets like custom
> > SelectBox and PopupPanel similar to the ones in jQuery and MooTools,
> > would you rather have them be a separate project or part of this one?
>
> Why not to use some javascript library for it?
>
> However, I don't see any problem, why it couldn't be in some
> additional module inside py2js.
>
While JS widgets will probably have a smaller footprint and most
people will probably use those, there could be some advantages to
Python widgets too. Being written in Python, they could be easier to
tweak/enhance/inherit for people wishing to expand the functionality,
but not wanting to learn JS. Additionally, these widgets can be
written to include methods/interfaces similar to those of other Python
ui libraries to allow for easier porting of Python apps to the web.
Imagine matplotlib implemented using canvas, for example.

> Ondrej



--
//Samuel "Neppord" Ytterbrink

Ondřej Čertík

unread,
Oct 23, 2011, 2:03:17 PM10/23/11
to py...@googlegroups.com
On Sun, Oct 23, 2011 at 9:26 AM, Samuel Ytterbrink <nep...@gmail.com> wrote:
>
>
> 2011/10/23 Alexander Tsepkov <atse...@gmail.com>
>>
>>
>> On Oct 23, 11:33 am, Ondřej Čertík <ondrej.cer...@gmail.com> wrote:
>> > Hi Alex!
[...]

>> >
>> > We wrote it from scratch with Mateusz, and then Sam and Christian
>> > contributed significant code as well.
>> >
>> So it sounds like the libraries just happen to be named the same,
>> ironic.

I thought the old py2js is dead, so we just reused the name. Maybe it
was a mistake.

>
> Im sad to hear you say this Ondrej, cause actually this is not true if you
> look into the git logs... alot of the tests are from the old py2js wich is
> what you have found.

Thanks for the notice, I forgot about the tests. I just put the
credits into the AUTHORs file:

https://github.com/qsnake/py2js/commit/4dc41274895989da54ebca4a5317f156e59fd126

let me know if it fixes the confusion.

Ondrej

Reply all
Reply to author
Forward
0 new messages