2

I have 3 appengine modules lets say modA (default module-contains app.yaml), modB and modC, which share datastore entities and some utility functions and external libs in an 'common' directory as shown in the below:

- modA
  - app.yaml
  - appengine_config.py
- modB
  - modB.yaml
  - appengine_config.py
- modC
  - modC.yaml
  - appengine_config.py
- common
  - __init__.py

To share 'common' among the modules, I created appengine_config.py file with the following code:

#!/usr/bin/env python

import sys
import os
import logging

logging.info("LOADING CONFIG FILE")

PARENT_DIR = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, os.path.join(PARENT_DIR, 'common'))

logging.info(sys.path)

In the console it shows the 'common' in sys.path but it still fails to recognize the module when using import statements.

Please let me know on how to fix this. Also is there a better way to do this ?

Harshal Patil
  • 6,659
  • 8
  • 41
  • 57
sshntt
  • 191
  • 1
  • 13
  • 1
    As per the answer [here](http://stackoverflow.com/a/15653005/203455), one way to do it is to create links in each of the modules to the common folder. I tried the approach and it worked. No need to even add the module to the PYTHONPATH. But if somebody has a another approach and also the reason to why the above is happening. Please do answer. – sshntt Mar 25 '15 at 14:30

1 Answers1

4

All of the application files you want to deploy must be in the same directory as the app.yaml. So what you probably want to do is create a symlink folder underneath each of your module folders that points to /common

- modA
  - app.yaml
  - common -> ../common
- modB
  - modB.yaml
  - common -> ../common
- modC
  - modC.yaml
  - common -> ../common
- common
  - __init__.py

appcfg.py update will follow symlinks and upload the /common module into each app engine module

Nicholas Franceschina
  • 6,009
  • 6
  • 36
  • 51