Is there a way to determine the Bazaar directory programmatically? If there is a bazaar command to determine the plugin directory, this would be the best solution.
4 Answers
Bazaar plugins are searched for in the following directories:
* <pythonlib>/site-packages/bzrlib/plugins/
(where <pythonlib> is something like usr/lib/python2.4,
depending on your installation)
* $HOME/.bazaar/plugins/
You can set the bazaar plugins directory via BZR_PLUGIN_PATH
environement variable, also.
More on bazaar plugins: http://bazaar-vcs.org/BzrPlugins

- 181,842
- 47
- 306
- 310
According to the bazaar website,
user plugins are looked for in ~/.bazaar/plugins
by default, but may be overridden by the environment variable BZR_PLUGIN_PATH
.
So test if this variable is set, otherwise return the default. In python:
import os
user_plugin_path = os.environ.get('BZR_PLUGIN_PATH', '~/.bazaar/plugins')
Edit: this works for unix based systems, for windows the uses plugin path is $APPDATA/bazaar/2.0/plugins
.
The system wide plugin is in bzrlib/plugins
, see Installing a plugin down the page here. Use distutils
to get the prefix (e.g. /usr/lib/python2.4/site-packages/bzrlib/plugins/) :
from distutils.sysconfig import get_python_lib
global_plugin_path = os.path.join(get_python_lib(), 'bzrlib/plugins')
(Thanks to The MYYN for providing the other documentation page)

- 7,179
- 1
- 29
- 26
Have a look at the Bazaar configuration:
output of bzr version
. Also see function show_version
in bzrlib/version.py
.
For the configuration directory use:
from bzrlib import config
print config.config_dir()
Or, for the user plugin path (see bzrlib/plugin.py
):
from bzrlib import plugin
print plugin.get_user_plugin_path()
For a full list of plugin paths:
from bzrlib import plugin
print plugin.get_standard_plugins_path()

- 4,036
- 2
- 22
- 16
-
All three answers are correct and its difficult to choose which one is the most correct "answer", but i did need a way to get to the version via the bazaar command rather than the internal api. I didn't mention that i was using java not python to get this directory. So I'm going to have to mark this as the anwer :) – Craig Dec 07 '09 at 20:20
-
If you need this available as output of bzr command you can write very simple bzr plugin for this. – bialix Dec 08 '09 at 07:47
-
Or even just run python with the snippet I've provided. – bialix Dec 08 '09 at 07:48
-
I want to install the Bazaar xmloutput plugin when the user installs qbzr-eclipse plugin. So it might not be such a bad idea to run your python script as a Process from java and use the output to determine the path of the user's plugin directory – Craig Dec 08 '09 at 20:37
If you have bzr installed in your system you can use following Python snippet to get the list of directories where bzr looking for plugins:
>>> import os
>>> from bzrlib import plugin
>>> list_of_bzr_plugins_paths = [os.path.abspath(p)
for p in plugin.get_standard_plugins_path()]

- 20,053
- 8
- 46
- 63