Debian Codegraph @

tests/roots/test-util-copyasset_overwrite/myext.py

raw
1 from pathlib import Path
2
3 from sphinx.util.fileutil import copy_asset
4
5
6 def _copy_asset_overwrite_hook(app):
7 css = app.outdir / '_static' / 'custom-styles.css'
8 # html_static_path is copied by default
9 css_content = css.read_text(encoding='utf-8')
10 assert css_content == '/* html_static_path */\n', 'invalid default text'
11 # warning generated by here
12 copy_asset(
13 Path(__file__).resolve().parent.joinpath('myext_static', 'custom-styles.css'),
14 app.outdir / '_static',
15 )
16 # This demonstrates that no overwriting occurs
17 css_content = css.read_text(encoding='utf-8')
18 assert css_content == '/* html_static_path */\n', 'file overwritten!'
19 return []
20
21
22 def setup(app):
23 app.connect('html-collect-pages', _copy_asset_overwrite_hook)
24 app.add_css_file('custom-styles.css')