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