views:

44

answers:

2

Hi,

I'm brand new to Google App Engine and have just been playing around with it, but for the life of me I don't understand how to import non-standard modules, and for that matter don't fully understand the app.yaml file's purposes.

Essentially I want to import SimPy (a collection of ~15 python files) from my script file, but every combination of things I do results in an ImportError, i.e:

from SimPy.Simulation import *
ImportError: No module named SimPy.Simulation

At present they're all in the same folder, and my app.yaml file reads:

application: physicalsim
version: 1
runtime: python
api_version: 1

handlers:
- url: /
  script: physicalsim.py
- url: /
  script: Globals.py
- url: /
  script: Simulation.py
etc....

Now I'm quite certain I've got the syntax of the yaml file wrong, but can't really find any useful documentation for how to do it anywhere (bit frustrating), I don't really understand the meaning of the folders defined in some of the app.yaml files I've seen bearing in mind there is no physical structure, are they just virtual folders?

Cheers if you can help and I'm sure I've come across as a dunce :)

+1  A: 

From the appconfig (skipping files) doc:

Files in your application directory whose paths match a static_dir path or a static_files upload path are considered to be static files. All other files in the application directory are considered to be application program and data files.

The skip_files element specifies which files in the application directory are not to be uploaded to App Engine. The value is either a regular expression, or a list of regular expressions. Any filename that matches any of the regular expression is omitted from the list of files to upload when the application is uploaded.

(Do not put SimPy in a skip list).

There is no need to specify the included program files in app.yaml. Make sure your application directory includes a sub-directory named SimPy with an __init__.py file and, of course, Simulation.py.

gimel
A: 

The documentation for the app.yaml file is here in the Application Config page.

The handlers section essentially works by comparing a request's url with each of the patterns specified in turn and when the first match is found running the matching handler (or serving up static files if static_dir or static_files is specified instead of script.

In the app.yaml you've shown, the url exactly matching / will cause the handler physicalsim.py to be called. All the other handlers will be ignored since they're served from the same url. If those are support modules for physicalsim.py you don't need to include anything about them in app.yaml.

The urls don't have to have any bearing on what the structure of your webapp looks like internally. There doesn't need to be any correspondence between the url paths and the directories containing your handlers & modules (although for sanity's sake you might want to maintain at least some correlation).

Have you been through the getting started docs?

The directory in which app.yaml resides (i.e. the root of your Application as it will be uploaded) will be on the python path, you should be able to refer to all your modules with respect to it (and/or add others in your handler if needed).

pycruft