pth file overrides pythonpath

Bug #796992 reported by Martin Pool
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
lazr.restfulclient (Ubuntu)
Fix Released
High
Unassigned

Bug Description

python-lazr.restfulclient on natty installs /usr/share/pyshared/lazr.restfulclient-0.11.1-nspkg.pth with these contents:

import sys,types,os; p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('lazr',)); ie = os.path.exists(os.path.join(p,'__init__.py')); m = not ie and sys.modules.setdefault('lazr',types.ModuleType('lazr')); mp = (m or []) and m.__dict__.setdefault('__path__',[]); (p not in mp) and mp.append(p)

This has at least three consequences:

1- if you have a different lazr.restfulclient module earlier on your PYTHONPATH, for instance if you're trying to fix a bug in it, you still get the installed version:

PYTHONPATH=~/src/lazr.restfulclient/src/ python -c 'import lazr.restfulclient;print lazr.restfulclient'
<module 'lazr.restfulclient' from '/usr/lib/python2.7/dist-packages/lazr/restfulclient/__init__.pyc'>

This is inconsistent with other Python modules.

2- Bizarrely, lazr looks like a built-in module:
% PYTHONPATH=~/src/lazr.restfulclient/src/ python -c 'import lazr;print lazr'
<module 'lazr' (built-in)>

3- The lazr module will be loaded every time Python is started, whether it is wanted or not, which is a (perhaps small) waste of time:

% python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.modules['lazr']
<module 'lazr' (built-in)>

Is this really necessary just to make a namespace package?

Martin Pool (mbp)
Changed in lazr.restfulclient (Ubuntu):
importance: Undecided → High
status: New → Triaged
Revision history for this message
Martin Pool (mbp) wrote :

This also seems closely related to <http://comments.gmane.org/gmane.comp.version-control.bazaar-ng.general/72378>

   /usr/lib/python2.6/dist-packages/lazr/restfulclient/__init__.py:19: UserWarning: Module paste
was already imported from None, but /usr/lib/python2.6/dist-packages is being added to sys.path
          import pkg_resources

Revision history for this message
Martin Pool (mbp) wrote :

Jelmer suggests this might be different between python-central and python-support, and perhaps this is actually easier to fix on lucid (or not present on lucid) than on later series. Maybe we should migrate it to dh_python2.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package lazr.restfulclient - 0.13.1-1

---------------
lazr.restfulclient (0.13.1-1) experimental; urgency=low

  * New upstream release.
     - Now cache-safe for concurrent clients.
  * Upload to experimental, as we are in freeze.
  * Get rid of .pth files, dh_python2's namespace support is sufficient.
    (LP: #796992, #583426)
  * Depend on python-lazr.uri. (LP: #876445)
  * Update watch file to work with secure LP urls for the tarballs.
  * Bump Standards-Version to 3.9.4, no changes needed.
  * Bump machine readable copyright format to 1.0, no changes needed.
  * Updated copyright years.

 -- Stefano Rivera <email address hidden> Tue, 06 Nov 2012 11:53:59 +0200

Changed in lazr.restfulclient (Ubuntu):
status: Triaged → Fix Released
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.