Patchwork [3,of,5] setup: move environment computation into a helper function

login
register
mail settings
Submitter Adam Simpkins
Date June 26, 2017, 6:37 p.m.
Message ID <f12d9578f43cc253f46a.1498502262@devbig125.prn1.facebook.com>
Download mbox | patch
Permalink /patch/21737/
State Accepted
Headers show

Comments

Adam Simpkins - June 26, 2017, 6:37 p.m.
# HG changeset patch
# User Adam Simpkins <simpkins@fb.com>
# Date 1498501890 25200
#      Mon Jun 26 11:31:30 2017 -0700
# Node ID f12d9578f43cc253f46a5dce2c7e288cac0fdada
# Parent  a687d5c7ac85481471d973aa06c6fd4b1dad91f0
setup: move environment computation into a helper function

Add a helper function to compute the environment used for invoking mercurial,
rather than doing this computation entirely at global scope.  This will make it
easier to do some subsequent refactoring.
Augie Fackler - June 27, 2017, 9:12 p.m.
On Mon, Jun 26, 2017 at 11:37:42AM -0700, Adam Simpkins wrote:
> # HG changeset patch
> # User Adam Simpkins <simpkins@fb.com>
> # Date 1498501890 25200
> #      Mon Jun 26 11:31:30 2017 -0700
> # Node ID f12d9578f43cc253f46a5dce2c7e288cac0fdada
> # Parent  a687d5c7ac85481471d973aa06c6fd4b1dad91f0
> setup: move environment computation into a helper function

queued patces 1-3, thanks (you only need to rebase and resend 4 and 5)

Patch

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -165,20 +165,23 @@ 
         return ''
     return out
 
-version = ''
 
-# Execute hg out of this directory with a custom environment which takes care
-# to not use any hgrc files and do no localization.
-env = {'HGMODULEPOLICY': 'py',
-       'HGRCPATH': '',
-       'LANGUAGE': 'C',
-       'PATH': ''} # make pypi modules that use os.environ['PATH'] happy
-if 'LD_LIBRARY_PATH' in os.environ:
-    env['LD_LIBRARY_PATH'] = os.environ['LD_LIBRARY_PATH']
-if 'SystemRoot' in os.environ:
-    # SystemRoot is required by Windows to load various DLLs.  See:
-    # https://bugs.python.org/issue13524#msg148850
-    env['SystemRoot'] = os.environ['SystemRoot']
+def gethgenv():
+    # Execute hg out of this directory with a custom environment which takes
+    # care to not use any hgrc files and do no localization.
+    env = {'HGMODULEPOLICY': 'py',
+           'HGRCPATH': '',
+           'LANGUAGE': 'C',
+           'PATH': ''} # make pypi modules that use os.environ['PATH'] happy
+    if 'LD_LIBRARY_PATH' in os.environ:
+        env['LD_LIBRARY_PATH'] = os.environ['LD_LIBRARY_PATH']
+    if 'SystemRoot' in os.environ:
+        # SystemRoot is required by Windows to load various DLLs.  See:
+        # https://bugs.python.org/issue13524#msg148850
+        env['SystemRoot'] = os.environ['SystemRoot']
+
+env = gethgenv()
+version = ''
 
 if os.path.isdir('.hg'):
     cmd = [sys.executable, 'hg', 'log', '-r', '.', '--template', '{tags}\n']