Skip to content
Snippets Groups Projects
Commit f3b1df44 authored by Pierre-Yves David's avatar Pierre-Yves David :octopus:
Browse files

template: handle missing resource in `_readmapfile`

This fix the remaining issue in test-template-map.t.

Differential Revision: https://phab.mercurial-scm.org/D11288
parent da39b9c1
No related branches found
No related tags found
No related merge requests found
......@@ -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:
......
......@@ -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")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment