Patchwork D11354: hg: don't attempt to extend `sys.path` with the user site without `APPDATA`

login
register
mail settings
Submitter phabricator
Date Aug. 26, 2021, 3:19 p.m.
Message ID <differential-rev-PHID-DREV-4doc4ukbs5nxc5whaazt-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49669/
State Superseded
Headers show

Comments

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

REVISION SUMMARY
  This variable is created by the system and *should* be available, but
  test-lfs-bundle.t has a test where it is explicitly unset.  It wasn't caught
  before because prior to 95af358fcdfe <https://phab.mercurial-scm.org/rHG95af358fcdfe12e2241f52575a143a8c7efac10e>, it was limited to the py2exe binary.  As a
  precaution, fix both that and the pyoxidizer case that was causing the test to
  fail.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

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

AFFECTED FILES
  hg
  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
@@ -47,14 +47,16 @@ 
 # 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',
+    appdata = os.environ.get('APPDATA')
+    if appdata:
+        sys.path.append(
+            os.path.join(
+                appdata,
+                'Python',
+                'Python%d%d' % (vi[0], vi[1]),
+                'site-packages',
+            )
         )
-    )
 import hgdemandimport;
 hgdemandimport.enable();
 from mercurial import dispatch;
diff --git a/hg b/hg
--- a/hg
+++ b/hg
@@ -28,14 +28,16 @@ 
 # to the documentation.
 if getattr(sys, 'frozen', None) == 'console_exe':
     vi = sys.version_info
-    sys.path.append(
-        os.path.join(
-            os.environ['APPDATA'],
-            'Python',
-            'Python%d%d' % (vi[0], vi[1]),
-            'site-packages',
+    appdata = os.environ.get('APPDATA')
+    if appdata:
+        sys.path.append(
+            os.path.join(
+                appdata,
+                'Python',
+                'Python%d%d' % (vi[0], vi[1]),
+                'site-packages',
+            )
         )
-    )
 
 from hgdemandimport import tracing