##// END OF EJS Templates
help: get helptext/ data from `resources` module if available...
Martin von Zweigbergk -
r44708:1390bb81 default
parent child Browse files
Show More
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
@@ -8,7 +8,6 b''
8 from __future__ import absolute_import
8 from __future__ import absolute_import
9
9
10 import itertools
10 import itertools
11 import os
12 import re
11 import re
13 import textwrap
12 import textwrap
14
13
@@ -314,11 +313,11 b' def loaddoc(topic, subdir=None):'
314 """Return a delayed loader for help/topic.txt."""
313 """Return a delayed loader for help/topic.txt."""
315
314
316 def loader(ui):
315 def loader(ui):
317 docdir = os.path.join(resourceutil.datapath, b'helptext')
316 package = b'helptext'
318 if subdir:
317 if subdir:
319 docdir = os.path.join(docdir, subdir)
318 package = b'helptext' + b'.' + subdir
320 path = os.path.join(docdir, topic + b".txt")
319 with resourceutil.open_resource(package, topic + b'.txt') as fp:
321 doc = gettext(util.readfile(path))
320 doc = gettext(fp.read())
322 for rewriter in helphooks.get(topic, []):
321 for rewriter in helphooks.get(topic, []):
323 doc = rewriter(ui, topic, doc)
322 doc = rewriter(ui, topic, doc)
324 return doc
323 return doc
@@ -35,3 +35,25 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
39 try:
40 import importlib
41
42 # Force loading of the resources module
43 importlib.resources.open_binary
44
45 def open_resource(package, name):
46 package = b'mercurial.' + package
47 return importlib.resources.open_binary(
48 pycompat.sysstr(package), pycompat.sysstr(name)
49 )
50
51
52 except AttributeError:
53
54 def _package_path(package):
55 return os.path.join(datapath, *package.split(b'.'))
56
57 def open_resource(package, name):
58 path = os.path.join(_package_path(package), name)
59 return open(path, 'rb')
General Comments 0
You need to be logged in to leave comments. Login now