# HG changeset patch # User Matt Harbison # Date 2019-11-17 06:00:06 # Node ID 1fb19665c166b2d2d4b936d8d47dec0c952f2deb # Parent da925257a39e5797e5b2e35ce1d68e923ea8ddf2 debuginstall: gracefully handle missing __file__ attributes 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. Differential Revision: https://phab.mercurial-scm.org/D7451 diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py --- a/mercurial/debugcommands.py +++ b/mercurial/debugcommands.py @@ -1470,6 +1470,12 @@ def debuginstall(ui, **opts): ) # 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 @@ def debuginstall(ui, **opts): 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 @@ def debuginstall(ui, **opts): ) # compiled modules + hgmodules = None + if util.safehasattr(sys.modules[__name__], '__file__'): + hgmodules = os.path.dirname(pycompat.fsencode(__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')