1
1
import os
2
+ from functools import wraps
2
3
from typing import Any , Dict
3
4
5
+ from docutils import nodes
6
+ from sphinx import addnodes
4
7
from sphinx .application import Sphinx
5
8
from sphinx .application import logger
9
+ from sphinx .directives .other import TocTree
10
+
11
+
12
+ def NoWarnings (func ):
13
+ @wraps (func )
14
+ def wrapped (self , * args , ** kwargs ):
15
+ stream = self .state .document .reporter .stream
16
+ self .state .document .reporter .stream = None
17
+ ret = func (self , * args , ** kwargs )
18
+ self .state .document .reporter .stream = stream
19
+ ret = list (filter (lambda node : not isinstance (node , nodes .system_message ), ret ))
20
+ return ret
21
+
22
+ return wrapped
23
+
24
+
25
+ class NoWarningsToctree (TocTree ):
26
+ @NoWarnings
27
+ def run (self ):
28
+ return super ().run ()
29
+
30
+ @NoWarnings
31
+ def parse_content (self , toctree : addnodes .toctree ):
32
+ return super ().parse_content (toctree )
6
33
7
34
8
35
def on_rtd () -> bool :
@@ -22,40 +49,46 @@ def inject_changed_files(html_context: Dict[str, str], app: Sphinx) -> None:
22
49
res = requests .get (
23
50
f"https://api.github.com/repos/{ html_context ['github_user' ]} /{ html_context ['github_repo' ]} /pulls/{ html_context ['current_version' ]} /files"
24
51
)
52
+
25
53
if res .status_code != requests .codes .ok :
26
54
return
27
55
28
56
changes_rst = "" .join (
29
57
[
30
- ".. toctree::\n " ,
58
+ "\n " ,
59
+ ".. nowarningstoctree::\n " ,
31
60
" :maxdepth: 1\n " ,
32
61
" :caption: PR CHANGED FILES\n " ,
33
62
"\n " ,
34
63
]
35
64
)
36
65
66
+ if app .config .delta_inject_location is None :
67
+ inject_location = "index.rst"
68
+ else :
69
+ inject_location = app .config .delta_inject_location
70
+
37
71
for file_context in res .json ():
38
72
status : str = file_context ["status" ]
39
73
filename : str = file_context ["filename" ]
40
74
41
75
if app .config .delta_doc_path is None :
42
76
logger .error ("Required option delta_doc_path is not set!" )
43
- if status == "deleted " :
77
+ if status == "removed " :
44
78
continue
45
79
if not filename .startswith (app .config .delta_doc_path ):
46
80
continue
47
81
if not filename .endswith (".rst" ):
48
82
continue
49
83
50
- changes_rst += f" { os .path .relpath (filename , app .config .delta_doc_path )} \n "
84
+ rel_path = os .path .relpath (filename , app .config .delta_doc_path )
85
+ if rel_path == inject_location :
86
+ continue
87
+ changes_rst += f" { rel_path } \n "
51
88
52
89
changes_rst += "\n \n .. todolist::\n "
53
90
54
- if app .config .delta_inject_location is None :
55
- inject_location = "index.rst"
56
- else :
57
- inject_location = app .config .delta_inject_location
58
-
91
+ inject_location = os .path .join (app .srcdir , inject_location )
59
92
with open (inject_location , "a" ) as f :
60
93
f .write (changes_rst )
61
94
@@ -69,6 +102,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
69
102
app .connect ("config-inited" , config_inited )
70
103
app .add_config_value ("delta_doc_path" , None , str )
71
104
app .add_config_value ("delta_inject_location" , None , str )
105
+ app .add_directive ("nowarningstoctree" , NoWarningsToctree )
72
106
73
107
return {
74
108
"parallel_read_safe" : True ,
0 commit comments