Patchwork D9535: run-tests: extend PATH on Windows to include user installed scripts

login
register
mail settings
Submitter phabricator
Date Dec. 8, 2020, 4:01 a.m.
Message ID <differential-rev-PHID-DREV-eskugog7l5vq7zitwqbh-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47825/
State Superseded
Headers show

Comments

phabricator - Dec. 8, 2020, 4:01 a.m.
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This allows the test environment to see pylint.exe when installed with
  `pip install --user`, since it isn't normally on PATH.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9535

AFFECTED FILES
  tests/run-tests.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -3474,7 +3474,29 @@ 
             path = os.environ['PATH'].split(os.pathsep)
             while exedir in path:
                 path.remove(exedir)
-            os.environ['PATH'] = os.pathsep.join([exedir] + path)
+
+            # Binaries installed by pip into the user area like pylint.exe may
+            # not be in PATH by default.
+            extra_paths = [exedir]
+            vi = sys.version_info
+            if 'APPDATA' in os.environ:
+                scripts_dir = os.path.join(
+                    os.environ['APPDATA'],
+                    'Python',
+                    'Python%d%d' % (vi[0], vi[1]),
+                    'Scripts',
+                )
+
+                if vi.major == 2:
+                    scripts_dir = os.path.join(
+                        os.environ['APPDATA'],
+                        'Python',
+                        'Scripts',
+                    )
+
+                extra_paths.append(scripts_dir)
+
+            os.environ['PATH'] = os.pathsep.join(extra_paths + path)
             if not self._findprogram(pyexename):
                 print("WARNING: Cannot find %s in search path" % pyexename)