##// END OF EJS Templates
resourceutil: don't limit resources to the `mercurial` package...
Matt Harbison -
r44479:52f0140c default
parent child Browse files
Show More
@@ -313,9 +313,9 b' def loaddoc(topic, subdir=None):'
313 """Return a delayed loader for help/topic.txt."""
313 """Return a delayed loader for help/topic.txt."""
314
314
315 def loader(ui):
315 def loader(ui):
316 package = b'helptext'
316 package = b'mercurial.helptext'
317 if subdir:
317 if subdir:
318 package = b'helptext' + b'.' + subdir
318 package += b'.' + subdir
319 with resourceutil.open_resource(package, topic + b'.txt') as fp:
319 with resourceutil.open_resource(package, topic + b'.txt') as fp:
320 doc = gettext(fp.read())
320 doc = gettext(fp.read())
321 for rewriter in helphooks.get(topic, []):
321 for rewriter in helphooks.get(topic, []):
@@ -35,6 +35,7 b" if mainfrozen() and getattr(sys, 'frozen"
35 datapath = os.path.dirname(pycompat.sysexecutable)
35 datapath = os.path.dirname(pycompat.sysexecutable)
36 else:
36 else:
37 datapath = os.path.dirname(os.path.dirname(pycompat.fsencode(__file__)))
37 datapath = os.path.dirname(os.path.dirname(pycompat.fsencode(__file__)))
38 _rootpath = os.path.dirname(datapath)
38
39
39 try:
40 try:
40 from importlib import resources
41 from importlib import resources
@@ -43,7 +44,6 b' try:'
43 resources.open_binary # pytype: disable=module-attr
44 resources.open_binary # pytype: disable=module-attr
44
45
45 def open_resource(package, name):
46 def open_resource(package, name):
46 package = b'mercurial.' + package
47 return resources.open_binary( # pytype: disable=module-attr
47 return resources.open_binary( # pytype: disable=module-attr
48 pycompat.sysstr(package), pycompat.sysstr(name)
48 pycompat.sysstr(package), pycompat.sysstr(name)
49 )
49 )
@@ -52,7 +52,7 b' try:'
52 except (ImportError, AttributeError):
52 except (ImportError, AttributeError):
53
53
54 def _package_path(package):
54 def _package_path(package):
55 return os.path.join(datapath, *package.split(b'.'))
55 return os.path.join(_rootpath, *package.split(b'.'))
56
56
57 def open_resource(package, name):
57 def open_resource(package, name):
58 path = os.path.join(_package_path(package), name)
58 path = os.path.join(_package_path(package), name)
General Comments 0
You need to be logged in to leave comments. Login now