jump to navigation

Pyjamas + Pylons June 4, 2011

Posted by PythonGuy in Pyjamas, Pylons.
add a comment

I’m looking into Pyjamas, specifically combining it with Pylons.

First note: easy_install pyjamas does not work with virtualenv. This is not a good sign. Maybe because it is a build tool, this isn’t going to be as important as I thought. But something tells me something is fishy about the install process.

On Fedora:

$ sudo yum -y install pyjamas*

The base pyjamas package is missing a lot of things you’ll want to monkey around with, so you might as well install them all.

The pyjamas-examples package has all the examples. You may want to copy the entire thing into your home directory before modifying anything.

Pyjamas: I note that the build scripts don’t work out of the box, on account of /usr/share/pyjamas/bin/pyjsbuild is missing. This is very, very curious. Perhaps the pyjamas RPM doesn’t install in a complete state, or the build scripts are just plain wrong. Indeed, /usr/bin/pyjsbuild does exist, so the build scripts are wrong.

I’ve figured out a way to integrate Pylons and Pyjamas somewhat elegantly. Inside your Pylons project:

  1. Create a library directory for your_project/ui by touching your_project/ui/__init__.py
  2. Put your Pyjamas script in there in ClassName.py.
  3. Build your stuff with a script named build.sh which contains: /usr/bin/pyjsbuild -o your_project/public/ui your_project.ui.YourClass
  4. Copy the main HTML file (your_project.ui.YourClass.html) to your public/index.html.
  5. Modify the meta tag at the top of your new index.html to put “/ui/=” before the class name.

What we’re doing here is organizing your code so that all the Pyjamas stuff lives under your_project.ui. This unique namespace shouldn’t be relied upon but by things in that namespace, since whatever you rely on is going to be converted to Javascript.

That last step tells Pyjamas that all your stuff lives under the /ui/ path. I found this by using Firebug on the startup script.

Advertisements