"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "SCons/Variables/EnumVariable.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).

EnumVariable.py  (scons-4.2.0):EnumVariable.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 enumeration Variables. """Variable type for enumeration Variables.
This file defines the option type for SCons allowing only specified Enumeration variables allow selection of one from a specified set of values.
input-values.
Usage example:: Usage example::
opts = Variables() opts = Variables()
opts.Add( opts.Add(
EnumVariable( EnumVariable(
'debug', 'debug',
'debug output and symbols', help='debug output and symbols',
'no', default='no',
allowed_values=('yes', 'no', 'full'), allowed_values=('yes', 'no', 'full'),
map={}, map={},
ignorecase=2, ignorecase=2,
) )
) )
... ...
if env['debug'] == 'full': if env['debug'] == 'full':
... ...
""" """
__all__ = ['EnumVariable',] from typing import Tuple, Callable
import SCons.Errors import SCons.Errors
def _validator(key, val, env, vals): __all__ = ['EnumVariable',]
def _validator(key, val, env, vals) -> None:
if val not in vals: if val not in vals:
raise SCons.Errors.UserError( raise SCons.Errors.UserError(
'Invalid value for option %s: %s. Valid values are: %s' % (key, val , vals)) 'Invalid value for option %s: %s. Valid values are: %s' % (key, val , vals))
def EnumVariable(key, help, default, allowed_values, map={}, ignorecase=0): def EnumVariable(key, help, default, allowed_values, map={}, ignorecase=0) -> Tu
""" ple[str, str, str, Callable, Callable]:
"""Return a tuple describing an enumaration SCons Variable.
The input parameters describe an option with only certain values The input parameters describe an option with only certain values
allowed. They are returned with an appropriate converter and allowed. Returns A tuple including an appropriate converter and
validator appended. The result is usable for input to validator. The result is usable as input to :meth:`Add`.
Variables.Add().
'key' and 'default' are the values to be passed on to Variables.Add(). *key* and *default* are passed directly on to :meth:`Add`.
'help' will be appended by the allowed values automatically *help* is the descriptive part of the help text,
and will have the allowed values automatically appended.
'allowed_values' is a list of strings, which are allowed as values *allowed_values* is a list of strings, which are the allowed values
for this option. for this option.
The 'map'-dictionary may be used for converting the input value The *map*-dictionary may be used for converting the input value
into canonical values (e.g. for aliases). into canonical values (e.g. for aliases).
'ignorecase' defines the behaviour of the validator: The value of *ignorecase* defines the behaviour of the validator:
If ignorecase == 0, the validator/converter are case-sensitive.
If ignorecase == 1, the validator/converter are case-insensitive.
If ignorecase == 2, the validator/converter is case-insensitive and the
converted value will always be lower-case.
The 'validator' tests whether the value is in the list of allowed values. Th * 0: the validator/converter are case-sensitive.
e 'converter' converts input values * 1: the validator/converter are case-insensitive.
according to the given 'map'-dictionary (unmapped input values are returned * 2: the validator/converter is case-insensitive and the
unchanged). converted value will always be lower-case.
The *validator* tests whether the value is in the list of allowed values.
The *converter* converts input values according to the given
*map*-dictionary (unmapped input values are returned unchanged).
""" """
help = '%s (%s)' % (help, '|'.join(allowed_values)) help = '%s (%s)' % (help, '|'.join(allowed_values))
# define validator # define validator
if ignorecase >= 1: if ignorecase:
validator = lambda key, val, env: \ validator = lambda key, val, env: \
_validator(key, val.lower(), env, allowed_values) _validator(key, val.lower(), env, allowed_values)
else: else:
validator = lambda key, val, env: \ validator = lambda key, val, env: \
_validator(key, val, env, allowed_values) _validator(key, val, env, allowed_values)
# define converter # define converter
if ignorecase == 2: if ignorecase == 2:
converter = lambda val: map.get(val.lower(), val).lower() converter = lambda val: map.get(val.lower(), val).lower()
elif ignorecase == 1: elif ignorecase == 1:
converter = lambda val: map.get(val.lower(), val) converter = lambda val: map.get(val.lower(), val)
 End of changes. 14 change blocks. 
27 lines changed or deleted 29 lines changed or added

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