Rev 6076: (vila) ModuleAvailableFeature don't try to imported already imported in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Aug 17 08:40:26 UTC 2011


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6076 [merge]
revision-id: pqm at pqm.ubuntu.com-20110817084016-600z65qzqmmt44w7
parent: pqm at pqm.ubuntu.com-20110817053442-pz1w7iw2w0w78ewy
parent: v.ladeuil+lp at free.fr-20110816151934-pjl5vt95uotmizqn
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2011-08-17 08:40:16 +0000
message:
  (vila) ModuleAvailableFeature don't try to imported already imported
   modules. (Vincent Ladeuil)
modified:
  bzrlib/tests/features.py       features.py-20090820042958-jglgza3wrn03ha9e-1
  doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/tests/features.py'
--- a/bzrlib/tests/features.py	2011-08-11 10:09:27 +0000
+++ b/bzrlib/tests/features.py	2011-08-16 14:14:39 +0000
@@ -166,11 +166,17 @@
         self.module_name = module_name
 
     def _probe(self):
-        try:
-            self._module = __import__(self.module_name, {}, {}, [''])
+        sentinel = object()
+        module = sys.modules.get(self.module_name, sentinel)
+        if module is sentinel:
+            try:
+                self._module = __import__(self.module_name, {}, {}, [''])
+                return True
+            except ImportError:
+                return False
+        else:
+            self._module = module
             return True
-        except ImportError:
-            return False
 
     @property
     def module(self):

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2011-08-16 09:33:16 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2011-08-17 08:40:16 +0000
@@ -196,6 +196,10 @@
 * ``LockDir`` can now be run when the local hostname is ``localhost``.
   (Jelmer Vernooij, #825994)
 
+* ``ModuleAvailableFeature`` won't try to import already imported modules,
+  allowing it to be used for modules with side-effects.
+  (Vincent Ladeuil, #712474)
+
 * `TestCaseWithMemoryTransport` is faster now: `_check_safety_net` now
   just compares the bytes in the dirstate file to its pristine state,
   rather than opening the WorkingTree and calling ``last_revision()``.




More information about the bazaar-commits mailing list