From f1b387bdcff9fb74dad832865a32cc6b1f4a9b68 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Tue, 18 Apr 2017 23:22:03 +0900 Subject: [PATCH] Fix fail to load template file if the parent template is archived --- CHANGES | 1 + sphinx/jinja2glue.py | 4 ++-- sphinx/theming.py | 8 ++++++-- tests/roots/test-theming/child.zip | Bin 0 -> 661 bytes tests/roots/test-theming/conf.py | 1 + tests/roots/test-theming/parent.zip | Bin 0 -> 1039 bytes tests/test_theming.py | 6 ++++++ 7 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 tests/roots/test-theming/child.zip create mode 100644 tests/roots/test-theming/parent.zip diff --git a/CHANGES b/CHANGES index 5d605e405..62c041552 100644 --- a/CHANGES +++ b/CHANGES @@ -117,6 +117,7 @@ Bugs fixed * C++, properly look up ``any`` references. * #3624: sphinx.ext.intersphinx couldn't load inventories compressed with gzip * #3551: PDF information dictionary is lacking author and title data +* Fail to load template file if the parent template is archived Deprecated ---------- diff --git a/sphinx/jinja2glue.py b/sphinx/jinja2glue.py index 91b3a6e3a..c40b102ad 100644 --- a/sphinx/jinja2glue.py +++ b/sphinx/jinja2glue.py @@ -135,8 +135,8 @@ class BuiltinTemplateLoader(TemplateBridge, BaseLoader): if theme: # the theme's own dir and its bases' dirs pathchain = theme.get_dirchain() - # then the theme parent paths - loaderchain = pathchain + theme.themepath + # the loader dirs: pathchain + the parent directories for all themes + loaderchain = pathchain + [path.join(p, '..') for p in pathchain] elif dirs: pathchain = list(dirs) loaderchain = list(dirs) diff --git a/sphinx/theming.py b/sphinx/theming.py index f10d29010..a069a4e2c 100644 --- a/sphinx/theming.py +++ b/sphinx/theming.py @@ -22,6 +22,7 @@ from six.moves import configparser from sphinx import package_dir from sphinx.errors import ThemeError from sphinx.util import logging +from sphinx.util.osutil import ensuredir logger = logging.getLogger(__name__) @@ -127,12 +128,15 @@ class Theme(object): tdir, tinfo = self.themes[name] if tinfo is None: # already a directory, do nothing + self.rootdir = None self.themedir = tdir self.themedir_created = False else: # extract the theme to a temp directory - self.themedir = tempfile.mkdtemp('sxt') + self.rootdir = tempfile.mkdtemp('sxt') + self.themedir = path.join(self.rootdir, name) self.themedir_created = True + ensuredir(self.themedir) for name in tinfo.namelist(): if name.endswith('/'): continue @@ -214,7 +218,7 @@ class Theme(object): """Remove temporary directories.""" if self.themedir_created: try: - shutil.rmtree(self.themedir) + shutil.rmtree(self.rootdir) except Exception: pass if self.base: diff --git a/tests/roots/test-theming/child.zip b/tests/roots/test-theming/child.zip new file mode 100644 index 0000000000000000000000000000000000000000..b4a6a56b53e15ffb00450f53fff928c5d1d2f621 GIT binary patch literal 661 zcmWIWW@Zs#U|`^2NZ2&VE9>LCAB8|(4-j)R$S~w2R_2$M=w+1T=7ffDGB7&}eTxVJ z;?fFk21b@|j0_B5&AMm3xegofxL&LbQ)Fo?yOg7FGOTMB2hUgj->gwR-{oePRn50p z)%Jy%*Im(Xl4(NOr(ShAv3rIy%|e~^#lL^IIFl6G7bw17fa_6dYKEgv!mZ>NVqxp1 zCR}~}**-Aa=d;<@xN}Q>mc36s@%JfCuX2^DL zkkmaVrWCan$Pn;eS0%okY*)P=;mgk!`J=B=mG4INpWk35CsaP4SFwJgN zjQYu;bmiIU)2F|(pKh!bP>PlC`!goM=BFJkD0QFtVf(~b zlFVd%u#3Z`W_VfyF`A1(20*+GGT=w;jenPb2HXN-5rhE{b24+&^$POR;iiF1L^JI* z&xhjYPbWP}N=SI{^-BRK)1@AVoWlp%RHoPO`M|9bAoJwikqz(Wobgs@-+VxM(~QQ( zXo(g{$+WW*8Mro0ulTiV)BS`eqEC}o?73~pt)UY6NGkBrocXh7&k8^EAZE&}h)J^+ z1k%UrVW&V4|gUoC;?Gbgq_otOiinrXpWaBxfO$N17 z#csF7%$+)i&FMNz>#EW;%dN5rmcd4U+amwT?48-VKS}9n`t_+_u6^G;J3jbR;y;6* zb{9O@{KM_1m-=z~G9bcdF))0z9ZcVc0mCL8h`E5_Q<9OIo2r+bpO*#>l_p?_fG}F9 z$ae4KZ7>jE`MkP`>qUc?fYULZA1d`p=Noq)pO9l&)-i%Cg%(#-Q1ki;H z42(d$q!GkINx-a-1dQfPh=I6L6U0CU1_6e*j@y6+!qXPeFf1tn*>#vH3uYL|b>9(& qp`|mzCS%44vcJWd7*JveXdaf>3GilR1BDO^5PARuY$H$?0|NkQuTX;k literal 0 HcmV?d00001 diff --git a/tests/test_theming.py b/tests/test_theming.py index 4f305d8bf..9046956fb 100644 --- a/tests/test_theming.py +++ b/tests/test_theming.py @@ -100,3 +100,9 @@ def test_double_inheriting_theme(make_app, app_params): with mock.patch('sphinx.theming.load_theme_plugins', side_effect=load_themes): args, kwargs = app_params make_app(*args, **kwargs) + + +@pytest.mark.sphinx(testroot='theming', + confoverrides={'html_theme': 'child'}) +def test_nested_zipped_theme(app, status, warning): + app.build() # => not raises TemplateNotFound