@@ -68,15 +68,11 @@ def diskcheck_convert(value):
68
68
class SConsValues (optparse .Values ):
69
69
"""Holder class for uniform access to SCons options.
70
70
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
-
75
71
A SCons option value can originate three different ways:
76
72
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() ``
80
76
calls in the :func:`Parser` function, below).
81
77
82
78
The command line always overrides a value set in a SConscript file,
@@ -88,11 +84,10 @@ class SConsValues(optparse.Values):
88
84
89
85
The solution implemented in this class is to keep these different sets
90
86
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``).
96
91
97
92
Note that not all command line options are settable from SConscript
98
93
files, and the ones that are must be explicitly added to the
@@ -107,27 +102,22 @@ def __init__(self, defaults) -> None:
107
102
def __getattr__ (self , attr ):
108
103
"""Fetch an options value, respecting priority rules.
109
104
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 .
113
108
"""
114
109
try :
115
- return self .__dict__ [attr ]
110
+ return self .__dict__ [attr ]
116
111
except KeyError :
117
112
try :
118
113
return self .__dict__ ['__SConscript_settings__' ][attr ]
119
114
except KeyError :
120
115
try :
121
116
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
131
121
132
122
# keep this list in sync with the SetOption doc in SCons/Script/Main.xml
133
123
# search for UPDATE_SETOPTION_DOCS there.
@@ -153,15 +143,17 @@ def __getattr__(self, attr):
153
143
'warn' ,
154
144
]
155
145
156
- def set_option (self , name , value ):
146
+ def set_option (self , name : str , value ) -> None :
157
147
"""Sets an option *name* from an SConscript file.
158
148
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.
165
157
166
158
Raises:
167
159
UserError: the option is not settable.
@@ -313,9 +305,7 @@ class SConsOptionParser(optparse.OptionParser):
313
305
raise_exception_on_error = False
314
306
315
307
def error (self , msg ):
316
- """
317
- overridden OptionValueError exception handler
318
- """
308
+ """Overridden OptionValueError exception handler."""
319
309
if self .raise_exception_on_error :
320
310
raise SConsBadOptionError (msg , self )
321
311
else :
@@ -399,7 +389,7 @@ def _process_long_opt(self, rargs, values):
399
389
def reparse_local_options (self ) -> None :
400
390
"""Re-parse the leftover command-line options.
401
391
402
- Parse options are stored in ``self.largs``, so that any value
392
+ Leftover options are stored in ``self.largs``, so that any value
403
393
overridden on the command line is immediately available
404
394
if the user turns around and does a :func:`~SCons.Script.Main.GetOption`
405
395
right away.
0 commit comments