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

runzeo error (Plone 5/Python 2.7): Attempted relative import in non-package #87

Closed
jensens opened this issue May 22, 2017 · 6 comments
Closed

Comments

@jensens
Copy link
Member

jensens commented May 22, 2017

In order to not run into the problems of #84 I tried to use runzeo with supervisor.

runzeo fails to start with:

Traceback (most recent call last):
  File "/home/jensens/.buildout/shared-eggs/ZEO-5.1.0-py2.7.egg/ZEO/runzeo.py", line 401, in <module>
    main()
  File "/home/jensens/.buildout/shared-eggs/ZEO-5.1.0-py2.7.egg/ZEO/runzeo.py", line 392, in main
    s.main()
  File "/home/jensens/.buildout/shared-eggs/ZEO-5.1.0-py2.7.egg/ZEO/runzeo.py", line 155, in main
    self.create_server()
  File "/home/jensens/.buildout/shared-eggs/ZEO-5.1.0-py2.7.egg/ZEO/runzeo.py", line 251, in create_server
    self.server = create_server(self.storages, self.options)
  File "/home/jensens/.buildout/shared-eggs/ZEO-5.1.0-py2.7.egg/ZEO/runzeo.py", line 345, in create_server
    from .StorageServer import StorageServer
ValueError: Attempted relative import in non-package

I added a configuration to the Plone coredev buildout here:
https://github.com/plone/buildout.coredev/blob/5.1/experimental/zeoserver.cfg
and run it with ./bin/buildout -c experimental/zeoserver.cfg
The generated script ./bin/zeoserver has two modes, one uses zeoctl and the other, if in enviroment SUPERVISOR_ENABLED=1 is set, runzeo is used.

After changing the relative import to an absolute one this specific problem is gone and runzeo or SUPERVISOR_ENABLED=1 ./bin/zeoserver works (but #84 is still an issue).

@jensens jensens changed the title runzeo error (Plone 5/Python 2.7) runzeo error (Plone 5/Python 2.7): Attempted relative import in non-package May 22, 2017
@jimfulton
Copy link
Member

Please don't use zeoctl. No one really knows how to make it work. There should be no real difference between zdaemon and supervisord.

  1. Generate a ZEO config file.

2 a) If you're using supervisord generate/update your supervisord config to run runzeo with the ZEO config.

2 b) If you're using zdaemon, generate a zdaemon config that runs runzeo. (The zc.zdaemon recipe is good for this.

@jensens
Copy link
Member Author

jensens commented May 23, 2017

You got me wrong, I did not use zeoctl. As stated above I use runzeo started by a script generated by plone.recipe.zeoserver. This recipe offers two modes of operation, one uses zeoctl (which is really broken), the other one (triggered by the environment mentioned above) in fact just is a startup script for runzeo.

The startup script for runzeo looks like this:

$ cat parts/zeoserver/bin/runzeo 
#!/bin/sh
# ZEO instance start script

PYTHON="/home/workspacejensens/pro/akifair/bin/python"
INSTANCE_HOME="/home/workspacejensens/pro/akifair/parts/zeoserver"
ZODB3_HOME="/home/jensens/.buildout/shared-eggs/ZEO-5.1.0-py2.7.egg"

CONFIG_FILE="/home/workspacejensens/pro/akifair/parts/zeoserver/etc/zeo.conf"

PYTHONPATH="/home/workspacejensens/pro/akifair/srccore/plone.recipe.zeoserver/src:/home/jensens/.buildout/shared-eggs/ZopeUndo-4.2-py2.7.egg:/home/jensens/.buildout/shared-eggs/ZODB3-3.11.0-py2.7.egg:/home/jensens/.buildout/shared-eggs/zope.mkzeoinstance-3.9.5-py2.7.egg:/home/jensens/.buildout/shared-eggs/zc.recipe.egg-2.0.3-py2.7.egg:/home/workspacejensens/pro/akifair/lib/python2.7/site-packages:/home/workspacejensens/pro/akifair/lib/python2.7/site-packages:/home/workspacejensens/pro/akifair/lib/python2.7/site-packages:/home/workspacejensens/pro/akifair/lib/python2.7/site-packages:/home/workspacejensens/pro/akifair/lib/python2.7/site-packages:/home/workspacejensens/pro/akifair/lib/python2.7/site-packages:/home/jensens/.buildout/shared-eggs/transaction-2.1.2-py2.7.egg:/home/jensens/.buildout/shared-eggs/BTrees-4.4.1-py2.7-linux-x86_64.egg:/home/jensens/.buildout/shared-eggs/persistent-4.2.4.2-py2.7-linux-x86_64.egg:/home/jensens/.buildout/shared-eggs/ZODB-5.2.3-py2.7.egg:/home/jensens/.buildout/shared-eggs/ZEO-5.1.0-py2.7.egg:/home/jensens/.buildout/shared-eggs/zope.interface-4.4.0-py2.7-linux-x86_64.egg:/home/jensens/.buildout/shared-eggs/zodbpickle-0.6.0-py2.7-linux-x86_64.egg:/home/jensens/.buildout/shared-eggs/zc.lockfile-1.2.1-py2.7.egg:/home/jensens/.buildout/shared-eggs/ZConfig-3.1.0-py2.7.egg:/home/jensens/.buildout/shared-eggs/trollius-2.1-py2.7.egg:/home/jensens/.buildout/shared-eggs/futures-3.1.1-py2.7.egg:/home/jensens/.buildout/shared-eggs/zdaemon-4.2.0-py2.7.egg:"
export PYTHONPATH INSTANCE_HOME

