-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Google Appengine: KeyError: '__main__' when using config.include() #63
Comments
Here is a hint ... Solved ... patched the init.py class VirtualModule(object):
def __init__(self,name):
import sys
sys.modules[name]=self
def __getattr__(self,name):
return globals()[name]
VirtualModule("__main__") |
Also relevant: docent@a6f1b79 Hopefully someone on GAE provides a patch with tests someday :-) |
Note: this will bump required pyramid version to 1.3 |
Closing this, let me know if bug still exists |
@domenkozar This bug appears to still exist. I'm working on fleshing out Pyramid's support for appengine (at the very least seeing where it stands) and am able to get chameleon working just fine, but jinja2 doesn't seem to work right. Getting this error, where all I'm doing is swapping out Chameleon for Jinja2. The workaround doesn't appear to be valid anymore, as I'm not seeing a _get_or_build_default_environment function anywhere. |
_get_or_build_default_environment is only context to hint where the patch could go in the file, I removed it in my comment because it is confusing. I just append the code to pyramid_jinja2/init.py using echo statements automatically. |
I am using google appengine with pyramid, and tried to use jinja2.
When I add config.include('pyramid_jinja2') it crashes in some introspect code ...
in _get_or_build_default_environment(config.registry)
It seems to crash in python's inspect.py
Someone else had this error too:
http://stackoverflow.com/questions/8031476/pyramid-jinja2-and-new-gae-runtime
It can be fixed by creating a VirtualModule main which means patching init.py of every new release of pyramid_jinja2, see comment below.
main.py ...
import os
import logging
logging.getLogger().setLevel(logging.DEBUG)
from pyramid.config import Configurator
from yaml import load
from appglobals import APP_BASE_DIR
SETTINGS_FILE = os.path.join(APP_BASE_DIR, 'settings.yaml')
def app_config():
config = Configurator(settings=load(open(SETTINGS_FILE, 'r').read()))
config.add_settings({'locandy.appbasedir': APP_BASE_DIR})
config.hook_zca()
config.include('pyramid_jinja2')
config.add_route('catchall', '{notfound:.*}')
return config
config = app_config()
application = config.make_wsgi_app()
Traceback (most recent call last):
File "/Users/cat/repositories/locandy-web/parts/appengine_sdk/google/appengine/runtime/wsgi.py", line 196, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Users/cat/repositories/locandy-web/parts/appengine_sdk/google/appengine/runtime/wsgi.py", line 255, in _LoadHandler
handler = import(path[0])
File "/Users/cat/repositories/locandy-web/app/main.py", line 22, in
config = app_config()
File "/Users/cat/repositories/locandy-web/app/main.py", line 18, in app_config
config.include('pyramid_jinja2')
File "distlib/pyramid/config/init.py", line 773, in include
c(configurator)
File "distlib/pyramid_jinja2/init.py", line 468, in includeme
_get_or_build_default_environment(config.registry)
File "distlib/pyramid_jinja2/init.py", line 252, in _get_or_build_default_environment
package = _caller_package(('pyramid_jinja2', 'jinja2', 'pyramid.config'))
File "distlib/pyramid_jinja2/init.py", line 132, in caller_package
for t in self.inspect.stack():
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 1054, in stack
return getouterframes(sys._getframe(1), context)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 1032, in getouterframes
framelist.append((frame,) + getframeinfo(frame, context))
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 1007, in getframeinfo
lines, lnum = findsource(frame)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 532, in findsource
module = getmodule(object, file)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/inspect.py", line 504, in getmodule
main = sys.modules['main']
KeyError: 'main'
The text was updated successfully, but these errors were encountered: