DOCS Fix console.html deploy (#3510)

Put `console.html` in `app.outdir`.

This was needed because readthedocs/readthedocs.org PR 9888 moved the outdir
This commit is contained in:
Hood Chatham 2023-01-25 09:31:06 -08:00 committed by GitHub
parent 1c2bf92a3f
commit c06f4d5dfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 15 deletions

View File

@ -133,13 +133,6 @@ dist/console.html: src/templates/console.html
cp $< $@ cp $< $@
sed -i -e 's#{{ PYODIDE_BASE_URL }}#$(PYODIDE_BASE_URL)#g' $@ sed -i -e 's#{{ PYODIDE_BASE_URL }}#$(PYODIDE_BASE_URL)#g' $@
.PHONY: docs/_build/html/console.html
docs/_build/html/console.html: src/templates/console.html
mkdir -p docs/_build/html
cp $< $@
sed -i -e 's#{{ PYODIDE_BASE_URL }}#$(PYODIDE_BASE_URL)#g' $@
.PHONY: dist/webworker.js .PHONY: dist/webworker.js
dist/webworker.js: src/templates/webworker.js dist/webworker.js: src/templates/webworker.js
cp $< $@ cp $< $@

View File

@ -178,31 +178,35 @@ html_title = f"Version {version}"
global_replacements = {"{{PYODIDE_CDN_URL}}": CDN_URL, "{{VERSION}}": version} global_replacements = {"{{PYODIDE_CDN_URL}}": CDN_URL, "{{VERSION}}": version}
if IN_READTHEDOCS: def write_console_html(app):
# Make console.html file # Make console.html file
env = {"PYODIDE_BASE_URL": CDN_URL} env = {"PYODIDE_BASE_URL": CDN_URL}
os.makedirs("_build/html", exist_ok=True) os.makedirs(app.outdir, exist_ok=True)
os.makedirs("../dist", exist_ok=True)
res = subprocess.check_output( res = subprocess.check_output(
["make", "-C", "..", "docs/_build/html/console.html"], ["make", "-C", "..", "dist/console.html"],
env=env, env=env,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
encoding="utf-8", encoding="utf-8",
) )
print(res) print(res)
# insert the Plausible analytics script to console.html # insert the Plausible analytics script to console.html
console_path = Path("_build/html/console.html") console_html_lines = (
console_html = console_path.read_text().splitlines(keepends=True) Path("../dist/console.html").read_text().splitlines(keepends=True)
for idx, line in enumerate(list(console_html)): )
for idx, line in enumerate(list(console_html_lines)):
if 'pyodide.js">' in line: if 'pyodide.js">' in line:
# insert the analytics script after the `pyodide.js` script # insert the analytics script after the `pyodide.js` script
console_html.insert( console_html_lines.insert(
idx, idx,
'<script defer data-domain="pyodide.org" src="https://plausible.io/js/plausible.js"></script>\n', '<script defer data-domain="pyodide.org" src="https://plausible.io/js/plausible.js"></script>\n',
) )
break break
else: else:
raise ValueError("Could not find pyodide.js in the <head> section") raise ValueError("Could not find pyodide.js in the <head> section")
console_path.write_text("".join(console_html)) output_path = Path(app.outdir) / "console.html"
output_path.write_text("".join(console_html_lines))
if IN_SPHINX: if IN_SPHINX:
@ -283,3 +287,4 @@ def typehints_formatter(annotation, config):
def setup(app): def setup(app):
app.add_config_value("global_replacements", {}, True) app.add_config_value("global_replacements", {}, True)
app.connect("source-read", globalReplace) app.connect("source-read", globalReplace)
write_console_html(app)