Commit 3872f74
[doc] add ipython3 lexer hook for notebooks with shell/magic cells (ray-project#63515)
## Description
Sphinx falls back to the `python3` lexer on `.ipynb` files that don't
declare `language_info.pygments_lexer`, but `python3` can't tokenise
`!shell` or `%magic` cells. The pygments warning is fatal under
Readthedocs `-W` and breaks the docs build.
This source-read hook injects `pygments_lexer = "ipython3"` into
notebooks matching configurable glob patterns (`ipython3_lexer_patterns`
/ `_exclude_patterns`). Globs cover the in-tree example layouts plus
`_collections/**/*.ipynb` for notebooks fetched at build time by
`sphinx_collections`.
Review feedback from the previous round on ray-project#59984 (early-return pattern,
no broad `except`) is preserved.
## Related issues
Related to ray-project#59984 (closed-stale 2026-02-07).
## Additional information
Verified locally with `make html` against `upstream/master` plus this
commit and a fixture notebook at `_collections/lexer-fixture/test.ipynb`
containing a `!pip install` cell and no `language_info`: build
succeeded, no `WARNING.*lexer` matches in the log, fixture confirmed
source-read.
Today most `_collections/` notebooks are excluded from the build via
`exclude_patterns` in favour of their `.md` counterparts, so the new
`_collections/**/*.ipynb` glob is mostly defensive. The exclude design
is upstream of this PR.
---------
Signed-off-by: Aydin Abiar <aydin@anyscale.com>
Signed-off-by: Neelansh Khare <kharen@uci.edu>1 parent b215adc commit 3872f74
1 file changed
Lines changed: 49 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
783 | 784 | | |
784 | 785 | | |
785 | 786 | | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
786 | 792 | | |
787 | 793 | | |
788 | 794 | | |
| |||
921 | 927 | | |
922 | 928 | | |
923 | 929 | | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
0 commit comments