Skip to content
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

Imports fail on Google App Engine #5

Open
KitB opened this issue Jul 19, 2012 · 8 comments
Open

Imports fail on Google App Engine #5

KitB opened this issue Jul 19, 2012 · 8 comments

Comments

@KitB
Copy link

KitB commented Jul 19, 2012

In particular the execjs library tries to import subprocess which I believe is a disallowed module on app engine.

Along with this the "from . import errors" line fails but "from plim.errors import *" seems to work

I have solved the problem for my own system by ripping out the extensions and using the wildcard import but this is not a real solution; I will look into fixing it more elegantly once my site is a MVP (unless it is already fixed by then)

@avanov
Copy link
Owner

avanov commented Jul 19, 2012

Hello!

In fact, I didn't test Plim on GAE at all, but it seems to work perfectly well with a regular CPython environment (both in 2.x and 3.x). Therefore, I need more information about the GAE environment. Is there a list of allowed/prohibited packages for GAE?

Along with this the "from . import errors" line fails but "from plim.errors import *" seems to work

The initial version used absolute imports. But the 2to3 utility suggested me to rewrite them to relative ones. It works for me now both on 2.x and 3.x environment.

So, could you provide your import traceback? I believe that the problem caused either by incorrect PYTHONPATH/sys.path or by another GAE restriction.

@KitB
Copy link
Author

KitB commented Jul 19, 2012

I wouldn't be surprised if I had a peculiarity on my machine causing it to fail.
Traceback follows:

ERROR    2012-07-19 17:27:05,793 wsgi.py:189] 
Traceback (most recent call last):
  File "/opt/google-appengine-python/google/appengine/runtime/wsgi.py", line 187, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/opt/google-appengine-python/google/appengine/runtime/wsgi.py", line 236, in _LoadHandler
    __import__(cumulative_path)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1858, in load_module
    return self.FindAndLoadModule(submodule, fullname, search_path)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1722, in FindAndLoadModule
    description)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1665, in LoadModuleRestricted
    description)
  File "/home/kit/Programming/Python/GAE/temp/turbopunch/main.py", line 4, in <module>
    from turbopunch.pages import Index, Signup, UserPage, DisplayImagePage
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1858, in load_module
    return self.FindAndLoadModule(submodule, fullname, search_path)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1722, in FindAndLoadModule
    description)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1665, in LoadModuleRestricted
    description)
  File "/home/kit/Programming/Python/GAE/temp/turbopunch/pages/__init__.py", line 6, in <module>
    import plim
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1858, in load_module
    return self.FindAndLoadModule(submodule, fullname, search_path)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1722, in FindAndLoadModule
    description)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1665, in LoadModuleRestricted
    description)
  File "/home/kit/Programming/Python/GAE/temp/plim/__init__.py", line 2, in <module>
    from . import lexer
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1858, in load_module
    return self.FindAndLoadModule(submodule, fullname, search_path)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1722, in FindAndLoadModule
    description)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1665, in LoadModuleRestricted
    description)
  File "/home/kit/Programming/Python/GAE/temp/plim/lexer.py", line 8, in <module>
    from .extensions import rst_to_html
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1858, in load_module
    return self.FindAndLoadModule(submodule, fullname, search_path)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1722, in FindAndLoadModule
    description)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1665, in LoadModuleRestricted
    description)
  File "/home/kit/Programming/Python/GAE/temp/plim/extensions.py", line 2, in <module>
    import coffeescript
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1858, in load_module
    return self.FindAndLoadModule(submodule, fullname, search_path)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1722, in FindAndLoadModule
    description)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1665, in LoadModuleRestricted
    description)
  File "/home/kit/Programming/Python/GAE/temp/coffeescript/__init__.py", line 34, in <module>
    import execjs
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1858, in load_module
    return self.FindAndLoadModule(submodule, fullname, search_path)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1722, in FindAndLoadModule
    description)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
    return func(self, *args, **kwargs)
  File "/opt/google-appengine-python/google/appengine/tools/dev_appserver_import_hook.py", line 1665, in LoadModuleRestricted
    description)
  File "/home/kit/Programming/Python/GAE/temp/execjs/__init__.py", line 32, in <module>
    from subprocess import Popen, PIPE, STDOUT
ImportError: cannot import name Popen

@KitB
Copy link
Author

KitB commented Jul 19, 2012

I'm running appengine installed on Archlinux from the AUR package google-appengine-python

My code is using the python27 runtime and threading is enabled; I'll try and throw together a minimal error example later for you to try.

@avanov
Copy link
Owner

avanov commented Jul 19, 2012

Ok, keep me in touch

@mez
Copy link

mez commented Apr 17, 2014

Has this ever been addressed? Is plim still active?

@avanov
Copy link
Owner

avanov commented Apr 18, 2014

@mez it is active, but since I never used GAE and do not have plans for using Python on GAE, I need somebody else to address this issue. I can only guarantee that Plim works correctly in classic CPython environments - https://travis-ci.org/avanov/Plim/builds

@mez
Copy link

mez commented Apr 18, 2014

Thanks @avanov I managed to just download the .egg into the bundle. Any plans to create an adapter for webapp2 framework?

Here is what I managed to gather from the internet and was able to get correct rendering output.

from functools import partial
from plim import preprocessor as plim_preprocessor
from mako.template import Template as MakoTemplate
from mako.lookup import TemplateLookup

lookup = TemplateLookup(directories=['/templates'])
Template = partial(MakoTemplate, lookup=lookup,
preprocessor=plim_preprocessor)

print Template(filename="templates/index.plim").render()

Is there a better, easier way to use this engine? Sorry I am new to python in general so this is a learning step for me!

-Mez

@avanov
Copy link
Owner

avanov commented Apr 19, 2014

You have used the correct way of initializing Mako Lookup. The only thing is that if you specify the parent directory via TemplateLookup(directories=['/templates']), it becomes the root of all your template paths, so instead of templates/index.plim you just use /index.plim. The same rule is applicable when you use inheritance inside templates.

Any plans to create an adapter for webapp2 framework?

Could you provide me a link on how templates work in this framework? I need to know if there's a way to integrate custom Mako Lookups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants