Skip to content

Commit 42d9399

Browse files
s-weigandpre-commit-ci[bot]trallard
authored
Fix error during linkcheck when trying to write pygments.css (#2097)
Hi there, I'm currently changing our docs to use your nice theme 😄 However, [our CI fails during lickcheck](https://github.com/s-weigand/pyglotaran-extras/actions/runs/12713637790/job/35441962465) since the parent folder where the theme tries to write `pygments.css` to does not exist during link checking. ```py Extension error (pydata_sphinx_theme.pygments): Handler <function overwrite_pygments_css at 0x7f93feb0e4d0> for event 'build-finished' threw an exception (exception: [Errno 2] No such file or directory: '/home/runner/work/pyglotaran-extras/pyglotaran-extras/docs/_build/linkcheck/_static/pygments.css') make: *** [Makefile:25: linkcheck] Error 2 make: Leaving directory '/home/runner/work/pyglotaran-extras/pyglotaran-extras/docs' ``` My workaround on our side is to [create the expected parent path for linkcheck](https://github.com/s-weigand/pyglotaran-extras/blob/f5b35f98e63e68dee73b347f175ee6c7abfe35f0/docs/conf.py#L27-L29) in our `conf.py` which [lets the CI pass again](https://github.com/s-weigand/pyglotaran-extras/actions/runs/12844533235/job/35817635012). This error didn't surface here for 2 reasons: - Linkchecking detects broken links, causing the function to [exit early](https://github.com/pydata/pydata-sphinx-theme/blob/d76892d437e3c0dc8a059741a84afbd6cc458509/src/pydata_sphinx_theme/pygments.py#L63) - The [HTML build folder is passed to linkcheck](https://github.com/pydata/pydata-sphinx-theme/blob/d76892d437e3c0dc8a059741a84afbd6cc458509/tox.ini#L44) --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Tania Allard <[email protected]>
1 parent 4a1e789 commit 42d9399

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/pydata_sphinx_theme/pygments.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,6 @@ def overwrite_pygments_css(app: Sphinx, exception=None):
9999

100100
# re-write pygments.css
101101
pygments_css = Path(app.builder.outdir) / "_static" / "pygments.css"
102-
with pygments_css.open("w") as f:
103-
f.write(get_pygments_stylesheet(light_theme, dark_theme))
102+
# Ensure the _static folder exists for all builders
103+
pygments_css.parent.mkdir(exist_ok=True)
104+
pygments_css.write_text(get_pygments_stylesheet(light_theme, dark_theme))

0 commit comments

Comments
 (0)