73
73
Future calls to load_plugins() will be ignored.
75
# TODO: jam 20060131 This should probably also disable
81
78
def _strip_trailing_sep(path):
82
79
return path.rstrip("\\/")
85
def set_plugins_path():
86
"""Set the path for plugins to be loaded from."""
82
def set_plugins_path(path=None):
83
"""Set the path for plugins to be loaded from.
85
:param path: The list of paths to search for plugins. By default,
86
path will be determined using get_standard_plugins_path.
87
if path is [], no plugins can be loaded.
90
path = get_standard_plugins_path()
91
_mod_plugins.__path__ = path
95
def get_standard_plugins_path():
96
"""Determine a plugin path suitable for general use."""
87
97
path = os.environ.get('BZR_PLUGIN_PATH',
88
98
get_default_plugin_path()).split(os.pathsep)
99
# Get rid of trailing slashes, since Python can't handle them when
100
# it tries to import modules.
101
path = map(_strip_trailing_sep, path)
89
102
bzr_exe = bool(getattr(sys, 'frozen', None))
90
103
if bzr_exe: # expand path for bzr.exe
91
104
# We need to use relative path to system-wide plugin
100
113
# so relative path is ../../../plugins
101
114
path.append(osutils.abspath(osutils.pathjoin(
102
115
osutils.dirname(__file__), '../../../plugins')))
103
# Get rid of trailing slashes, since Python can't handle them when
104
# it tries to import modules.
105
path = map(_strip_trailing_sep, path)
106
116
if not bzr_exe: # don't look inside library.zip
107
117
# search the plugin path before the bzrlib installed dir
108
118
path.append(os.path.dirname(_mod_plugins.__file__))
120
130
if archless_path not in path:
121
131
path.append(archless_path)
122
_mod_plugins.__path__ = path
135
def load_plugins(path=None):
127
136
"""Load bzrlib plugins.
129
138
The environment variable BZR_PLUGIN_PATH is considered a delimited
134
143
load_from_dirs() provides the underlying mechanism and is called with
135
144
the default directory list to provide the normal behaviour.
146
:param path: The list of paths to search for plugins. By default,
147
path will be determined using get_standard_plugins_path.
148
if path is [], no plugins can be loaded.