0

Using python 2.7 and Google app engine I am building a website composed of multiple modules.

By that I mean that I am looking to build each module in an app like fashion.

To achieve my goal I have set up multiple *.yaml files using the includes (https://developers.google.com/appengine/docs/python/config/appconfig#Python_app_yaml_Includes). It seems to do what I want until... none of the secondary modules are loaded... I could play around with the 'import' loader in python locally, but I am looking for something less hacky that would work with the app engine deployer (and on the Google server). Basically my problem is that I do not know how to 'include' all python modules (as they live in separate directories as ruled by different yaml). I looked over on the doc and it does not seem to be explained.

I am NOT looking to run them as separated modules, which could be a way of handling it. I could be opened to it but I run into a similar situation with that approach though: how to I include/package the common code in each module?

As I have nothing working I did not include sample code or yaml.

Thank you for your help!

@TimHoffman & @EzequielMuns

Thank you, I implemented the change suggested:

import os
import sys
sys.path.append("[absolute_path_to_be_sure]/used_app")

And got:

  File "[...]/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 903, in load_module
    raise ImportError('No module named %s' % fullname)
ImportError: No module named DefaultHandler

Seems the sandboxing gets in the way (the function that returns this seems hard coded). The Defaulthandler is a python class that live in a module at the root of used_app. I got the error trying to import it.

My directory structure is as follows:

 - main_app
   - app.yaml
   - MyApp.py
   - Handler.py
 - used_app
   - DefaultHandler.py
   - include.yaml (though I am not sure it is useful to me right now)

Where Handler inherits DefaultHandler for example.

1
  • I think you need to rewrite your question making very specific where you're referring to python modules and where you are referring to Google App Engine Modules. Can you at least post the directory structure you have? Commented Jan 6, 2014 at 3:44

2 Answers 2

1

First, using the include.yaml isn't doing anything. It's meant to include more handlers and other limited amounts of config into your main app.yaml.

It's my experience that all your code needs to live under the main app directory, but you can have symlinks if you must (this is especially useful with 3rd party libraries). So why not try to have used_app inside the main app directory.

For reference, I have set up these two layouts before with success:

appdir/
    app.yaml
    main.py
    lib/
    package/
        __init__.py
        module.py

Here there is no need to modify sys.path to access package.module as the appdir is in the PYTHONPATH.

Occasionally I've had to include 3rd party libraries into a lib subdirectory, which then needs to be added to sys.path via appengine_config.py:

appdir/
    app.yaml
    main.py
    appengine_config.py
    lib/
        awesomelibrary/
            __init__.py
            thirdpartymodule.py
    package/
        __init__.py
        module.py

With appengine_config.py:

import sys, os
base = os.path.dirname(__file__)
sys.path.append(os.path.join(base, 'lib'))

Thereby making awesomelibrary.thirdpartymodule importable (and any other packages/modules under lib/).

Sign up to request clarification or add additional context in comments.

1 Comment

Just to point out, the code for a module can live outside the appdir(Mine lives in a sibling dir), without having any symlinks.
0

Setup your paths in appengine_config then import as required in each handler. appengine_confgi.py is loaded prior to any of you code being imported.

https://developers.google.com/appengine/docs/python/tools/appengineconfig

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.