94
def get_standard_plugins_path():
95
"""Determine a plugin path suitable for general use."""
96
path = os.environ.get('BZR_PLUGIN_PATH',
97
get_default_plugin_path()).split(os.pathsep)
98
# Get rid of trailing slashes, since Python can't handle them when
99
# it tries to import modules.
100
path = map(_strip_trailing_sep, path)
98
def _append_new_path(paths, new_path):
99
"""Append a new path if it set and not already known."""
100
if new_path is not None and new_path not in paths:
101
paths.append(new_path)
105
def get_core_plugin_path():
101
107
bzr_exe = bool(getattr(sys, 'frozen', None))
102
108
if bzr_exe: # expand path for bzr.exe
103
109
# We need to use relative path to system-wide plugin
110
116
# then plugins directory is
111
117
# C:\Program Files\Bazaar\plugins
112
118
# so relative path is ../../../plugins
113
path.append(osutils.abspath(osutils.pathjoin(
114
osutils.dirname(__file__), '../../../plugins')))
115
if not bzr_exe: # don't look inside library.zip
119
core_path = osutils.abspath(osutils.pathjoin(
120
osutils.dirname(__file__), '../../../plugins'))
121
else: # don't look inside library.zip
116
122
# search the plugin path before the bzrlib installed dir
117
path.append(os.path.dirname(_mod_plugins.__file__))
118
# search the arch independent path if we can determine that and
119
# the plugin is found nowhere else
120
if sys.platform != 'win32':
122
from distutils.sysconfig import get_python_lib
124
# If distutuils is not available, we just won't add that path
127
archless_path = osutils.pathjoin(get_python_lib(), 'bzrlib',
129
if archless_path not in path:
130
path.append(archless_path)
123
core_path = os.path.dirname(_mod_plugins.__file__)
127
def get_site_plugin_path():
128
"""Returns the path for the site installed plugins."""
129
if sys.platform == 'win32':
130
# We don't have (yet) a good answer for windows since that is certainly
131
# related to the way we build the installers. -- vila20090821
135
from distutils.sysconfig import get_python_lib
137
# If distutuils is not available, we just don't know where they are
140
site_path = osutils.pathjoin(get_python_lib(), 'bzrlib', 'plugins')
144
def get_user_plugin_path():
145
return osutils.pathjoin(config.config_dir(), 'plugins')
148
def get_standard_plugins_path():
149
"""Determine a plugin path suitable for general use."""
150
# Ad-Hoc default: core is not overriden by site but user can overrides both
151
# The rationale is that:
152
# - 'site' comes last, because these plugins should always be available and
153
# are supposed to be in sync with the bzr installed on site.
154
# - 'core' comes before 'site' so that running bzr from sources or a user
155
# installed version overrides the site version.
156
# - 'user' comes first, because... user is always right.
157
# - the above rules clearly defines which plugin version will be loaded if
158
# several exist. Yet, it is sometimes desirable to disable some directory
159
# so that a set of plugins is disabled as once. This can be done via
160
# -site, -core, -user.
162
env_paths = os.environ.get('BZR_PLUGIN_PATH', '+user').split(os.pathsep)
163
defaults = ['+core', '+site']
165
# The predefined references
166
refs = dict(core=get_core_plugin_path(),
167
site=get_site_plugin_path(),
168
user=get_user_plugin_path())
170
# Unset paths that should be removed
171
for k,v in refs.iteritems():
173
# defaults can never mention removing paths as that will make it
174
# impossible for the user to revoke these removals.
175
if removed in env_paths:
176
env_paths.remove(removed)
181
for p in env_paths + defaults:
182
if p.startswith('+'):
183
# Resolve reference if they are known
187
# Leave them untouched otherwise, user may have paths starting
190
_append_new_path(paths, p)
192
# Get rid of trailing slashes, since Python can't handle them when
193
# it tries to import modules.
194
paths = map(_strip_trailing_sep, paths)
134
198
def load_plugins(path=None):