[Updated] D11288: template: handle missing resource in `_readmapfile`
baymax (Baymax, Your Personal Patch-care Companion)
phabricator at mercurial-scm.org
Wed Aug 18 10:47:07 UTC 2021
baymax added a comment.
baymax edited the summary of this revision.
baymax updated this revision to Diff 29912.
✅ refresh by Heptapod after a successful CI run (🐙 💚)
⚠ This patch is intended for stable ⚠
<img src="https://phab.mercurial-scm.org/file/data/p334drn6opgk3ac7exvu/PHID-FILE-h4oskowh6xyt7acp2mxz/source.gif" />
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D11288?vs=29897&id=29912
BRANCH
stable
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D11288/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D11288
AFFECTED FILES
mercurial/templater.py
mercurial/utils/resourceutil.py
CHANGE DETAILS
diff --git a/mercurial/utils/resourceutil.py b/mercurial/utils/resourceutil.py
--- a/mercurial/utils/resourceutil.py
+++ b/mercurial/utils/resourceutil.py
@@ -64,6 +64,11 @@
# Force loading of the resources module
resources.open_binary # pytype: disable=module-attr
+ # pytype: disable=import-error
+ from importlib.resources import FileNotFoundError
+
+ # pytype: enable=import-error
+
def open_resource(package, name):
return resources.open_binary( # pytype: disable=module-attr
pycompat.sysstr(package), pycompat.sysstr(name)
@@ -85,6 +90,9 @@
# importlib.resources was not found (almost definitely because we're on a
# Python version before 3.7)
+ class FileNotFoundError(RuntimeError):
+ pass
+
def open_resource(package, name):
path = os.path.join(_package_path(package), name)
return open(path, "rb")
diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -852,9 +852,12 @@
if not subresource:
if pycompat.ossep not in rel:
abs = rel
- subresource = resourceutil.open_resource(
- b'mercurial.templates', rel
- )
+ try:
+ subresource = resourceutil.open_resource(
+ b'mercurial.templates', rel
+ )
+ except resourceutil.FileNotFoundError:
+ subresource = None
else:
dir = templatedir()
if dir:
To: marmoute, #hg-reviewers
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20210818/51ebb633/attachment-0002.html>
More information about the Mercurial-patches
mailing list