Rev 4633: Fixes prompted by review. in file:///home/vila/src/bzr/bugs/412930-plugin-path/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Aug 21 10:19:11 BST 2009


At file:///home/vila/src/bzr/bugs/412930-plugin-path/

------------------------------------------------------------
revno: 4633
revision-id: v.ladeuil+lp at free.fr-20090821091911-hatou4w3xz99prlp
parent: v.ladeuil+lp at free.fr-20090820132946-gqkb7ewet7oihw1a
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 412930-plugin-path
timestamp: Fri 2009-08-21 11:19:11 +0200
message:
  Fixes prompted by review.
  
  * bzrlib/tests/test_plugins.py:
  (TestEnvPluginPath.test_duplicates_are_removed): Check that paths
  are clean.
  (TestEnvPluginPath.test_bogus_references): Check robustness.
  
  * bzrlib/plugin.py:
  (get_site_plugin_path): Windows has no idea of a 'site' directory.
  (get_standard_plugins_path): Simplified.
  
  * bzrlib/help_topics/en/configuration.txt: 
  Fix typos and bad grammar.
-------------- next part --------------
=== modified file 'bzrlib/help_topics/en/configuration.txt'
--- a/bzrlib/help_topics/en/configuration.txt	2009-08-20 13:26:36 +0000
+++ b/bzrlib/help_topics/en/configuration.txt	2009-08-21 09:19:11 +0000
@@ -65,12 +65,12 @@
 The path to the plugins directory that Bazaar should use.
 If not set, Bazaar will search for plugins in:
 
-* the user specific plugin directory (containing the user plugins),
-
-* the bzrlib directory (containing the core plugins),
-
-* the size specific plugin directory if applicable (containing
-  the site plugins).
+* the user specific plugin directory (containing the ``user`` plugins),
+
+* the bzrlib directory (containing the ``core`` plugins),
+
+* the site specific plugin directory if applicable (containing
+  the ``site`` plugins).
 
 If ``BZR_PLUGIN_PATH`` is set in any fashion, it will change the
 the way the plugin are searched. 
@@ -80,8 +80,9 @@
 platform specific appropriate character (':' on Unix/Linux/etc,
 ';' on windows)
 
-By default all directories specified in ``BZR_PLUGIN_PATH``
-replace 'user' in the but keep searching in 'core' then 'site'.
+By default if ``BZR_PLUGIN_PATH`` is set, it replaces searching
+in ``user``.  However it will continue to search in ``core`` and
+``site`` unless they are explicitly removed.
 
 If you need to change the order or remove one of these
 directories, you should use special values:

=== modified file 'bzrlib/plugin.py'
--- a/bzrlib/plugin.py	2009-08-20 13:29:46 +0000
+++ b/bzrlib/plugin.py	2009-08-21 09:19:11 +0000
@@ -52,7 +52,10 @@
 from bzrlib import plugins as _mod_plugins
 """)
 
-from bzrlib.symbol_versioning import deprecated_function
+from bzrlib.symbol_versioning import (
+    deprecated_function,
+    deprecated_in,
+    )
 
 
 DEFAULT_PLUGIN_PATH = None
@@ -123,6 +126,10 @@
 
 def get_site_plugin_path():
     """Returns the path for the site installed plugins."""
+    if sys.platform == 'win32':
+        # We don't have (yet) a good answer for windows since that is certainly
+        # related to the way we build the installers. -- vila20090821
+        return None
     site_path = None
     try:
         from distutils.sysconfig import get_python_lib
@@ -160,41 +167,27 @@
                 site=get_site_plugin_path(),
                 user=get_user_plugin_path())
 
-    # Handle removals first
-    def unset_ref(p):
-        if p.startswith('-'):
-            key = p[1:]
-            if key in refs: # Needed to handle multiple removals
-                refs[key] = None
-                p = None
-        return p
-
-    defaults = [p for p in defaults if unset_ref(p) is not None]
-    env_paths = [p for p in env_paths if unset_ref(p) is not None]
-
-    for k, v in refs.iteritems():
-        added = '+%s' % k
-        if v is None:
-            # References removed can't be used anymore
-            if added in env_paths:
-                env_paths.remove(added)
-            if added in defaults:
-                defaults.remove(added)
-        else:
-            # Explicit beats implicit
-            if added in env_paths and added in defaults:
-                defaults.remove(added)
-
-    # Append the remaining defaults
-    paths = env_paths + defaults
-
-    # Resolve references
-    def resolve_ref(p):
-        if p.startswith('+') and refs.get(p[1:], None) is not None:
-            p = refs[p[1:]]
-        return p
-
-    paths = [resolve_ref(p) for p in paths]
+    # Unset paths that should be removed
+    for k,v in refs.iteritems():
+        removed = '-%s' % k
+        # defaults can never mention removing paths as that will make it
+        # impossible for the user to revoke these removals.
+        if removed in env_paths:
+            env_paths.remove(removed)
+            refs[k] = None
+
+    # Expand references
+    paths = []
+    for p in env_paths + defaults:
+        if p.startswith('+'):
+            # Resolve reference if they are known
+            try:
+                p = refs[p[1:]]
+            except KeyError:
+                # Leave them untouched otherwise, user may have paths starting
+                # with '+'...
+                pass
+        _append_new_path(paths, p)
 
     # Get rid of trailing slashes, since Python can't handle them when
     # it tries to import modules.

=== modified file 'bzrlib/tests/test_plugins.py'
--- a/bzrlib/tests/test_plugins.py	2009-08-20 13:26:36 +0000
+++ b/bzrlib/tests/test_plugins.py	2009-08-21 09:19:11 +0000
@@ -692,6 +692,16 @@
         # Ensures multiple removals don't left cruft
         self.check_path([self.core, self.site], ['-user', '-user'])
 
+    def test_duplicates_are_removed(self):
+        self.check_path([self.user, self.core, self.site],
+                        ['+user', '+user'])
+        # And only the first reference is kept (since the later references will
+        # onnly produce <plugin> already loaded mutters)
+        self.check_path([self.user, self.core, self.site],
+                        ['+user', '+user', '+core',
+                         '+user', '+site', '+site',
+                         '+core'])
+
     def test_disable_overrides_disable(self):
         self.check_path([self.core, self.site], ['-user', '+user'])
 
@@ -722,3 +732,6 @@
         self.check_path(['myplugin', self.core, self.site, self.user],
                         ['myplugin', '+core', '+site', '+user'])
 
+    def test_bogus_references(self):
+        self.check_path(['+foo', '-bar', self.core, self.site],
+                        ['+foo', '-bar'])



More information about the bazaar-commits mailing list