1
1
#
2
- # Copyright (C) 2023 , Advanced Micro Devices, Inc. All rights reserved.
2
+ # Copyright (C) 2025 , Advanced Micro Devices, Inc. All rights reserved.
3
3
# SPDX-License-Identifier: MIT
4
4
#
5
5
6
6
import os
7
+
7
8
from sphinx .util import logging
8
9
9
10
logger = logging .getLogger (__name__ )
10
11
12
+
11
13
def update_jupyter_notebook_toc_placeholder (app , docname , source ):
12
14
"""
13
15
Replace THE *.ipynb references by *.rst from @quark_jupyter_notebook_toc_placeholder@ toc when QUARK_SPHINX_BUILD_SKIP_TUTORIALS is set on env var
@@ -21,32 +23,43 @@ def update_jupyter_notebook_toc_placeholder(app, docname, source):
21
23
```
22
24
"""
23
25
24
- jupyter_notebook_index_rst = os .path .join (' source' , ' jupyter_notebook_index.rst_' )
26
+ jupyter_notebook_index_rst = os .path .join (" source" , " jupyter_notebook_index.rst_" )
25
27
if "READTHEDOCS" in os .environ :
26
28
READTHEDOCS_REPOSITORY_PATH = os .environ .get ("READTHEDOCS_REPOSITORY_PATH" )
27
- jupyter_notebook_index_rst = os .path .join (READTHEDOCS_REPOSITORY_PATH , 'docs' , 'source' , 'jupyter_notebook_index.rst_' )
28
- jupyter_notebook_toc_placeholder = '@quark_jupyter_notebook_toc_placeholder@'
29
- with open (jupyter_notebook_index_rst , 'r' ) as f :
29
+ jupyter_notebook_index_rst = os .path .join (
30
+ READTHEDOCS_REPOSITORY_PATH , "docs" , "source" , "jupyter_notebook_index.rst_"
31
+ )
32
+ jupyter_notebook_toc_placeholder = "@quark_jupyter_notebook_toc_placeholder@"
33
+ with open (jupyter_notebook_index_rst ) as f :
30
34
quark_jupyter_notebook_toc = f .read ().strip ()
31
35
32
- generate_jupyter_notebook_docs = "QUARK_SPHINX_BUILD_SKIP_TUTORIALS" not in os .environ or os .environ ["QUARK_SPHINX_BUILD_SKIP_TUTORIALS" ].lower () in ("0" , "false" , "off" )
36
+ generate_jupyter_notebook_docs = "QUARK_SPHINX_BUILD_SKIP_TUTORIALS" not in os .environ or os .environ [
37
+ "QUARK_SPHINX_BUILD_SKIP_TUTORIALS"
38
+ ].lower () in ("0" , "false" , "off" )
33
39
if not generate_jupyter_notebook_docs :
34
- quark_jupyter_notebook_toc = quark_jupyter_notebook_toc .replace (' .ipynb' , ' .rst' )
40
+ quark_jupyter_notebook_toc = quark_jupyter_notebook_toc .replace (" .ipynb" , " .rst" )
35
41
36
- if jupyter_notebook_toc_placeholder in source [0 ]: # Only process documents containing `jupyter_notebook_toc_placeholder`
42
+ if (
43
+ jupyter_notebook_toc_placeholder in source [0 ]
44
+ ): # Only process documents containing `jupyter_notebook_toc_placeholder`
37
45
source [0 ] = source [0 ].replace (jupyter_notebook_toc_placeholder , quark_jupyter_notebook_toc )
38
- if '.rst' in quark_jupyter_notebook_toc :
39
- logger .info (f'Replaced { jupyter_notebook_toc_placeholder } with ReStructuredText tutorials at jupyter_notebook_index_rst and indexed by { docname } .rst' )
46
+ if ".rst" in quark_jupyter_notebook_toc :
47
+ logger .info (
48
+ f"Replaced { jupyter_notebook_toc_placeholder } with ReStructuredText tutorials at jupyter_notebook_index_rst and indexed by { docname } .rst"
49
+ )
40
50
else :
41
- logger .info (f'Replaced { jupyter_notebook_toc_placeholder } with Jupyter Notebook tutorials at jupyter_notebook_index_rst and indexed by { docname } .rst' )
51
+ logger .info (
52
+ f"Replaced { jupyter_notebook_toc_placeholder } with Jupyter Notebook tutorials at jupyter_notebook_index_rst and indexed by { docname } .rst"
53
+ )
54
+
42
55
43
56
def setup (app ):
44
57
"""
45
58
Setup Sphinx extension
46
59
"""
47
- app .connect (' source-read' , update_jupyter_notebook_toc_placeholder )
60
+ app .connect (" source-read" , update_jupyter_notebook_toc_placeholder )
48
61
return {
49
- ' version' : ' 1.0' ,
50
- ' parallel_read_safe' : True ,
51
- ' parallel_write_safe' : True ,
62
+ " version" : " 1.0" ,
63
+ " parallel_read_safe" : True ,
64
+ " parallel_write_safe" : True ,
52
65
}
0 commit comments