RUNZEO="$ZODB3_HOME/ZEO/runzeo.py"

exec "$PYTHON" "$RUNZEO" -C "$CONFIG_FILE" ${1+"$@"}

the generated configuration looks like this

$ cat parts/zeoserver/etc/zeo.conf
%define INSTANCE /home/workspacejensens/pro/akifair/parts/zeoserver

<zeo>
  address 127.0.0.1:8100
  read-only false
  invalidation-queue-size 100
  pid-filename /home/workspacejensens/pro/akifair/var/zeoserver.pid
  
  
</zeo>

<filestorage 1>
  path /home/workspacejensens/pro/akifair/var/filestorage/Data.fs
  blob-dir /home/workspacejensens/pro/akifair/var/blobstorage
  
  
</filestorage>

<eventlog>
  level info
  <logfile>
      path /home/workspacejensens/pro/akifair/var/log/zeoserver.log
      format %(asctime)s %(message)s
      
    </logfile>
</eventlog>

<runner>
  program $INSTANCE/bin/runzeo
  socket-name /home/workspacejensens/pro/akifair/var/zeo.zdsock
  daemon true
  forever false
  backoff-limit 10
  exit-codes 0, 2
  directory $INSTANCE
  default-to-interactive true
  

  # This logfile should match the one in the zeo.conf file.
  # It is used by zdctl's logtail command, zdrun/zdctl doesn't write it.
  logfile /home/workspacejensens/pro/akifair/var/log/zeoserver.log
</runner>

Now, when I start the runzeo script directly, w/o the patch it runs into the traceback:

$ ./parts/zeoserver/bin/runzeo 
Traceback (most recent call last):
  File "/home/jensens/.buildout/shared-eggs/ZEO-5.1.0-py2.7.egg/ZEO/runzeo.py", line 401, in <module>
    main()
  File "/home/jensens/.buildout/shared-eggs/ZEO-5.1.0-py2.7.egg/ZEO/runzeo.py", line 392, in main
    s.main()
  File "/home/jensens/.buildout/shared-eggs/ZEO-5.1.0-py2.7.egg/ZEO/runzeo.py", line 155, in main
    self.create_server()
  File "/home/jensens/.buildout/shared-eggs/ZEO-5.1.0-py2.7.egg/ZEO/runzeo.py", line 251, in create_server
    self.server = create_server(self.storages, self.options)
  File "/home/jensens/.buildout/shared-eggs/ZEO-5.1.0-py2.7.egg/ZEO/runzeo.py", line 345, in create_server
    from .StorageServer import StorageServer
ValueError: Attempted relative import in non-package

@jensens
Copy link
Member Author

jensens commented May 23, 2017

And, I forgot to mention, with the patch in #88 everything works as expected.

@jensens
Copy link
Member Author

jensens commented May 23, 2017

I tried to find the reason of the problem. The generated script runs the main function of ZEO-5.1.0-py2.7.egg/ZEO/runzeo.py. Since it is implemented I would expect it to work.

The Python import mechanism works relative to the name of the current file. When you execute a file directly, it doesn't have its usual name, but has "main" as its name instead. So relative imports don't work. explanation found on Stackoverflow

So changing the generated script at the end to:

[...]
RUNZEO="ZEO.runzeo"
exec "$PYTHON" -m "$RUNZEO" -C "$CONFIG_FILE" ${1+"$@"}

works.

Question: Should a direct call of ZEO/runzeo.py as a script work? If not we can close this one and #88.

I'll fix plone.recipe.zeoserver anyway to call it in the right context.

@jensens
Copy link
Member Author

jensens commented May 23, 2017

What an odyssey! I never touched this, just found the code generated is in zope.mkzeoinstance, here https://github.com/zopefoundation/zope.mkzeoinstance/blob/master/src/zope/mkzeoinstance/__init__.py#L140

So best it's fixed there.

@jensens
Copy link
Member Author

jensens commented May 23, 2017

I close this one. Finally, it looks like the problem is in zope.mkzeoinstance

@jensens jensens closed this as completed May 23, 2017
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

2 participants