Mercurial > hg
comparison mercurial/extensions.py @ 49780:9d8757ddd0ab stable
extensions: process disabled external paths when `hgext` package is in-memory
This fixes `hg help -e ambiguous` in test-helpt.t:2055 with the
`ambiguous = !./ambiguous.py` configuration, when `hgext` is not in the
filesystem (e.g. pyoxidizer builds with in-memory resources, or TortoiseHg with
py2exe), but the disabled external extension is. Now instead of aborting with a
suggestion to try `--keyword`, the help command prints text for the extension.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Wed, 07 Dec 2022 11:26:07 -0500 |
parents | 2d519511c5c3 |
children | f4a363b25859 |
comparison
equal
deleted
inserted
replaced
49779:7d6c8943353a | 49780:9d8757ddd0ab |
---|---|
727 | 727 |
728 def _disabledpaths(): | 728 def _disabledpaths(): |
729 '''find paths of disabled extensions. returns a dict of {name: path}''' | 729 '''find paths of disabled extensions. returns a dict of {name: path}''' |
730 import hgext | 730 import hgext |
731 | 731 |
732 exts = {} | |
733 | |
732 # The hgext might not have a __file__ attribute (e.g. in PyOxidizer) and | 734 # The hgext might not have a __file__ attribute (e.g. in PyOxidizer) and |
733 # it might not be on a filesystem even if it does. | 735 # it might not be on a filesystem even if it does. |
734 if util.safehasattr(hgext, '__file__'): | 736 if util.safehasattr(hgext, '__file__'): |
735 extpath = os.path.dirname( | 737 extpath = os.path.dirname( |
736 util.abspath(pycompat.fsencode(hgext.__file__)) | 738 util.abspath(pycompat.fsencode(hgext.__file__)) |
737 ) | 739 ) |
738 try: | 740 try: |
739 files = os.listdir(extpath) | 741 files = os.listdir(extpath) |
740 except OSError: | 742 except OSError: |
741 return {} | 743 pass |
742 else: | |
743 return {} | |
744 | |
745 exts = {} | |
746 for e in files: | |
747 if e.endswith(b'.py'): | |
748 name = e.rsplit(b'.', 1)[0] | |
749 path = os.path.join(extpath, e) | |
750 else: | 744 else: |
751 name = e | 745 for e in files: |
752 path = os.path.join(extpath, e, b'__init__.py') | 746 if e.endswith(b'.py'): |
753 if not os.path.exists(path): | 747 name = e.rsplit(b'.', 1)[0] |
754 continue | 748 path = os.path.join(extpath, e) |
755 if name in exts or name in _order or name == b'__init__': | 749 else: |
756 continue | 750 name = e |
757 exts[name] = path | 751 path = os.path.join(extpath, e, b'__init__.py') |
752 if not os.path.exists(path): | |
753 continue | |
754 if name in exts or name in _order or name == b'__init__': | |
755 continue | |
756 exts[name] = path | |
757 | |
758 for name, path in _disabledextensions.items(): | 758 for name, path in _disabledextensions.items(): |
759 # If no path was provided for a disabled extension (e.g. "color=!"), | 759 # If no path was provided for a disabled extension (e.g. "color=!"), |
760 # don't replace the path we already found by the scan above. | 760 # don't replace the path we already found by the scan above. |
761 if path: | 761 if path: |
762 exts[name] = path | 762 exts[name] = path |