bzr doesn't work in parent directories of python packages with certain names

Bug #304891 reported by Wesley J. Landaker
2
Affects Status Importance Assigned to Milestone
Bazaar
New
Undecided
Unassigned

Bug Description

It shouldn't be surprising that I use bzr a lot on python projects. However, bzr becomes unusable as soon as some sub-package of my project has a name that bzr doesn't like.

For example, say I have my own "codecs" python subpackage:

$ mkdir -p src/libmyapp/tools/codecs
$ cd src/libmyapp
$ touch codecs/__init__.py
$ bzr add
Traceback (most recent call last):
  File "/usr/bin/bzr", line 79, in <module>
    import locale
  File "/usr/lib/python2.5/locale.py", line 14, in <module>
    import sys, encodings, encodings.aliases
  File "/usr/lib/python2.5/encodings/__init__.py", line 32, in <module>
    from encodings import aliases
ImportError: cannot import name aliases

Or if the package is named bisect instead:
cannot import name bisect_right
Unable to load plugin 'search' from '/usr/lib/python2.5/site-packages/bzrlib/plugins'
cannot import name bisect_right
Unable to load plugin 'loom' from '/usr/lib/python2.5/site-packages/bzrlib/plugins'
cannot import name bisect_right
Unable to load plugin 'launchpad' from '/usr/lib/python2.5/site-packages/bzrlib/plugins'
cannot import name bisect_right
Unable to load plugin 'cvsps_import' from '/usr/lib/python2.5/site-packages/bzrlib/plugins'
bzr: ERROR: exceptions.ImportError: cannot import name bisect_right

Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/bzrlib/commands.py", line 893, in run_bzr_catch_errors
    return run_bzr(argv)
  File "/usr/lib/python2.5/site-packages/bzrlib/commands.py", line 839, in run_bzr
    ret = run(*run_argv)
  File "/usr/lib/python2.5/site-packages/bzrlib/commands.py", line 539, in run_argv_aliases
    return self.run(**all_cmd_args)
  File "/usr/lib/python2.5/site-packages/bzrlib/builtins.py", line 497, in run
    tree = WorkingTree.open_containing(u'.')[0]
  File "/usr/lib/python2.5/site-packages/bzrlib/workingtree.py", line 325, in open_containing
    control, relpath = bzrdir.BzrDir.open_containing(path)
  File "/usr/lib/python2.5/site-packages/bzrlib/bzrdir.py", line 828, in open_containing
    return BzrDir.open_containing_from_transport(transport)
  File "/usr/lib/python2.5/site-packages/bzrlib/bzrdir.py", line 849, in open_containing_from_transport
    result = BzrDir.open_from_transport(a_transport)
  File "/usr/lib/python2.5/site-packages/bzrlib/bzrdir.py", line 803, in open_from_transport
    redirected)
  File "/usr/lib/python2.5/site-packages/bzrlib/lazy_import.py", line 125, in __call__
    return obj(*args, **kwargs)
  File "/usr/lib/python2.5/site-packages/bzrlib/transport/__init__.py", line 1634, in do_catching_redirections
    return action(transport)
  File "/usr/lib/python2.5/site-packages/bzrlib/bzrdir.py", line 780, in find_format
    transport, _server_formats=_server_formats)
  File "/usr/lib/python2.5/site-packages/bzrlib/bzrdir.py", line 1634, in find_format
    return format.probe_transport(transport)
  File "/usr/lib/python2.5/site-packages/bzrlib/plugins/svn/format.py", line 71, in probe_transport
    format = klass()
  File "/usr/lib/python2.5/site-packages/bzrlib/plugins/svn/format.py", line 64, in __init__
    from bzrlib.plugins.svn.repository import SvnRepositoryFormat
  File "/usr/lib/python2.5/site-packages/bzrlib/plugins/svn/repository.py", line 19, in <module>
    from bzrlib.branch import BranchCheckResult
  File "/usr/lib/python2.5/site-packages/bzrlib/branch.py", line 1466, in <module>
    __format7 = BzrBranchFormat7()
  File "/usr/lib/python2.5/site-packages/bzrlib/branch.py", line 1369, in __init__
    RepositoryFormatKnitPack5RichRoot()
  File "/usr/lib/python2.5/site-packages/bzrlib/lazy_import.py", line 122, in __call__
    obj = _replace()
  File "/usr/lib/python2.5/site-packages/bzrlib/lazy_import.py", line 89, in _replace
    obj = factory(self, scope, name)
  File "/usr/lib/python2.5/site-packages/bzrlib/lazy_import.py", line 192, in _import
    module = __import__(module_python_path, scope, scope, [member])
  File "/usr/lib/python2.5/site-packages/bzrlib/repofmt/pack_repo.py", line 57, in <module>
    from bzrlib.btree_index import (
  File "/usr/lib/python2.5/site-packages/bzrlib/btree_index.py", line 22, in <module>
    from bisect import bisect_right
ImportError: cannot import name bisect_right

bzr 1.9 on python 2.5.2 (linux2)
arguments: ['/usr/bin/bzr', 'add']
encoding: 'UTF-8', fsenc: 'UTF-8', lang: 'en_US.UTF-8'
plugins:
  bzrtools /usr/lib/python2.5/site-packages/bzrlib/plugins/bzrtools [1.9.1]
  gtk /usr/lib/python2.5/site-packages/bzrlib/plugins/gtk [0.96.0dev1]
  rebase /usr/lib/python2.5/site-packages/bzrlib/plugins/rebase [0.4.1]
  stats /usr/lib/python2.5/site-packages/bzrlib/plugins/stats [unknown]
  svn /usr/lib/python2.5/site-packages/bzrlib/plugins/svn [0.4.15dev0]
  upload /usr/lib/python2.5/site-packages/bzrlib/plugins/upload [0.1.0]
*** Bazaar has encountered an internal error.
    Please report a bug at https://bugs.launchpad.net/bzr/+filebug
    including this traceback, and a description of what you
    were doing when the error occurred.

This happens with LOTS of names, and depending on what the conflict is it may or may not show up except with certain commands, etc. It's really annoying and makes bzr feel very fragile.

I realize this is happening because bzr is implemented in python, and so it's trying to import the subpackages in the current directory. The workaround is to move up or down in the heirarchy and run bzr command from there. But this is really lame, because as a bzr user, bzr should act just like svn or git, and be able to version any times of files, and not have implementation details (i.e. bzr written in python) screw up using it. The worst irony is that if I wasn't writing python programs, I wouldn't run into this.

Revision history for this message
Vincent Ladeuil (vila) wrote :

This is a duplicate, but your use case makes it really painful :-/

Revision history for this message
Wouter van Heyst (larstiq) wrote :

Wesley, can you check that something like Forest explains in the dupe (bug #72227) isn't going on?
PYTHONPATH="foo:$PYTHONPATH" with PYTHONPATH previously being empty.

If not, what python version/distro are you using? Debian Lenny 2.5 and Ubuntu Jaunty 2.6 don't seem to have '' on the path, we'd like to know if there are any pythons in the wild that add '' to sys.path other than in the documented case of not knowing the script directory, which shouldn't happen for bzr.

  http://docs.python.org/library/sys.html#sys.path

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.