Patchwork [5,of,6] setup: show how to set the module policy for imports

login
register
mail settings
Submitter timeless@mozdev.org
Date March 8, 2016, 5:33 a.m.
Message ID <e907f1a7b27764981a18.1457415203@waste.org>
Download mbox | patch
Permalink /patch/13668/
State Superseded
Commit a7e3b72cf7562cd6167c537b8cbd93adb06a6527
Headers show

Comments

timeless@mozdev.org - March 8, 2016, 5:33 a.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1452573929 0
#      Tue Jan 12 04:45:29 2016 +0000
# Node ID e907f1a7b27764981a1858c2d32396f34230439d
# Parent  6f8152b11dc36ea701c8a6a247cd3bbed4c53ca1
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.

Patch

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