comparison mercurial/utils/resourceutil.py @ 47853:df94c13ddf60 stable

resources: stop important a non existent FileNotFoundError The error was hidden by the wide try/except Differential Revision: https://phab.mercurial-scm.org/D11311
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 19 Aug 2021 17:47:27 +0200
parents f3b1df44b716
children 08f16b3331df
comparison
equal deleted inserted replaced
47852:2b76255a4f74 47853:df94c13ddf60
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
72 def open_resource(package, name): 67 def open_resource(package, name):
73 return resources.open_binary( # pytype: disable=module-attr 68 return resources.open_binary( # pytype: disable=module-attr
74 pycompat.sysstr(package), pycompat.sysstr(name) 69 pycompat.sysstr(package), pycompat.sysstr(name)
75 ) 70 )
76 71
88 83
89 except (ImportError, AttributeError): 84 except (ImportError, AttributeError):
90 # importlib.resources was not found (almost definitely because we're on a 85 # importlib.resources was not found (almost definitely because we're on a
91 # Python version before 3.7) 86 # Python version before 3.7)
92 87
93 class FileNotFoundError(RuntimeError):
94 pass
95
96 def open_resource(package, name): 88 def open_resource(package, name):
97 path = os.path.join(_package_path(package), name) 89 path = os.path.join(_package_path(package), name)
98 return open(path, "rb") 90 return open(path, "rb")
99 91
100 def is_resource(package, name): 92 def is_resource(package, name):