mpenning / ciscoconfparse

Parse, Audit, Query, Build, and Modify Arista / Cisco / Juniper / Palo Alto / F5 configurations.
http://www.pennington.net/py/ciscoconfparse/
GNU General Public License v3.0
793 stars 220 forks source link

Relative module import name conflict #52

Closed optiz0r closed 6 years ago

optiz0r commented 8 years ago

I'd love to be able to use this module, but I have an unresolvable name conflict with an existing dns module. ciscoconfparse uses relative imports, and since my app is higher on the PYTHONPATH this means my dns module is being loaded in preference to the ciscoconfparse internal one.

>>> print "\n".join(sys.path)
/home/ben/projects/hdb/hdb
/usr/lib/entropy/lib
/home/ben/.virtualenvs/hdb/lib64/python27.zip
/home/ben/.virtualenvs/hdb/lib64/python2.7
/home/ben/.virtualenvs/hdb/lib64/python2.7/plat-linux2
/home/ben/.virtualenvs/hdb/lib64/python2.7/lib-tk
/home/ben/.virtualenvs/hdb/lib64/python2.7/lib-old
/home/ben/.virtualenvs/hdb/lib64/python2.7/lib-dynload
/usr/lib64/python2.7
/usr/lib/python2.7/plat-linux2
/usr/lib64/python2.7/lib-tk
/usr/lib/python2.7/lib-tk
/home/ben/.virtualenvs/hdb/lib/python2.7/site-packages

>>> from ciscoconfparse import CiscoConfParse
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/ben/.virtualenvs/hdb/lib/python2.7/site-packages/ciscoconfparse/__init__.py", line 1, in <module>
    from ciscoconfparse import *
  File "/home/ben/.virtualenvs/hdb/lib/python2.7/site-packages/ciscoconfparse/ciscoconfparse.py", line 11, in <module>
    from models_cisco import IOSHostnameLine, IOSRouteLine, IOSIntfLine
  File "/home/ben/.virtualenvs/hdb/lib/python2.7/site-packages/ciscoconfparse/models_cisco.py", line 5, in <module>
    from ccp_util import _IPV6_REGEX_STR_COMPRESSED1, _IPV6_REGEX_STR_COMPRESSED2
  File "/home/ben/.virtualenvs/hdb/lib/python2.7/site-packages/ciscoconfparse/ccp_util.py", line 8, in <module>
    from dns.exception import DNSException
ImportError: No module named exception

If ciscoconfparse used absolute imports instead, I think this problem could be avoided. Short of renaming the local module in my application (not simple), I don't think there's any way I can work around it without code changes in ciscoconfparse.

mpenning commented 6 years ago

You should use ciscoconfparse in a virtualenv that has the correct dns module.

optiz0r commented 6 years ago

FTR I ended up refactoring my own codebase so that instead of having a top-level package named dns I had prefix.dns.