in

Dot Net Mafia

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

Not Necessarily Dot Net

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.

Comments

 

Alejandro Zürcher said:

Hey, I'm getting the same error!, but changing blank spaces wont do the trick. It's a small app, since I'm just starting, but It's a headache. Here's my app.yaml:

#app.yaml

application: userstoriesGAE

version: 1

runtime: python

api_version: 1

handlers:

- url: /.*

 script: main.py

And the error when running server:

mapping values are not allowed here

in "...\app.yaml", line 2, column 8

November 19, 2009 12:21 PM
 

Alexis said:

"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."

Yeah, thank you!

December 10, 2009 10:33 AM
 

Erik Swanson said:

Thank you for solving my app.yaml problem. I actually was missing a whitespace character and got the same result. But you helped me fix it.

December 13, 2009 10:44 PM
 

Josh said:

Thanks!  Just had the

"mapping values are not allowed here" error, and your post provided the solution.  Much obliged!

March 21, 2010 11:01 PM

Leave a Comment

(required)  
(optional)
(required)  
Add
2012 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems