Patchwork run-tests: forward Python USER_BASE from site (issue5425)

login
register
mail settings
Submitter Augie Fackler
Date Nov. 10, 2016, 9:11 p.m.
Message ID <4a82a34d2694953ad58e.1478812287@augie-macbookair2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/17453/
State Changes Requested
Headers show

Comments

Augie Fackler - Nov. 10, 2016, 9:11 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1478812044 18000
#      Thu Nov 10 16:07:24 2016 -0500
# Node ID 4a82a34d2694953ad58e5565a318d6909978d4ca
# Parent  61c9f8b3663cc6144446bbe1b8d8fc5088f081be
run-tests: forward Python USER_BASE from site (issue5425)

We do this so that any linters installed via pip install --user don't
break. See https://docs.python.org/2/library/site.html#site.USER_BASE
for a description of what this nonsense is all about.

An alternative would be to not set HOME, but that'll cause other
problems (see issue2707), or to forward every single path entry from
sys.path in PYTHONPATH (which seems sketchy in its own way).
Yuya Nishihara - Nov. 16, 2016, 1:15 p.m.
On Thu, 10 Nov 2016 16:11:27 -0500, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1478812044 18000
> #      Thu Nov 10 16:07:24 2016 -0500
> # Node ID 4a82a34d2694953ad58e5565a318d6909978d4ca
> # Parent  61c9f8b3663cc6144446bbe1b8d8fc5088f081be
> run-tests: forward Python USER_BASE from site (issue5425)
> 
> We do this so that any linters installed via pip install --user don't
> break. See https://docs.python.org/2/library/site.html#site.USER_BASE
> for a description of what this nonsense is all about.
> 
> An alternative would be to not set HOME, but that'll cause other
> problems (see issue2707), or to forward every single path entry from
> sys.path in PYTHONPATH (which seems sketchy in its own way).
> 
> diff --git a/tests/run-tests.py b/tests/run-tests.py
> --- a/tests/run-tests.py
> +++ b/tests/run-tests.py
> @@ -58,6 +58,7 @@ import signal
>  import socket
>  import subprocess
>  import sys
> +import sysconfig

Seems fine, but the sysconfig module doesn't exist in Python 2.6. I think
simple try-except would be okay.

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -58,6 +58,7 @@  import signal
 import socket
 import subprocess
 import sys
+import sysconfig
 import tempfile
 import threading
 import time
@@ -818,6 +819,7 @@  class Test(unittest.TestCase):
             offset = '' if i == 0 else '%s' % i
             env["HGPORT%s" % offset] = '%s' % (self._startport + i)
         env = os.environ.copy()
+        env['PYTHONUSERBASE'] = sysconfig.get_config_var('userbase')
         env['TESTTMP'] = self._testtmp
         env['HOME'] = self._testtmp
         # This number should match portneeded in _getport