Skip to content

Commit 66d0f8f

Browse files
committed
Tweak some docstrings for Options
Also change the build matrix on AppVeyor so we can hopefully get to a pass. Signed-off-by: Mats Wichmann <[email protected]>
1 parent 5ca36e8 commit 66d0f8f

File tree

2 files changed

+28
-38
lines changed

2 files changed

+28
-38
lines changed

.appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
image:
88
# linux builds done in Travis CI for now
9-
# - Visual Studio 2017
9+
- Visual Studio 2017
1010
- Visual Studio 2019
11-
- Visual Studio 2022
11+
#- Visual Studio 2022 XXX Temporary disable while failing on .10 versions
1212

1313
cache:
1414
- downloads -> appveyor.yml

SCons/Script/SConsOptions.py

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,11 @@ def diskcheck_convert(value):
6868
class SConsValues(optparse.Values):
6969
"""Holder class for uniform access to SCons options.
7070
71-
Usable whether or not of whether they can be set on the command line
72-
or in the SConscript files (using the :func:`~SComs.Main.SetOption`
73-
function).
74-
7571
A SCons option value can originate three different ways:
7672
77-
1) set on the command line;
78-
2) set in an SConscript file;
79-
3) the default setting (from the the ``op.add_option``
73+
1. set on the command line.
74+
2. set in an SConscript file via :func:`~SCons.Script.Main.SetOption`.
75+
3. the default setting (from the the ``op.add_option()``
8076
calls in the :func:`Parser` function, below).
8177
8278
The command line always overrides a value set in a SConscript file,
@@ -88,11 +84,10 @@ class SConsValues(optparse.Values):
8884
8985
The solution implemented in this class is to keep these different sets
9086
of settings separate (command line, SConscript file, and default)
91-
and to override the :meth:`__getattr__` method to check them in turn
92-
(a little similar in concept to a ChainMap).
93-
This should allow the rest of the code to just fetch values as
94-
attributes of an instance of this class, without having to worry
95-
about where they came from.
87+
and to override the :meth:`__getattr__` method to check them in turn.
88+
This allows the rest of the code to just fetch values as attributes of
89+
an instance of this class, without having to worry about where they
90+
came from (the scheme is similar to a ``ChainMap``).
9691
9792
Note that not all command line options are settable from SConscript
9893
files, and the ones that are must be explicitly added to the
@@ -107,27 +102,22 @@ def __init__(self, defaults) -> None:
107102
def __getattr__(self, attr):
108103
"""Fetch an options value, respecting priority rules.
109104
110-
Check first for explicit settings from the command line
111-
(which are direct attributes), then the SConscript file settings,
112-
then the default values.
105+
This is a little tricky: since we're answering questions
106+
about outselves, we have avoid lookups that would send us into
107+
into infinite recursion, thus the ``__dict__`` stuff.
113108
"""
114109
try:
115-
return self.__dict__[attr]
110+
return self.__dict__[attr]
116111
except KeyError:
117112
try:
118113
return self.__dict__['__SConscript_settings__'][attr]
119114
except KeyError:
120115
try:
121116
return getattr(self.__dict__['__defaults__'], attr)
122-
except KeyError:
123-
# Added because with py3 this is a new class,
124-
# not a classic class, and due to the way
125-
# In that case it will create an object without
126-
# __defaults__, and then query for __setstate__
127-
# which will throw an exception of KeyError
128-
# deepcopy() is expecting AttributeError if __setstate__
129-
# is not available.
130-
raise AttributeError(attr)
117+
except KeyError as exc:
118+
# Need to respond with AttributeError because
119+
# deepcopy expects that if __setstate__ is not available.
120+
raise AttributeError(attr) from exc
131121

132122
# keep this list in sync with the SetOption doc in SCons/Script/Main.xml
133123
# search for UPDATE_SETOPTION_DOCS there.
@@ -153,15 +143,17 @@ def __getattr__(self, attr):
153143
'warn',
154144
]
155145

156-
def set_option(self, name, value):
146+
def set_option(self, name: str, value) -> None:
157147
"""Sets an option *name* from an SConscript file.
158148
159-
Any necessary validation steps are in-line here. Validation should
160-
be along the same lines as for options processed from the command
161-
line - it's kind of a pain to have to duplicate. On the other
162-
hand, we can hope that the build maintainer will be more careful
163-
about correct SetOption values and it's not as big a deal to
164-
have validation for everything.
149+
Vvalidation steps for known (that is, defined in SCons itself)
150+
options are in-line here. Validation should be along the same
151+
lines as for options processed from the command line -
152+
it's kind of a pain to have to duplicate. Project-defined options
153+
can specify callbacks for the command-line version, but will have
154+
no inbuilt validation here. It's up to the build system maintainer
155+
to make sure :func:`~SCons.Script.Main.SetOption` is being used
156+
correctly, we can't really do any better here.
165157
166158
Raises:
167159
UserError: the option is not settable.
@@ -313,9 +305,7 @@ class SConsOptionParser(optparse.OptionParser):
313305
raise_exception_on_error = False
314306

315307
def error(self, msg):
316-
"""
317-
overridden OptionValueError exception handler
318-
"""
308+
"""Overridden OptionValueError exception handler."""
319309
if self.raise_exception_on_error:
320310
raise SConsBadOptionError(msg, self)
321311
else:
@@ -399,7 +389,7 @@ def _process_long_opt(self, rargs, values):
399389
def reparse_local_options(self) -> None:
400390
"""Re-parse the leftover command-line options.
401391
402-
Parse options are stored in ``self.largs``, so that any value
392+
Leftover options are stored in ``self.largs``, so that any value
403393
overridden on the command line is immediately available
404394
if the user turns around and does a :func:`~SCons.Script.Main.GetOption`
405395
right away.

0 commit comments

Comments
 (0)