Skip to content

Commit 06942c2

Browse files
authored
Merge pull request SCons#4707 from mwichmann/doc/doctools
Update docs for `SConsDoc` and `SConsExample`
2 parents 122b1b5 + 758bd26 commit 06942c2

File tree

3 files changed

+164
-104
lines changed

3 files changed

+164
-104
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
2727
- runtest.py once again finds "external" tests, such as the tests for
2828
tools in scons-contrib. An earlier rework had broken this. Fixes #4699.
2929
- Clarify how pre/post actions on an alias work.
30+
- Tweak the two doc-generation modules. The significant change is
31+
turning the introductory comment in bin/SConsExamples into a docstring
32+
that can be rendered by Sphinx, and updating that text. The rest is
33+
minor fiddling like switching to f-strings small doc changes.
3034
- Fix a couple of unit tests to not fail with Python 3.14. These involve
3135
bytecode and error message contents, and there was no problem with
3236
SCons itself using 3.14 in its current (just-before-freeze) state.

bin/SConsDoc.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# SPDX-FileCopyrightText: Copyright The SCons Foundation (https://scons.org)
44
# SPDX-License-Identifier: MIT
55

6-
"""Module for handling SCons documentation processing.
6+
"""
7+
SCons Documentation Processing module
8+
=====================================
79
810
This module parses home-brew XML files that document important SCons
911
components. Currently it handles Builders, Environment functions/methods,
@@ -18,6 +20,8 @@
1820
1921
Builder example:
2022
23+
.. code-block:: xml
24+
2125
<builder name="BUILDER">
2226
<summary>
2327
<para>This is the summary description of an SCons Builder.
@@ -29,7 +33,7 @@
2933
interpolated by specifying the &b-link-BUILDER; element.
3034
</para>
3135
32-
Unlike normal XML, blank lines are significant in these
36+
Unlike vanilla DocBook, blank lines are significant in these
3337
descriptions and serve to separate paragraphs.
3438
They'll get replaced in DocBook output with appropriate tags
3539
to indicate a new paragraph.
@@ -42,6 +46,8 @@
4246
4347
Function example:
4448
49+
.. code-block:: xml
50+
4551
<scons_function name="FUNCTION">
4652
<arguments signature="SIGTYPE">
4753
(arg1, arg2, key=value)
@@ -74,6 +80,8 @@
7480
7581
Construction variable example:
7682
83+
.. code-block:: xml
84+
7785
<cvar name="VARIABLE">
7886
<summary>
7987
<para>This is the summary description of a construction variable.
@@ -93,6 +101,8 @@
93101
94102
Tool example:
95103
104+
.. code-block:: xml
105+
96106
<tool name="TOOL">
97107
<summary>
98108
<para>This is the summary description of an SCons Tool.
@@ -223,7 +233,7 @@ def addEntity(self, name, uri):
223233
self.entries.append(DoctypeEntity(name, uri))
224234

225235
def createDoctype(self):
226-
content = '<!DOCTYPE %s [\n' % self.name
236+
content = f'<!DOCTYPE {self.name} [\n'
227237
for e in self.entries:
228238
content += e.getEntityString()
229239
content += ']>\n'
@@ -318,7 +328,7 @@ def prettyPrintFile(fpath):
318328

319329
@staticmethod
320330
def decorateWithHeader(root):
321-
root.attrib["{"+xsi+"}schemaLocation"] = "%s %s/scons.xsd" % (dbxsd, dbxsd)
331+
root.attrib["{"+xsi+"}schemaLocation"] = f"{dbxsd} {dbxsd}/scons.xsd"
322332
return root
323333

324334
def newXmlTree(self, root):
@@ -340,22 +350,22 @@ def validateXml(fpath, xmlschema_context):
340350
try:
341351
doc = etree.parse(fpath)
342352
except Exception as e:
343-
print("ERROR: %s fails to parse:"%fpath)
353+
print(f"ERROR: {fpath} fails to parse:")
344354
print(e)
345355
return False
346356
doc.xinclude()
347357
try:
348358
TreeFactory.xmlschema.assertValid(doc)
349359
except etree.XMLSchemaValidateError as e:
350-
print("ERROR: %s fails to validate:" % fpath)
360+
print(f"ERROR: {fpath} fails to validate:")
351361
print(e)
352362
print(e.error_log.last_error.message)
353-
print("In file: [%s]" % e.error_log.last_error.filename)
363+
print(f"In file: [{e.error_log.last_error.filename}]")
354364
print("Line : %d" % e.error_log.last_error.line)
355365
return False
356366

357367
except Exception as e:
358-
print("ERROR: %s fails to validate:" % fpath)
368+
print(f"ERROR: {fpath} fails to validate:")
359369
print(e)
360370

361371
return False
@@ -365,14 +375,14 @@ def validateXml(fpath, xmlschema_context):
365375
def findAll(root, tag, ns=None, xp_ctxt=None, nsmap=None):
366376
expression = ".//{%s}%s" % (nsmap[ns], tag)
367377
if not ns or not nsmap:
368-
expression = ".//%s" % tag
378+
expression = f".//{tag}"
369379
return root.findall(expression)
370380

371381
@staticmethod
372382
def findAllChildrenOf(root, tag, ns=None, xp_ctxt=None, nsmap=None):
373383
expression = "./{%s}%s/*" % (nsmap[ns], tag)
374384
if not ns or not nsmap:
375-
expression = "./%s/*" % tag
385+
expression = f"./{tag}/*"
376386
return root.findall(expression)
377387

378388
@staticmethod
@@ -495,7 +505,7 @@ def __str__(self):
495505
result = []
496506
for m in re.findall(r'([a-zA-Z/_]+|[^a-zA-Z/_]+)', s):
497507
if ' ' in m:
498-
m = '"%s"' % m
508+
m = f'"{m}"'
499509
result.append(m)
500510
return ' '.join(result)
501511
def append(self, data):

0 commit comments

Comments
 (0)