##// END OF EJS Templates
resourceutil: start using importlib.resources.files() when possible...
av6 -
r50838:330d8821 stable
parent child Browse files
Show More
@@ -59,7 +59,10 b' try:'
59 from importlib import resources # pytype: disable=import-error
59 from importlib import resources # pytype: disable=import-error
60
60
61 # Force loading of the resources module
61 # Force loading of the resources module
62 resources.open_binary # pytype: disable=module-attr
62 if pycompat.safehasattr(resources, 'files'):
63 resources.files # pytype: disable=module-attr
64 else:
65 resources.open_binary # pytype: disable=module-attr
63
66
64 # py2exe raises an AssertionError if uses importlib.resources
67 # py2exe raises an AssertionError if uses importlib.resources
65 if getattr(sys, "frozen", None) in ("console_exe", "windows_exe"):
68 if getattr(sys, "frozen", None) in ("console_exe", "windows_exe"):
@@ -92,9 +95,18 b' else:'
92 from .. import encoding
95 from .. import encoding
93
96
94 def open_resource(package, name):
97 def open_resource(package, name):
95 return resources.open_binary( # pytype: disable=module-attr
98 if pycompat.safehasattr(resources, 'files'):
96 pycompat.sysstr(package), pycompat.sysstr(name)
99 return (
97 )
100 resources.files( # pytype: disable=module-attr
101 pycompat.sysstr(package)
102 )
103 .joinpath(pycompat.sysstr(name))
104 .open('rb')
105 )
106 else:
107 return resources.open_binary( # pytype: disable=module-attr
108 pycompat.sysstr(package), pycompat.sysstr(name)
109 )
98
110
99 def is_resource(package, name):
111 def is_resource(package, name):
100 return resources.is_resource( # pytype: disable=module-attr
112 return resources.is_resource( # pytype: disable=module-attr
General Comments 0
You need to be logged in to leave comments. Login now