[Updated] D8894: templater: make open_template() read from resources if in frozen binary
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Thu Aug 6 00:48:59 UTC 2020
Closed by commit rHG3b27ed8e324e: templater: make open_template() read from resources if in frozen binary (authored by martinvonz).
This revision was automatically updated to reflect the committed changes.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D8894?vs=22276&id=22292
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D8894/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D8894
AFFECTED FILES
mercurial/templater.py
CHANGE DETAILS
diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -1074,7 +1074,12 @@
def open_template(name):
- '''returns a file-like object for the given template, and its full path'''
+ '''returns a file-like object for the given template, and its full path
+
+ If the name is a relative path and we're in a frozen binary, the template
+ will be read from the mercurial.templates package instead. The returned path
+ will then be the relative path.
+ '''
templatepath = templatedir()
if templatepath is not None or os.path.isabs(name):
f = os.path.join(templatepath, name)
@@ -1083,5 +1088,12 @@
except EnvironmentError:
return None, None
else:
- # TODO: read from resources here
- return None, None
+ name_parts = pycompat.sysstr(name).split('/')
+ package_name = '.'.join(['mercurial', 'templates'] + name_parts[:-1])
+ try:
+ return (
+ name,
+ resourceutil.open_resource(package_name, name_parts[-1]),
+ )
+ except (ModuleNotFoundError, FileNotFoundError):
+ return None, None
To: martinvonz, #hg-reviewers, indygreg
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20200806/43094efc/attachment-0002.html>
More information about the Mercurial-patches
mailing list