Import errors when using a local copy of launchpadlib in a package

Bug #254379 reported by Markus Korn
2
Affects Status Importance Assigned to Milestone
launchpadlib
Invalid
Undecided
Unassigned
wadllib
Invalid
Undecided
Unassigned

Bug Description

In a development environment I would like to use launchpadlib and wadllib within the following structure:

mysript.py
package/
   mymodule.py
   __init__.py
   launchpadlib/
      ....
      wadllib/
         ....

launchpadlib/ and wadllib/ are symlinks to local copies of the development branches.

Importing launchpadlib in mymodule.py results in various ImportErrors, like

---------------------------------------------------------------------------
<type 'exceptions.ImportError'> Traceback (most recent call last)

/media/disk-1/python-launchpad-bugs/launchpadlib.connector/<ipython console> in <module>()

/media/disk-1/python-launchpad-bugs/launchpadlib.connector/launchpadbugs/connector.py in __init__(self, method)
     71 class ConnectBug(LaunchpadConnector):
     72 def __init__(self, method=CONNECTOR.MODES.DEFAULT):
---> 73 LaunchpadConnector.__init__(self, "Bug", method)
     74
     75 def __call__(self, bug=None, url=None):

/media/disk-1/python-launchpad-bugs/launchpadlib.connector/launchpadbugs/connector.py in __init__(self, cls, method)
     33 ValueError
     34 try:
---> 35 mod_connection = __import__(connection_id[0], globals(), locals(), [], -1)
     36 except TypeError:
     37 mod_connection = __import__(connection_id[0], globals(), locals(), [])

/media/disk-1/python-launchpad-bugs/launchpadlib.connector/launchpadbugs/api_connection.py in <module>()
      2 from launchpadlib.credentials import Credentials
      3
      4 class APIConnection(object):
      5 def __init__(self):
      6 self.content_types = None

/media/disk-1/python-launchpad-bugs/launchpadlib.connector/launchpadlib/launchpad.py in <module>()

<type 'exceptions.ImportError'>: No module named launchpadlib._browser

Fixing this would allow me to use launchpadlib without systemwide installing or changing sys.path.

Markus

Revision history for this message
Markus Korn (thekorn) wrote :

I created two branches with proposed fixes for launchpadlib and wadllib

Revision history for this message
Barry Warsaw (barry) wrote :

I don't think this patch is a good idea. First, doing this kind of re-situating of a package is generaly frowned upon in the Python world. See specifically the extensive discussion surrounding PEP 328's absolute and relative imports.

More importantly, wrapping these imports in try/excepts is really just a bandaid on the problem. If you try to do this with any other packages, you'll find just as many similar problems.

It's much better to just use wadllib and launchpadlib as they're intended, as setuptools-based Python eggs. There are many solutions out there that would allow you to use the package as it's intended without having to install it system-wide or hacking sys.path. E.g. 'setup.py develop' and virtualenv.

Revision history for this message
Markus Korn (thekorn) wrote :

marking the tasks as invalid as using virtualenv or setup.py develop is a multible times better solution

Changed in launchpadlib:
status: New → Invalid
Changed in wadllib:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.