Skip to content

Commit 9352481

Browse files
committed
More tweaks to Subst module docstring [skip ci]
Signed-off-by: Mats Wichmann <[email protected]>
1 parent 3a0e6f2 commit 9352481

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

SCons/Subst.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@
2525
2626
A substitution mini-language describes how SCons performs token
2727
replacement on strings or lists of strings that are intended for use
28-
in actions. A replaceble element is specified as ``${expression}``.
29-
``expression`` can refer to a construction variable within a given
30-
environment or to a Python expression. The curly braces can be omitted
31-
for variable references if there is no ambiguity with the following text.
32-
For technical reasons the unbraced ``$var`` form is preferable when it can
33-
be used. Doubling the ``$`` escapes its special meaning. The sequence
34-
``$(subexpression$)`` is used to indicate ``subexpression`` should be
35-
included in the substituted string if substitution is intended for a
36-
command line, and omitted if the substitution is to produce a string for
37-
signature (hash) computation. THe begin/end markers are always omitted
38-
in the substituted text.
28+
in actions. A replaceable element is specified as ``${expression}``,
29+
where ``expression`` is all the characters up to the matching closing
30+
brace. If ``expression`` is a construction variable reference, the
31+
braces can be omitted (this is preferred for performance reasons), in
32+
which case the expression ends at the first character not valid in a
33+
Python identifier. ``expression`` can also be Python code, which always
34+
requires braces. ``$(subexpression$)`` is used to indicate text to be
35+
included in the substituted string when a command line is being produced,
36+
and omitted if the string is being produced for signature (hash) calculation.
37+
The begin/end markers are always omitted in the substituted text.
38+
The special meaning of ``$`` can be escaped by doubling it, which
39+
eventually produces a single ``$`` in the output.
3940
4041
Substitution is recursive: the token replacement may produce new
4142
substitutable sequences, and work has to proceed until there are no more.
@@ -423,8 +424,8 @@ def expand(self, s, lvars):
423424
if s1 == '$':
424425
# In this case keep the double $'s which we'll later
425426
# swap for a single dollar sign as we need to retain
426-
# this information to properly avoid matching "$("" when
427-
# the actual text was "$$("" (or "$)"" when "$$)"" )
427+
# this information to properly avoid matching "$(" when
428+
# the actual text was "$$(" (or "$)" when "$$)" )
428429
return '$$'
429430
elif s1 in '()':
430431
return s
@@ -543,9 +544,9 @@ def sub_match(match):
543544
class ListSubber(UserList):
544545
"""A class to construct the results of a scons_subst_list() call.
545546
546-
Like StringSubber, this class binds a specific construction
547-
environment, mode, target and source with two methods
548-
(substitute() and expand()) that handle the expansion.
547+
Like :class:`StringSubber:class:`, this class binds a specific
548+
construction environment, mode, target and source with two methods
549+
(:meth:`substitute` and :meth:`expand`) that handle the expansion.
549550
550551
In addition, however, this class is used to track the state of
551552
the result(s) we're gathering so we can do the appropriate thing
@@ -572,11 +573,11 @@ def __init__(self, env, mode, conv, gvars) -> None:
572573
self.next_line()
573574

574575
def expanded(self, s) -> bool:
575-
"""Determines if the string s requires further expansion.
576+
"""Determine if the string *s* requires further expansion.
576577
577-
Due to the implementation of ListSubber expand will call
578-
itself 2 additional times for an already expanded string. This
579-
method is used to determine if a string is already fully
578+
Due to the implementation of :class:`ListSubber`, :meth:`expand`
579+
will call itself 2 additional times for an already expanded string.
580+
This method is used to determine if a string is already fully
580581
expanded and if so exit the loop early to prevent these
581582
recursive calls.
582583
"""
@@ -878,7 +879,7 @@ def scons_subst(strSubst, env, mode=SUBST_RAW, target=None, source=None, gvars={
878879
substitutions.
879880
880881
This is the work-horse function for substitutions in file names
881-
and the like. The companion scons_subst_list() function (below)
882+
and the like. The companion :func:`scons_subst_list` function
882883
handles separating command lines into lists of arguments, so see
883884
that function if that's what you're looking for.
884885
"""
@@ -959,7 +960,7 @@ def scons_subst_list(strSubst, env, mode=SUBST_RAW, target=None, source=None, gv
959960
"""Substitute construction variables in a string (or list or other
960961
object) and separate the arguments into a command list.
961962
962-
The companion scons_subst() function (above) handles basic
963+
The companion :func:`scons_subst` function handles basic
963964
substitutions within strings, so see that function instead
964965
if that's what you're looking for.
965966
"""
@@ -1009,7 +1010,7 @@ def scons_subst_once(strSubst, env, key):
10091010
10101011
This is used when setting a variable when copying or overriding values
10111012
in an Environment. We want to capture (expand) the old value before
1012-
we override it, so people can do things like:
1013+
we override it, so people can do things like::
10131014
10141015
env2 = env.Clone(CCFLAGS = '$CCFLAGS -g')
10151016

0 commit comments

Comments
 (0)