How To Import Lib Folder Within Modules
Solution 1:
Credit goes to Google Cloud Platform Tech Solutions Representative Adam:
Modules documentations may not be explicitly stated, but the folder 'Module1', 'Module2' as well as the default module actually run inside separate Python virtual environments on separate instances and need to be self contained. They cannot 'see' any directories above them which exist on the local filesystem, and 'default.py' can't see anything in each of the module directories. The whole folder tree isn't copied to each module instance.
He suggested that instead of making symlinks, just copy ./lib to each of the modules.
I do not like the idea very much.
Firstly, these modules share some base class, duplicating them is really an anti-pattern.
Secondly, copying the lib folders everywhere corrupts unit tests as nose will try to run all unit tests it can run, also because it's a pain to explicitly exclude the directories.
At the end of the day, I wrote a makefile to help deployment / testing easier...
# Create simlinks before deployment.deploy: mksimlnks
appcfg.py --oauth2 update $(CURDIR)/app.yaml
appcfg.py --oauth2 update $(CURDIR)/MODULE_1/module_1.yaml
appcfg.py --oauth2 update $(CURDIR)/MODULE_2/module_2.yaml
appcfg.py --oauth2 update_queues $(CURDIR)mksimlnks:
ln -s $(CURDIR)/lib $(CURDIR)/MODULE_1/lib
ln -s $(CURDIR)/lib $(CURDIR)/MODULE_2/lib
# Need to remove symlinks before unittest# or unit test will explode.test: rmsimlnks
nosetests --exclude-dir=lib --with-gae -w $(CURDIR) --with-coverage --cover-html
# Remove all symlinksrmsimlnks:
rm -rf $(shell find * -type l)# remove symlinks and other stuffclean: rmsimlnks
rm -f $(shell find * -name *.pyc)
rm -f $(shell find * -name .DS_Store)
rm -f .coverage
rm -rf $(CURDIR)/cover
Post a Comment for "How To Import Lib Folder Within Modules"