15
15
from time import asctime
16
16
from pprint import pformat
17
17
18
- from docutils import nodes , utils
18
+ from docutils import nodes
19
19
from docutils .io import StringOutput
20
- from docutils .parsers .rst import Directive
21
- from docutils .utils import new_document
20
+ from docutils .utils import new_document , unescape
22
21
from sphinx import addnodes
23
22
from sphinx .builders import Builder
24
23
from sphinx .domains .python import PyFunction , PyMethod
52
51
# Support for marking up and linking to bugs.python.org issues
53
52
54
53
def issue_role (typ , rawtext , text , lineno , inliner , options = {}, content = []):
55
- issue = utils . unescape (text )
54
+ issue = unescape (text )
56
55
# sanity check: there are no bpo issues within these two values
57
56
if 47261 < int (issue ) < 400000 :
58
57
msg = inliner .reporter .error (f'The BPO ID { text !r} seems too high -- '
@@ -67,7 +66,7 @@ def issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
67
66
# Support for marking up and linking to GitHub issues
68
67
69
68
def gh_issue_role (typ , rawtext , text , lineno , inliner , options = {}, content = []):
70
- issue = utils . unescape (text )
69
+ issue = unescape (text )
71
70
# sanity check: all GitHub issues have ID >= 32426
72
71
# even though some of them are also valid BPO IDs
73
72
if int (issue ) < 32426 :
@@ -82,7 +81,7 @@ def gh_issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
82
81
83
82
# Support for marking up implementation details
84
83
85
- class ImplementationDetail (Directive ):
84
+ class ImplementationDetail (SphinxDirective ):
86
85
87
86
has_content = True
88
87
final_argument_whitespace = True
@@ -214,7 +213,7 @@ def audit_events_merge(app, env, docnames, other):
214
213
env .all_audit_events [name ] = value
215
214
216
215
217
- class AuditEvent (Directive ):
216
+ class AuditEvent (SphinxDirective ):
218
217
219
218
has_content = True
220
219
required_arguments = 1
@@ -244,15 +243,14 @@ def run(self):
244
243
text = label .format (name = "``{}``" .format (name ),
245
244
args = ", " .join ("``{}``" .format (a ) for a in args if a ))
246
245
247
- env = self .state .document .settings .env
248
- if not hasattr (env , 'all_audit_events' ):
249
- env .all_audit_events = {}
246
+ if not hasattr (self .env , 'all_audit_events' ):
247
+ self .env .all_audit_events = {}
250
248
251
249
new_info = {
252
250
'source' : [],
253
251
'args' : args
254
252
}
255
- info = env .all_audit_events .setdefault (name , new_info )
253
+ info = self . env .all_audit_events .setdefault (name , new_info )
256
254
if info is not new_info :
257
255
if not self ._do_args_match (info ['args' ], new_info ['args' ]):
258
256
self .logger .warning (
@@ -272,7 +270,7 @@ def run(self):
272
270
)
273
271
ids .append (target )
274
272
275
- info ['source' ].append ((env .docname , target ))
273
+ info ['source' ].append ((self . env .docname , target ))
276
274
277
275
pnode = nodes .paragraph (text , classes = ["audit-hook" ], ids = ids )
278
276
pnode .line = self .lineno
@@ -310,7 +308,7 @@ class audit_event_list(nodes.General, nodes.Element):
310
308
pass
311
309
312
310
313
- class AuditEventListDirective (Directive ):
311
+ class AuditEventListDirective (SphinxDirective ):
314
312
315
313
def run (self ):
316
314
return [audit_event_list ('' )]
@@ -395,7 +393,7 @@ def run(self):
395
393
396
394
# Support for documenting version of removal in deprecations
397
395
398
- class DeprecatedRemoved (Directive ):
396
+ class DeprecatedRemoved (SphinxDirective ):
399
397
has_content = True
400
398
required_arguments = 2
401
399
optional_arguments = 1
@@ -411,8 +409,7 @@ def run(self):
411
409
node ['type' ] = 'deprecated-removed'
412
410
version = (self .arguments [0 ], self .arguments [1 ])
413
411
node ['version' ] = version
414
- env = self .state .document .settings .env
415
- current_version = tuple (int (e ) for e in env .config .version .split ('.' ))
412
+ current_version = tuple (int (e ) for e in self .config .version .split ('.' ))
416
413
removed_version = tuple (int (e ) for e in self .arguments [1 ].split ('.' ))
417
414
if current_version < removed_version :
418
415
label = self ._deprecated_label
@@ -444,8 +441,7 @@ def run(self):
444
441
classes = ['versionmodified' ]),
445
442
translatable = False )
446
443
node .append (para )
447
- env = self .state .document .settings .env
448
- env .get_domain ('changeset' ).note_changeset (node )
444
+ self .env .get_domain ('changeset' ).note_changeset (node )
449
445
return [node ] + messages
450
446
451
447
@@ -456,7 +452,7 @@ def run(self):
456
452
whatsnew_re = re .compile (r"(?im)^what's new in (.*?)\??$" )
457
453
458
454
459
- class MiscNews (Directive ):
455
+ class MiscNews (SphinxDirective ):
460
456
has_content = False
461
457
required_arguments = 1
462
458
optional_arguments = 0
@@ -471,7 +467,7 @@ def run(self):
471
467
if not source_dir :
472
468
source_dir = path .dirname (path .abspath (source ))
473
469
fpath = path .join (source_dir , fname )
474
- self .state . document . settings . record_dependencies . add (fpath )
470
+ self .env . note_dependency ( path . abspath (fpath ) )
475
471
try :
476
472
with io .open (fpath , encoding = 'utf-8' ) as fp :
477
473
content = fp .read ()
0 commit comments