Skip to content

Commit 1855784

Browse files
[3.12] GH-121970: Use SphinxDirective instead of Directive (GH-121972) (#122009)
GH-121970: Use ``SphinxDirective`` instead of ``Directive`` (GH-121972) (cherry picked from commit ac39151) Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
1 parent eedb44e commit 1855784

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

Diff for: Doc/tools/extensions/pyspecific.py

+16-20
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@
1515
from time import asctime
1616
from pprint import pformat
1717

18-
from docutils import nodes, utils
18+
from docutils import nodes
1919
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
2221
from sphinx import addnodes
2322
from sphinx.builders import Builder
2423
from sphinx.domains.python import PyFunction, PyMethod
@@ -52,7 +51,7 @@
5251
# Support for marking up and linking to bugs.python.org issues
5352

5453
def issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
55-
issue = utils.unescape(text)
54+
issue = unescape(text)
5655
# sanity check: there are no bpo issues within these two values
5756
if 47261 < int(issue) < 400000:
5857
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=[]):
6766
# Support for marking up and linking to GitHub issues
6867

6968
def gh_issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
70-
issue = utils.unescape(text)
69+
issue = unescape(text)
7170
# sanity check: all GitHub issues have ID >= 32426
7271
# even though some of them are also valid BPO IDs
7372
if int(issue) < 32426:
@@ -82,7 +81,7 @@ def gh_issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
8281

8382
# Support for marking up implementation details
8483

85-
class ImplementationDetail(Directive):
84+
class ImplementationDetail(SphinxDirective):
8685

8786
has_content = True
8887
final_argument_whitespace = True
@@ -214,7 +213,7 @@ def audit_events_merge(app, env, docnames, other):
214213
env.all_audit_events[name] = value
215214

216215

217-
class AuditEvent(Directive):
216+
class AuditEvent(SphinxDirective):
218217

219218
has_content = True
220219
required_arguments = 1
@@ -244,15 +243,14 @@ def run(self):
244243
text = label.format(name="``{}``".format(name),
245244
args=", ".join("``{}``".format(a) for a in args if a))
246245

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 = {}
250248

251249
new_info = {
252250
'source': [],
253251
'args': args
254252
}
255-
info = env.all_audit_events.setdefault(name, new_info)
253+
info = self.env.all_audit_events.setdefault(name, new_info)
256254
if info is not new_info:
257255
if not self._do_args_match(info['args'], new_info['args']):
258256
self.logger.warning(
@@ -272,7 +270,7 @@ def run(self):
272270
)
273271
ids.append(target)
274272

275-
info['source'].append((env.docname, target))
273+
info['source'].append((self.env.docname, target))
276274

277275
pnode = nodes.paragraph(text, classes=["audit-hook"], ids=ids)
278276
pnode.line = self.lineno
@@ -310,7 +308,7 @@ class audit_event_list(nodes.General, nodes.Element):
310308
pass
311309

312310

313-
class AuditEventListDirective(Directive):
311+
class AuditEventListDirective(SphinxDirective):
314312

315313
def run(self):
316314
return [audit_event_list('')]
@@ -395,7 +393,7 @@ def run(self):
395393

396394
# Support for documenting version of removal in deprecations
397395

398-
class DeprecatedRemoved(Directive):
396+
class DeprecatedRemoved(SphinxDirective):
399397
has_content = True
400398
required_arguments = 2
401399
optional_arguments = 1
@@ -411,8 +409,7 @@ def run(self):
411409
node['type'] = 'deprecated-removed'
412410
version = (self.arguments[0], self.arguments[1])
413411
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('.'))
416413
removed_version = tuple(int(e) for e in self.arguments[1].split('.'))
417414
if current_version < removed_version:
418415
label = self._deprecated_label
@@ -444,8 +441,7 @@ def run(self):
444441
classes=['versionmodified']),
445442
translatable=False)
446443
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)
449445
return [node] + messages
450446

451447

@@ -456,7 +452,7 @@ def run(self):
456452
whatsnew_re = re.compile(r"(?im)^what's new in (.*?)\??$")
457453

458454

459-
class MiscNews(Directive):
455+
class MiscNews(SphinxDirective):
460456
has_content = False
461457
required_arguments = 1
462458
optional_arguments = 0
@@ -471,7 +467,7 @@ def run(self):
471467
if not source_dir:
472468
source_dir = path.dirname(path.abspath(source))
473469
fpath = path.join(source_dir, fname)
474-
self.state.document.settings.record_dependencies.add(fpath)
470+
self.env.note_dependency(path.abspath(fpath))
475471
try:
476472
with io.open(fpath, encoding='utf-8') as fp:
477473
content = fp.read()

0 commit comments

Comments
 (0)