changeset 48217:e10f5dc7f5bf

pyoxidizer: add the user site to `sys.path` on macOS This allows 3rd party extensions that are installed with `pip` to be picked up, similar to what we do on Windows. PyOxidizer has a bug that prevents this from working without this extra help (see 95af358fcdfe), though it appears there's another wrinkle here with `sys._framework` too. I needed this to see if the problem[1] loading the keyring extension on Windows also occurs on macOS (it doesn't). [1] https://github.com/indygreg/PyOxidizer/issues/445 Differential Revision: https://phab.mercurial-scm.org/D11452
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 17 Sep 2021 15:07:30 -0400
parents 7bc1beedd718
children 15dedc0c5c35
files rust/hgcli/pyoxidizer.bzl
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hgcli/pyoxidizer.bzl	Fri Sep 17 15:02:01 2021 -0400
+++ b/rust/hgcli/pyoxidizer.bzl	Fri Sep 17 15:07:30 2021 -0400
@@ -58,6 +58,20 @@
                 'site-packages',
             )
         )
+elif sys.platform == "darwin":
+    vi = sys.version_info
+
+    def joinuser(*args):
+        return os.path.expanduser(os.path.join(*args))
+
+    # Note: site.py uses `sys._framework` instead of hardcoding "Python" as the
+    #   3rd arg, but that is set to an empty string in an oxidized binary.  It
+    #   has a fallback to ~/.local when `sys._framework` isn't set, but we want
+    #   to match what the system python uses, so it sees pip installed stuff.
+    usersite = joinuser("~", "Library", "Python",
+                        "%d.%d" % vi[:2], "lib/python/site-packages")
+
+    sys.path.append(usersite)
 import hgdemandimport;
 hgdemandimport.enable();
 from mercurial import dispatch;