Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Google Appengine: KeyError: '__main__' when using config.include() #63

Closed
katzlbt opened this Issue · 4 comments

2 participants

@katzlbt

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'

@katzlbt

Here is a hint ...
http://www.inductiveautomation.com/forum/viewtopic.php?f=70&p=36917

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__")

def _get_or_build_default_environment(registry):
@domenkozar
Owner

Also relevant: docent@a6f1b79

Hopefully someone on GAE provides a patch with tests someday :-)

@domenkozar
Owner

Note: this will bump required pyramid version to 1.3

@domenkozar
Owner

Closing this, let me know if bug still exists

@domenkozar domenkozar closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.