"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "SCons/Variables/BoolVariable.py" between
scons-4.2.0.tar.gz and SCons-4.3.0.tar.gz

About: SCons is a software construction tool (a Python script and a set of modules as a superior alternative to the classic "Make" build tool).

BoolVariable.py  (scons-4.2.0):BoolVariable.py  (SCons-4.3.0)
skipping to change at line 24 skipping to change at line 24
# in all copies or substantial portions of the Software. # in all copies or substantial portions of the Software.
# #
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""Option type for true/false Variables. """Variable type for true/false Variables.
Usage example:: Usage example::
opts = Variables() opts = Variables()
opts.Add(BoolVariable('embedded', 'build for an embedded system', 0)) opts.Add(BoolVariable('embedded', 'build for an embedded system', 0))
... ...
if env['embedded'] == 1: if env['embedded'] == 1:
... ...
""" """
__all__ = ['BoolVariable',] from typing import Tuple, Callable
import SCons.Errors import SCons.Errors
__true_strings = ('y', 'yes', 'true', 't', '1', 'on' , 'all' ) __all__ = ['BoolVariable',]
__false_strings = ('n', 'no', 'false', 'f', '0', 'off', 'none')
def _text2bool(val): TRUE_STRINGS = ('y', 'yes', 'true', 't', '1', 'on' , 'all')
""" FALSE_STRINGS = ('n', 'no', 'false', 'f', '0', 'off', 'none')
Converts strings to True/False depending on the 'truth' expressed by
the string. If the string can't be converted, the original value def _text2bool(val) -> bool:
will be returned. """Converts strings to True/False.
If *val* looks like it expresses a bool-like value, based on
the :data:`TRUE_STRINGS` and :data:`FALSE_STRINGS` tuples,
return the appropriate value.
See '__true_strings' and '__false_strings' for values considered This is usable as a converter function for SCons Variables.
'true' or 'false respectively.
This is usable as 'converter' for SCons' Variables. Raises:
ValueError: if the string cannot be converted.
""" """
lval = val.lower() lval = val.lower()
if lval in __true_strings: return True if lval in TRUE_STRINGS:
if lval in __false_strings: return False return True
if lval in FALSE_STRINGS:
return False
raise ValueError("Invalid value for boolean option: %s" % val) raise ValueError("Invalid value for boolean option: %s" % val)
def _validator(key, val, env): def _validator(key, val, env) -> None:
""" """Validates the given value to be either true or false.
Validates the given value to be either '0' or '1'.
This is usable as a validator function for SCons Variables.
This is usable as 'validator' for SCons' Variables. Raises:
KeyError: if key is not set in env
UserError: if key does not validate.
""" """
if not env[key] in (True, False): if not env[key] in (True, False):
raise SCons.Errors.UserError( raise SCons.Errors.UserError(
'Invalid value for boolean option %s: %s' % (key, env[key])) 'Invalid value for boolean option %s: %s' % (key, env[key])
)
def BoolVariable(key, help, default): def BoolVariable(key, help, default) -> Tuple[str, str, str, Callable, Callable]
""" :
The input parameters describe a boolean option, thus they are """Return a tuple describing a boolean SCons Variable.
returned with the correct converter and validator appended. The
'help' text will by appended by '(yes|no) to show the valid The input parameters describe a boolean option. Returns a tuple
valued. The result is usable for input to opts.Add(). including the correct converter and validator.
The *help* text will have ``(yes|no)`` automatically appended to show the
valid values. The result is usable as input to :meth:`Add`.
""" """
return (key, '%s (yes|no)' % help, default, help = '%s (yes|no)' % help
_validator, _text2bool) return (key, help, default, _validator, _text2bool)
# Local Variables: # Local Variables:
# tab-width:4 # tab-width:4
# indent-tabs-mode:nil # indent-tabs-mode:nil
# End: # End:
# vim: set expandtab tabstop=4 shiftwidth=4: # vim: set expandtab tabstop=4 shiftwidth=4:
 End of changes. 13 change blocks. 
27 lines changed or deleted 39 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)