diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index 25cdc04bd..9e8600968 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -33,7 +33,7 @@ from sphinx.util.osutil import SEP, os_path, relative_uri, ensuredir, \ movefile, copyfile from sphinx.util.nodes import inline_all_toctrees from sphinx.util.fileutil import copy_asset -from sphinx.util.matching import patmatch, compile_matchers, Matcher +from sphinx.util.matching import patmatch, Matcher from sphinx.config import string_classes from sphinx.locale import _, l_ from sphinx.search import js_index @@ -620,15 +620,14 @@ class StandaloneHTMLBuilder(Builder): copy_static_entry(entry, path.join(self.outdir, '_static'), self, ctx) # then, copy over all user-supplied static files - staticentries = [path.join(self.confdir, spath) - for spath in self.config.html_static_path] - matchers = compile_matchers(self.config.exclude_patterns) - for entry in staticentries: + excluded = Matcher(self.config.exclude_patterns + ["**/.*"]) + for static_path in self.config.html_static_path: + entry = path.join(self.confdir, static_path) if not path.exists(entry): self.warn('html_static_path entry %r does not exist' % entry) continue - copy_static_entry(entry, path.join(self.outdir, '_static'), self, - ctx, exclude_matchers=matchers) + copy_asset(entry, path.join(self.outdir, '_static'), excluded, + context=ctx, renderer=self.templates) # copy logo and favicon files if not already in static path if self.config.html_logo: logobase = path.basename(self.config.html_logo) diff --git a/tests/roots/test-html_extra_path/conf.py b/tests/roots/test-html_assets/conf.py similarity index 63% rename from tests/roots/test-html_extra_path/conf.py rename to tests/roots/test-html_assets/conf.py index 53ee62197..a17e417a3 100644 --- a/tests/roots/test-html_extra_path/conf.py +++ b/tests/roots/test-html_assets/conf.py @@ -1,6 +1,9 @@ # -*- coding: utf-8 -*- master_doc = 'index' +project = 'Sphinx' +version = '1.4.4' +html_static_path = ['static', 'subdir'] html_extra_path = ['extra', 'subdir'] exclude_patterns = ['**/_build', '**/.htpasswd'] diff --git a/tests/roots/test-html_extra_path/extra/.htaccess b/tests/roots/test-html_assets/extra/.htaccess similarity index 100% rename from tests/roots/test-html_extra_path/extra/.htaccess rename to tests/roots/test-html_assets/extra/.htaccess diff --git a/tests/roots/test-html_extra_path/extra/.htpasswd b/tests/roots/test-html_assets/extra/.htpasswd similarity index 100% rename from tests/roots/test-html_extra_path/extra/.htpasswd rename to tests/roots/test-html_assets/extra/.htpasswd diff --git a/tests/roots/test-html_assets/extra/API.html_t b/tests/roots/test-html_assets/extra/API.html_t new file mode 100644 index 000000000..34ecd9df1 --- /dev/null +++ b/tests/roots/test-html_assets/extra/API.html_t @@ -0,0 +1 @@ +{{ project }}-{{ version }} diff --git a/tests/roots/test-html_extra_path/extra/css/style.css b/tests/roots/test-html_assets/extra/css/style.css similarity index 100% rename from tests/roots/test-html_extra_path/extra/css/style.css rename to tests/roots/test-html_assets/extra/css/style.css diff --git a/tests/roots/test-html_extra_path/extra/rimg.png b/tests/roots/test-html_assets/extra/rimg.png similarity index 100% rename from tests/roots/test-html_extra_path/extra/rimg.png rename to tests/roots/test-html_assets/extra/rimg.png diff --git a/tests/roots/test-html_extra_path/extra/subdir/.htaccess b/tests/roots/test-html_assets/extra/subdir/.htaccess similarity index 100% rename from tests/roots/test-html_extra_path/extra/subdir/.htaccess rename to tests/roots/test-html_assets/extra/subdir/.htaccess diff --git a/tests/roots/test-html_extra_path/extra/subdir/.htpasswd b/tests/roots/test-html_assets/extra/subdir/.htpasswd similarity index 100% rename from tests/roots/test-html_extra_path/extra/subdir/.htpasswd rename to tests/roots/test-html_assets/extra/subdir/.htpasswd diff --git a/tests/roots/test-html_extra_path/index.rst b/tests/roots/test-html_assets/index.rst similarity index 100% rename from tests/roots/test-html_extra_path/index.rst rename to tests/roots/test-html_assets/index.rst diff --git a/tests/roots/test-html_extra_path/extra/API.html_t b/tests/roots/test-html_assets/static/.htaccess similarity index 100% rename from tests/roots/test-html_extra_path/extra/API.html_t rename to tests/roots/test-html_assets/static/.htaccess diff --git a/tests/roots/test-html_extra_path/subdir/_build/index.html b/tests/roots/test-html_assets/static/.htpasswd similarity index 100% rename from tests/roots/test-html_extra_path/subdir/_build/index.html rename to tests/roots/test-html_assets/static/.htpasswd diff --git a/tests/roots/test-html_assets/static/API.html_t b/tests/roots/test-html_assets/static/API.html_t new file mode 100644 index 000000000..34ecd9df1 --- /dev/null +++ b/tests/roots/test-html_assets/static/API.html_t @@ -0,0 +1 @@ +{{ project }}-{{ version }} diff --git a/tests/roots/test-html_assets/static/css/style.css b/tests/roots/test-html_assets/static/css/style.css new file mode 100644 index 000000000..e69de29bb diff --git a/tests/roots/test-html_extra_path/subdir/background.png b/tests/roots/test-html_assets/static/rimg.png similarity index 100% rename from tests/roots/test-html_extra_path/subdir/background.png rename to tests/roots/test-html_assets/static/rimg.png diff --git a/tests/roots/test-html_assets/static/subdir/.htaccess b/tests/roots/test-html_assets/static/subdir/.htaccess new file mode 100644 index 000000000..e69de29bb diff --git a/tests/roots/test-html_assets/static/subdir/.htpasswd b/tests/roots/test-html_assets/static/subdir/.htpasswd new file mode 100644 index 000000000..e69de29bb diff --git a/tests/roots/test-html_assets/subdir/_build/index.html b/tests/roots/test-html_assets/subdir/_build/index.html new file mode 100644 index 000000000..e69de29bb diff --git a/tests/roots/test-html_assets/subdir/background.png b/tests/roots/test-html_assets/subdir/background.png new file mode 100644 index 000000000..1081dc143 Binary files /dev/null and b/tests/roots/test-html_assets/subdir/background.png differ diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 78ef1770c..7a0cb7cfd 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -976,10 +976,23 @@ def test_jsmath(app, status, warning): assert '
\na + 1 < b
' in content -@with_app(buildername='html', testroot='html_extra_path') -def test_html_extra_path(app, status, warning): +@with_app(buildername='html', testroot='html_assets') +def test_html_assets(app, status, warning): app.builder.build_all() + # html_static_path + assert not (app.outdir / '_static' / '.htaccess').exists() + assert not (app.outdir / '_static' / '.htpasswd').exists() + assert (app.outdir / '_static' / 'API.html').exists() + assert (app.outdir / '_static' / 'API.html').text() == 'Sphinx-1.4.4' + assert (app.outdir / '_static' / 'css/style.css').exists() + assert (app.outdir / '_static' / 'rimg.png').exists() + assert not (app.outdir / '_static' / '_build/index.html').exists() + assert (app.outdir / '_static' / 'background.png').exists() + assert not (app.outdir / '_static' / 'subdir' / '.htaccess').exists() + assert not (app.outdir / '_static' / 'subdir' / '.htpasswd').exists() + + # html_extra_path assert (app.outdir / '.htaccess').exists() assert not (app.outdir / '.htpasswd').exists() assert (app.outdir / 'API.html_t').exists()