[PATCH 6 of 7 v2] setup: show how to set the module policy for imports

timeless timeless at mozdev.org
Mon Jan 11 23:23:08 CST 2016


# HG changeset patch
# User timeless <timeless at mozdev.org>
# Date 1452573929 0
#      Tue Jan 12 04:45:29 2016 +0000
# Node ID dc89d0d3d9c1a422e0c2e2550d554357c54d7a2a
# Parent  21b17c69ea254cceefc474baabedd5a777278c8c
setup: show how to set the module policy for imports

This is not technically needed, since mercurial.__version__
does not exist as a native module, but, without this style wrappings,
if something else had a native flavor, the module loader would get
upset.

In principle, the `env` object is trying to set HGMODULEPOLICY for
children, so, conceptually we should set it for this in-process
child.

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -227,10 +227,17 @@
 
 
 try:
+    oldpolicy = os.environ.get('HGMODULEPOLICY', None)
+    os.environ['HGMODULEPOLICY'] = 'py'
     from mercurial import __version__
     version = __version__.version
 except ImportError:
     version = 'unknown'
+finally:
+    if oldpolicy is None:
+        del os.environ['HGMODULEPOLICY']
+    else:
+        os.environ['HGMODULEPOLICY'] = oldpolicy
 
 class hgbuild(build):
     # Insert hgbuildmo first so that files in mercurial/locale/ are found


More information about the Mercurial-devel mailing list