Patchwork D11308: pyoxidizer: add user-site to `sys.path` on Windows

login
register
mail settings
Submitter phabricator
Date Aug. 19, 2021, 2:47 a.m.
Message ID <differential-rev-PHID-DREV-7gda2iwbhqzf23guvivq-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49622/
State Superseded
Headers show

Comments

phabricator - Aug. 19, 2021, 2:47 a.m.
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is a port of 53221078e0de <https://phab.mercurial-scm.org/rHG53221078e0de65d1a821ce5311dec45a7a978301> to Windows to allow pip-installed extensions to
  be loaded without specifying a path.  It's a major headache to have an hg.exe on
  `PATH` that needs to have the path to the extensions specified, because WSL
  doesn't see the same path.
  
  This is only for Windows for now, to match the currently shipping py2 behavior.
  There is a better solution with using the `site` package, but this needs support
  in PyOxidizer[1].
  
  [1] https://github.com/indygreg/PyOxidizer/issues/430

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  rust/hgcli/pyoxidizer.bzl

CHANGE DETAILS




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

Patch

diff --git a/rust/hgcli/pyoxidizer.bzl b/rust/hgcli/pyoxidizer.bzl
--- a/rust/hgcli/pyoxidizer.bzl
+++ b/rust/hgcli/pyoxidizer.bzl
@@ -44,6 +44,17 @@ 
     # We do not prepend the values because the Mercurial library wants to be in
     # the front of the sys.path to avoid picking up other installations.
     sys.path.extend(extra_path.split(os.pathsep))
+# Add user site to sys.path to load extensions without the full path
+if os.name == 'nt':
+    vi = sys.version_info
+    sys.path.append(
+        os.path.join(
+            os.environ['APPDATA'],
+            'Python',
+            'Python%d%d' % (vi[0], vi[1]),
+            'site-packages',
+        )
+    )
 import hgdemandimport;
 hgdemandimport.enable();
 from mercurial import dispatch;