Rev 3841: (abentley) Give bzrlib clients more control over plugin loading in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Nov 19 07:55:32 GMT 2008
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 3841
revision-id: pqm at pqm.ubuntu.com-20081119075529-9c4jtbifm0igp3vf
parent: pqm at pqm.ubuntu.com-20081118222130-vczdog5my1bc6ta4
parent: aaron at aaronbentley.com-20081115194137-wghezl9da7aluk3p
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2008-11-19 07:55:29 +0000
message:
(abentley) Give bzrlib clients more control over plugin loading
modified:
bzrlib/__init__.py __init__.py-20050309040759-33e65acf91bbcd5d
bzrlib/plugin.py plugin.py-20050622060424-829b654519533d69
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/test_plugins.py plugins.py-20050622075746-32002b55e5e943e9
------------------------------------------------------------
revno: 3835.2.7
revision-id: aaron at aaronbentley.com-20081115194137-wghezl9da7aluk3p
parent: aaron at aaronbentley.com-20081115184313-targ6r7bkut2aslq
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: control-plugin-path
timestamp: Sat 2008-11-15 14:41:37 -0500
message:
Add tests for plugins
modified:
bzrlib/plugin.py plugin.py-20050622060424-829b654519533d69
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/test_plugins.py plugins.py-20050622075746-32002b55e5e943e9
------------------------------------------------------------
revno: 3835.2.6
revision-id: aaron at aaronbentley.com-20081115184313-targ6r7bkut2aslq
parent: aaron at aaronbentley.com-20081113202626-yvxt9hjoflmtgsw3
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: control-plugin-path
timestamp: Sat 2008-11-15 13:43:13 -0500
message:
Restore vila's colordiff change
modified:
bzrlib/shelf_ui.py shelver.py-20081005210102-33worgzwrtdw0yrm-1
------------------------------------------------------------
revno: 3835.2.5
revision-id: aaron at aaronbentley.com-20081113202626-yvxt9hjoflmtgsw3
parent: aaron at aaronbentley.com-20081113201950-w3a98jl6d13z7sfe
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: control-plugin-path
timestamp: Thu 2008-11-13 15:26:26 -0500
message:
Simplify disable_plugins implementation
modified:
bzrlib/plugin.py plugin.py-20050622060424-829b654519533d69
------------------------------------------------------------
revno: 3835.2.4
revision-id: aaron at aaronbentley.com-20081113201950-w3a98jl6d13z7sfe
parent: aaron at aaronbentley.com-20081113193842-v53xoga2fecdcc35
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: control-plugin-path
timestamp: Thu 2008-11-13 15:19:50 -0500
message:
Allow paths to be specified to load_plugins
modified:
bzrlib/plugin.py plugin.py-20050622060424-829b654519533d69
------------------------------------------------------------
revno: 3835.2.3
revision-id: aaron at aaronbentley.com-20081113193842-v53xoga2fecdcc35
parent: aaron at aaronbentley.com-20081113193651-lvdru0153lrugo6u
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: control-plugin-path
timestamp: Thu 2008-11-13 14:38:42 -0500
message:
Revert vila's colordiff change.
modified:
bzrlib/shelf_ui.py shelver.py-20081005210102-33worgzwrtdw0yrm-1
------------------------------------------------------------
revno: 3835.2.2
revision-id: aaron at aaronbentley.com-20081113193651-lvdru0153lrugo6u
parent: aaron at aaronbentley.com-20081113175419-cbc89ihcue8zum0h
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: control-plugin-path
timestamp: Thu 2008-11-13 14:36:51 -0500
message:
Allow specifying plugin paths, disable co-installed plugins.
modified:
bzrlib/plugin.py plugin.py-20050622060424-829b654519533d69
------------------------------------------------------------
revno: 3835.2.1
revision-id: aaron at aaronbentley.com-20081113175419-cbc89ihcue8zum0h
parent: pqm at pqm.ubuntu.com-20081113075004-skgl7ma39awgyjze
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: control-plugin-path
timestamp: Thu 2008-11-13 12:54:19 -0500
message:
Stop automagically setting plugins patch on importing bzrlib
modified:
bzrlib/__init__.py __init__.py-20050309040759-33e65acf91bbcd5d
=== modified file 'bzrlib/__init__.py'
--- a/bzrlib/__init__.py 2008-11-11 00:57:17 +0000
+++ b/bzrlib/__init__.py 2008-11-13 17:54:19 +0000
@@ -108,11 +108,6 @@
version_string = __version__
-# allow bzrlib plugins to be imported.
-import bzrlib.plugin
-bzrlib.plugin.set_plugins_path()
-
-
def test_suite():
import tests
return tests.test_suite()
=== modified file 'bzrlib/plugin.py'
--- a/bzrlib/plugin.py 2008-11-03 21:16:53 +0000
+++ b/bzrlib/plugin.py 2008-11-15 19:41:37 +0000
@@ -72,20 +72,33 @@
Future calls to load_plugins() will be ignored.
"""
- # TODO: jam 20060131 This should probably also disable
- # load_from_dirs()
- global _loaded
- _loaded = True
+ load_plugins([])
def _strip_trailing_sep(path):
return path.rstrip("\\/")
-def set_plugins_path():
- """Set the path for plugins to be loaded from."""
+def set_plugins_path(path=None):
+ """Set the path for plugins to be loaded from.
+
+ :param path: The list of paths to search for plugins. By default,
+ path will be determined using get_standard_plugins_path.
+ if path is [], no plugins can be loaded.
+ """
+ if path is None:
+ path = get_standard_plugins_path()
+ _mod_plugins.__path__ = path
+ return path
+
+
+def get_standard_plugins_path():
+ """Determine a plugin path suitable for general use."""
path = os.environ.get('BZR_PLUGIN_PATH',
get_default_plugin_path()).split(os.pathsep)
+ # Get rid of trailing slashes, since Python can't handle them when
+ # it tries to import modules.
+ path = map(_strip_trailing_sep, path)
bzr_exe = bool(getattr(sys, 'frozen', None))
if bzr_exe: # expand path for bzr.exe
# We need to use relative path to system-wide plugin
@@ -100,9 +113,6 @@
# so relative path is ../../../plugins
path.append(osutils.abspath(osutils.pathjoin(
osutils.dirname(__file__), '../../../plugins')))
- # Get rid of trailing slashes, since Python can't handle them when
- # it tries to import modules.
- path = map(_strip_trailing_sep, path)
if not bzr_exe: # don't look inside library.zip
# search the plugin path before the bzrlib installed dir
path.append(os.path.dirname(_mod_plugins.__file__))
@@ -119,11 +129,10 @@
'plugins')
if archless_path not in path:
path.append(archless_path)
- _mod_plugins.__path__ = path
return path
-def load_plugins():
+def load_plugins(path=None):
"""Load bzrlib plugins.
The environment variable BZR_PLUGIN_PATH is considered a delimited
@@ -133,6 +142,10 @@
load_from_dirs() provides the underlying mechanism and is called with
the default directory list to provide the normal behaviour.
+
+ :param path: The list of paths to search for plugins. By default,
+ path will be determined using get_standard_plugins_path.
+ if path is [], no plugins can be loaded.
"""
global _loaded
if _loaded:
@@ -141,7 +154,7 @@
_loaded = True
# scan for all plugins in the path.
- load_from_path(set_plugins_path())
+ load_from_path(set_plugins_path(path))
def load_from_path(dirs):
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2008-11-11 04:13:12 +0000
+++ b/bzrlib/tests/__init__.py 2008-11-15 19:41:37 +0000
@@ -1235,6 +1235,7 @@
'EMAIL': None,
'BZR_PROGRESS_BAR': None,
'BZR_LOG': None,
+ 'BZR_PLUGIN_PATH': None,
# SSH Agent
'SSH_AUTH_SOCK': None,
# Proxies
=== modified file 'bzrlib/tests/test_plugins.py'
--- a/bzrlib/tests/test_plugins.py 2008-11-03 21:16:53 +0000
+++ b/bzrlib/tests/test_plugins.py 2008-11-15 19:41:37 +0000
@@ -629,3 +629,66 @@
mod = FakeModule('two lines of help\nand more', 'bzrlib.plugins.foo_bar')
topic = plugin.ModuleHelpTopic(mod)
self.assertEqual('foo_bar', topic.get_help_topic())
+
+
+def clear_plugins(test_case):
+ old_plugins_path = bzrlib.plugins.__path__
+ bzrlib.plugins.__path__ = []
+ plugin._loaded = False
+ def restore_plugins():
+ bzrlib.plugins.__path__ = old_plugins_path
+ plugin._loaded = False
+ test_case.addCleanup(restore_plugins)
+
+
+class TestPluginPaths(tests.TestCase):
+
+ def test_set_plugins_path_with_args(self):
+ clear_plugins(self)
+ plugin.set_plugins_path(['a', 'b'])
+ self.assertEqual(['a', 'b'], bzrlib.plugins.__path__)
+
+ def test_set_plugins_path_defaults(self):
+ clear_plugins(self)
+ plugin.set_plugins_path()
+ self.assertEqual(plugin.get_standard_plugins_path(),
+ bzrlib.plugins.__path__)
+
+ def test_get_standard_plugins_path(self):
+ path = plugin.get_standard_plugins_path()
+ self.assertEqual(plugin.get_default_plugin_path(), path[0])
+ for directory in path:
+ self.assertNotContainsRe(r'\\/$', directory)
+ try:
+ from distutils.sysconfig import get_python_lib
+ except ImportError:
+ pass
+ else:
+ if sys.platform != 'win32':
+ python_lib = get_python_lib()
+ for directory in path:
+ if directory.startswith(python_lib):
+ break
+ else:
+ self.fail('No path to global plugins')
+
+ def test_get_standard_plugins_path_env(self):
+ os.environ['BZR_PLUGIN_PATH'] = 'foo/'
+ self.assertEqual('foo', plugin.get_standard_plugins_path()[0])
+
+
+class TestLoadPlugins(tests.TestCaseInTempDir):
+
+ def test_load_plugins(self):
+ clear_plugins(self)
+ plugin.load_plugins(['.'])
+ self.assertEqual(bzrlib.plugins.__path__, ['.'])
+ # subsequent loads are no-ops
+ plugin.load_plugins(['foo'])
+ self.assertEqual(bzrlib.plugins.__path__, ['.'])
+
+ def test_load_plugins_default(self):
+ clear_plugins(self)
+ plugin.load_plugins()
+ path = plugin.get_standard_plugins_path()
+ self.assertEqual(path, bzrlib.plugins.__path__)
More information about the bazaar-commits
mailing list