in

Corey Roth and Friends Blogs

Group site for developer blogs dealing with (usually) Ionic, .NET, SharePoint, Office 365, Mobile Development, and other Microsoft products, as well as some discussion of general programming related concepts.

Not Necessarily Dot Net

January 2009 - Posts

  • Pyjamas on Google App Engine

    Pyjamas is one of the most interesting frameworks I've run across in a long time. 

    You write a desktop-style app (it looks a lot like something you'd do if you were lame enough to actually write WPF code instead of using the GUI to build XAML) in python, and run it through a "compiler" that converts it to browser-independent javascript. There's even a pyjamas-desktop project that lets the serious hacker neophiles run it as a desktop app without the "compilation" stage (which restores the ability to develop like you're using an interpreted language).

    Google's been doing this for a while now with Java and GWT.  But who wants to write code in Java?  You might as well be doing C# ;-)

    I won't pretend there are scads of articles throwing themselves at us over the 'Net, but there are plenty to get started (which is totally where I am...along with several members of the GAE user's group who can't figure out how to serve static files).  But there *are* tons of materials devoted to GWT.  Same engine and libraries, just translated to a different (higher level, more intuitive, easier to use) language.

    I've seen a few articles devoted to running Pyjamas-generated apps on GAE, but I haven't seen anything that really gives the basic HOWTO, nuts & bolts details (they all assume that the reader is more familiar than I).  So, without further ado, let's get the basic "Hello World" app going.

    I'm going to assume that you already have pyjamas and the GAE SDK downloaded and extracted.  Along with python, of course.

    From the GAE SDK's new_project_template directory, copy the files into the one for your app...you have to start somewhere.

    ===Your application's source===

    This lives in some directory outside your website.  Or maybe a directory that's excluded by app.yaml.  Wherever.  Someplace that you will not be uploading to GAE.  (Just to clarify an FAQ: put this directory under some sort of source control, too).

    Run the `build.sh` script in...whichever directory's appropriate (for this, admittedly rather stupid example, pyjamas' SDK's helloworld directory).  You might have to suck it up and translate this into a .BAT file (actually, you *really* should.  Or whatever the powershell equivalent is.  Sooner or later, you're going to want to do a little more than you are now).  Run your source code through the pyjamas interpreter and get a folder that has output.

    Our goal, really, is to get the output of that to display as static content (there's some interesting possibilities revolving around hacking into that and making it dynamic...but those are *way* out of scope).  Therefore, copy the results (from the output/ directory) into your web app's /static directory (yes, you do have to create that...yet again, write a .BAT file for this so you can be lazy like the rest of us.  Better yet, make this a step in your first one.  Seriously, they aren't that scary).

    ===app.yaml===

    Update app.yaml.  (If you've played much with GAE, you know by now that this is where all configuration changes wind up living).

    My initial inclination was to add a section that tells it where to find static requests:

    Under [handlers], add

    - url: /static
       static_dir: static

    The server refuses to start, with this error:

    Fatal error when loading application configuration:
    mapping values are not allowed here
    in "/blah/app.yaml", line 10, column 14

     Which is, of course, as useless as those old "Error -16837" dialog boxes from Way Back When..  WTF does that actually mean?

    Just for the sake of anyone else who runs across that ridiculous error, it means that yaml's a lot pickier about white space than even make.  I have 3 spaces at the front of the static_dir line. Reduce it to 2 and the problem goes away.

    Now I can browse to (for example) http://localhost:8080/static/Hello.html and see my work of art.

    From here, it wouldn't be any big deal to add a main.py script that handles all your other requests and redirects them (for example) to /static/index.html.  But that's beyond the scope of today's babbling.

2019.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems