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

PluginBase causes ImportError in PyYAML #5

Closed
cesarvandevelde opened this issue Jan 1, 2015 · 13 comments
Closed

PluginBase causes ImportError in PyYAML #5

cesarvandevelde opened this issue Jan 1, 2015 · 13 comments
Assignees
Labels

Comments

@cesarvandevelde
Copy link

PluginBase seems to break PyYAML, causing ImportErrors on import.
I'm using the latest version of PyYAML (3.11) and PluginBase.
Tested on OS X and Linux.

Importing PluginBase first causes errors:

Python 2.7.3 (default, Mar 18 2014, 05:13:23) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pluginbase
>>> import yaml
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pluginbase.py", line 404, in plugin_import
    fromlist, level)
  File "/usr/local/lib/python2.7/dist-packages/yaml/__init__.py", line 2, in <module>
    from error import *
  File "/usr/local/lib/python2.7/dist-packages/pluginbase.py", line 404, in plugin_import
    fromlist, level)
ImportError: No module named error

Importing YAML first works fine:

Python 2.7.3 (default, Mar 18 2014, 05:13:23) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import yaml
>>> import pluginbase
@akun
Copy link

akun commented Feb 11, 2015

also causes ImportError in bsddb

Python 2.6.5 (r265:79063, Feb 27 2014, 19:43:51)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pluginbase
>>> import bsddb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.6/site-packages/pluginbase.py", line 404, in plugin_import
    fromlist, level)
  File "/usr/lib64/python2.6/bsddb/__init__.py", line 65, in <module>
    from bsddb.dbutils import DeadlockWrap as _DeadlockWrap
  File "/usr/local/lib/python2.6/site-packages/pluginbase.py", line 404, in plugin_import
    fromlist, level)
  File "/usr/lib64/python2.6/bsddb/dbutils.py", line 35, in <module>
    import db
  File "/usr/local/lib/python2.6/site-packages/pluginbase.py", line 404, in plugin_import
    fromlist, level)
ImportError: No module named db

Importing bsddb first works fine:

Python 2.6.5 (r265:79063, Feb 27 2014, 19:43:51)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bsddb
>>> import pluginbase

@nfarrar
Copy link

nfarrar commented Feb 20, 2015

Yeah, won't work with PyYAML. :(

@mittagessen
Copy link

I am encountering the same issue and it seems to be related to relative imports in the "offending" packages while the importer assumes absolute imports. I've been able to fix the issue by changing the last few relative imports in the "offending" package. I'll look at the pluginbase source code in the next few days and hopefully create a pull request.

@darvid
Copy link

darvid commented May 17, 2015

any updates on this? there are a number of libraries in the stdlib that are affected by this as well, including xml.sax.saxutils

@mittagessen
Copy link

I am sorry but I've switched to stevedore as it seems to be in active development and integrates nicely into setuptools.

@akun
Copy link

akun commented Jun 3, 2015

@mittagessen Thanks!

@PaulSec
Copy link

PaulSec commented Oct 20, 2015

Same issue here with Scapy.

@phretor
Copy link

phretor commented Nov 19, 2015

All same issues. See also #10

Is this module in active development?

@PaulSec
Copy link

PaulSec commented Nov 19, 2015

It does not seem too. I re-implemented my own Plugin system to be honest.

@zeroSteiner
Copy link
Collaborator

I am also experiencing this issue.

@PaulSec
Copy link

PaulSec commented May 25, 2016

In case you're interested, I create a small repo to show how I handled a minimalistic Plugin architecture - https://github.com/PaulSec/Python-plugins

@zeroSteiner
Copy link
Collaborator

I was able to fix the issue by changing _ImportHook.plugin_import(... level=0) to ...level=-1) which according to the docs will allow for both relative and absolute imports.

@zeroSteiner zeroSteiner self-assigned this Jun 9, 2016
@zeroSteiner zeroSteiner added the bug label Jun 9, 2016
@zeroSteiner
Copy link
Collaborator

I fixed this in commit 9e5764f by setting the level parameter to the default value for the version of Python which is running. This appears to have been an issue with level always defaulting to 0 in Python 2 which prevents relative imports from working. See the documentation of import for more details.

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

No branches or pull requests

8 participants