comparison mercurial/utils/resourceutil.py @ 47836:f3b1df44b716 stable

template: handle missing resource in `_readmapfile` This fix the remaining issue in test-template-map.t. Differential Revision: https://phab.mercurial-scm.org/D11288
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 18 Aug 2021 01:41:02 +0200
parents d4ba4d51f85f
children df94c13ddf60
comparison
equal deleted inserted replaced
47835:da39b9c1c486 47836:f3b1df44b716
62 from .. import encoding 62 from .. import encoding
63 63
64 # Force loading of the resources module 64 # Force loading of the resources module
65 resources.open_binary # pytype: disable=module-attr 65 resources.open_binary # pytype: disable=module-attr
66 66
67 # pytype: disable=import-error
68 from importlib.resources import FileNotFoundError
69
70 # pytype: enable=import-error
71
67 def open_resource(package, name): 72 def open_resource(package, name):
68 return resources.open_binary( # pytype: disable=module-attr 73 return resources.open_binary( # pytype: disable=module-attr
69 pycompat.sysstr(package), pycompat.sysstr(name) 74 pycompat.sysstr(package), pycompat.sysstr(name)
70 ) 75 )
71 76
83 88
84 except (ImportError, AttributeError): 89 except (ImportError, AttributeError):
85 # importlib.resources was not found (almost definitely because we're on a 90 # importlib.resources was not found (almost definitely because we're on a
86 # Python version before 3.7) 91 # Python version before 3.7)
87 92
93 class FileNotFoundError(RuntimeError):
94 pass
95
88 def open_resource(package, name): 96 def open_resource(package, name):
89 path = os.path.join(_package_path(package), name) 97 path = os.path.join(_package_path(package), name)
90 return open(path, "rb") 98 return open(path, "rb")
91 99
92 def is_resource(package, name): 100 def is_resource(package, name):