changeset 680:703f33576ad8

svnwrap: add runtime override for choice of Subversion bindings By setting the `HGSUBVERSION_BINDINGS environment variable to either `SWIG' or `Subvertpy', the choice of bindings can be forced at runtime. (For ease of use, the comparison is case-insensitive.) Examples: % HGSUBVERSION_BINDINGS=swig hg version --svn Mercurial Distributed SCM (version 1.6+172-b25e1ced9861) ... hgsubversion: 1.1.2+43-276742da2d85 Subversion: 1.6.12 bindings: SWIG % HGSUBVERSION_BINDINGS=subvertpy hg version --svn Mercurial Distributed SCM (version 1.6+172-b25e1ced9861) ... hgsubversion: 1.1.2+43-276742da2d85 Subversion: 1.6.12 bindings: Subvertpy 0.7.4 % HGSUBVERSION_BINDINGS=none hg version --svn Mercurial Distributed SCM (version 1.6+172-b25e1ced9861) ... abort: cannot use hgsubversion; bindings disabled using HGSUBVERSION_BINDINGS!
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Wed, 11 Aug 2010 20:03:47 +0200
parents 0b4e323ebedd
children 26b85c0cf48a
files hgsubversion/help/subversion.rst hgsubversion/svnwrap/__init__.py
diffstat 2 files changed, 29 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/help/subversion.rst
+++ b/hgsubversion/help/subversion.rst
@@ -178,3 +178,11 @@ Please note that some of these options m
 as well, and when done so, will override the configuration. If an authormap,
 filemap or branchmap is specified, its contents will be read and stored for use
 in future pulls.
+
+Finally, the following environment variables can be used for testing a
+deployment of hgsubversion:
+
+  HGSUBVERSION_BINDINGS
+    By default, hgsubversion will use Subvertpy, but fall back to the SWIG
+    bindings. Set this variable to either ``SWIG`` or ``Subvertpy`` (case-
+    insensitive) to force that set of bindings.
--- a/hgsubversion/svnwrap/__init__.py
+++ b/hgsubversion/svnwrap/__init__.py
@@ -8,11 +8,26 @@ present.
 
 from common import *
 
-try:
+import os
+
+choice = os.environ.get('HGSUBVERSION_BINDINGS', '').lower()
+
+if choice == 'subvertpy':
     from subvertpy_wrapper import *
-except ImportError, e:
+elif choice == 'swig':
+    from svn_swig_wrapper import *
+elif choice == 'none':
+    # useful for verifying that demandimport works properly
+    raise ImportError('cannot use hgsubversion; '
+                      'bindings disabled using HGSUBVERSION_BINDINGS')
+else:
     try:
-        from svn_swig_wrapper import *
-    except ImportError:
-        # propagate the subvertpy error; it's easier to install
-        import subvertpy_wrapper
+        from subvertpy_wrapper import *
+    except ImportError, e:
+        try:
+            from svn_swig_wrapper import *
+        except ImportError:
+            # propagate the subvertpy error; it's easier to install
+            raise e
+
+del os, choice