comparison mercurial/extensions.py @ 45105:5d09a120b4be

extensions: make `hg nonexistent` not crash with PyOxidizer When running `hg nonexistent`, we try to look for extensions that provide that command. We do that by looking for files in the `hgext.__file__` directory. However, PyOxidizer doesn't provide a `__file__`, so we crash when running with PyOxidizer. We should be able to look for the command in built-in extensions, but we seem to already have code for skipping the scan when running in a frozen binary, so I just modified that code instead. By the way, it also seems like we should be able to search for extensions in the `hgext3rd` module, but we don't do that yet either (before or after this patch). Differential Revision: https://phab.mercurial-scm.org/D8750
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 14 Jul 2020 11:28:06 -0700
parents 843418dc0b1b
children f96059fa519c
comparison
equal deleted inserted replaced
45104:eb26a9cf7821 45105:5d09a120b4be
704 704
705 def _disabledpaths(): 705 def _disabledpaths():
706 '''find paths of disabled extensions. returns a dict of {name: path}''' 706 '''find paths of disabled extensions. returns a dict of {name: path}'''
707 import hgext 707 import hgext
708 708
709 extpath = os.path.dirname( 709 # The hgext might not have a __file__ attribute (e.g. in PyOxidizer) and
710 os.path.abspath(pycompat.fsencode(hgext.__file__)) 710 # it might not be on a filesystem even if it does.
711 ) 711 if util.safehasattr(hgext, '__file__'):
712 try: # might not be a filesystem path 712 extpath = os.path.dirname(
713 files = os.listdir(extpath) 713 os.path.abspath(pycompat.fsencode(hgext.__file__))
714 except OSError: 714 )
715 try:
716 files = os.listdir(extpath)
717 except OSError:
718 return {}
719 else:
715 return {} 720 return {}
716 721
717 exts = {} 722 exts = {}
718 for e in files: 723 for e in files:
719 if e.endswith(b'.py'): 724 if e.endswith(b'.py'):