Patchwork D7451: debuginstall: gracefully handle missing __file__ attributes

login
register
mail settings
Submitter phabricator
Date Nov. 17, 2019, 6:06 a.m.
Message ID <differential-rev-PHID-DREV-hbnmf3qdo3yvcbfgsyoh-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/43321/
State Superseded
Headers show

Comments

phabricator - Nov. 17, 2019, 6:06 a.m.
mharbison72 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This was crashing PyOxidizer.  While here, point "Python lib" and "installed
  modules" to the oxidized binary when read from memory instead of pretending
  their location is unknown.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/debugcommands.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-devel
phabricator - Nov. 17, 2019, 11:26 p.m.
This revision is now accepted and ready to land.
indygreg added a comment.
indygreg accepted this revision.


  Pointing to the executable when running with PyOxidizer seems like a reasonable approach to me!

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7451/new/

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

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

Patch

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -1470,6 +1470,12 @@ 
     )
 
     # Python
+    pythonlib = None
+    if util.safehasattr(os, '__file__'):
+        pythonlib = os.path.dirname(pycompat.fsencode(os.__file__))
+    elif getattr(sys, 'oxidized', False):
+        pythonlib = pycompat.sysexecutable
+
     fm.write(
         b'pythonexe',
         _(b"checking Python executable (%s)\n"),
@@ -1483,7 +1489,7 @@ 
     fm.write(
         b'pythonlib',
         _(b"checking Python lib (%s)...\n"),
-        os.path.dirname(pycompat.fsencode(os.__file__)),
+        pythonlib or _(b"unknown"),
     )
 
     security = set(sslutil.supportedprotocols)
@@ -1527,13 +1533,19 @@ 
     )
 
     # compiled modules
+    hgmodules = None
+    if util.safehasattr(util, '__file__'):
+        hgmodules = os.path.dirname(pycompat.fsencode(util.__file__))
+    elif getattr(sys, 'oxidized', False):
+        hgmodules = pycompat.sysexecutable
+
     fm.write(
         b'hgmodulepolicy', _(b"checking module policy (%s)\n"), policy.policy
     )
     fm.write(
         b'hgmodules',
         _(b"checking installed modules (%s)...\n"),
-        os.path.dirname(pycompat.fsencode(__file__)),
+        hgmodules or _(b"unknown"),
     )
 
     rustandc = policy.policy in (b'rust+c', b'rust+c-allow')