Share python package between appengine modules

552 views Asked by At

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 ?

1

There are 1 answers

1
Nicholas Franceschina On BEST ANSWER

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