"Fossies" - the Fresh Open Source Software Archive  

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

ListVariable.py  (scons-4.2.0):ListVariable.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 list Variables. """Variable type for list Variables.
This file defines the option type for SCons implementing 'lists'.
A 'list' option may either be 'all', 'none' or a list of names A 'list' option may either be 'all', 'none' or a list of names
separated by comma. After the option has been processed, the option separated by comma. After the option has been processed, the option
value holds either the named list elements, all list elements or no value holds either the named list elements, all list elements or no
list elements at all. list elements at all.
Usage example:: Usage example::
list_of_libs = Split('x11 gl qt ical') list_of_libs = Split('x11 gl qt ical')
opts = Variables() opts = Variables()
opts.Add( opts.Add(
ListVariable( ListVariable(
'shared', 'shared',
'libraries to build as shared libraries', help='libraries to build as shared libraries',
'all', default='all',
elems=list_of_libs, elems=list_of_libs,
) )
) )
... ...
for lib in list_of_libs: for lib in list_of_libs:
if lib in env['shared']: if lib in env['shared']:
env.SharedObject(...) env.SharedObject(...)
else: else:
env.Object(...) env.Object(...)
""" """
# Known Bug: This should behave like a Set-Type, but does not really, # Known Bug: This should behave like a Set-Type, but does not really,
# since elements can occur twice. # since elements can occur twice.
__all__ = ['ListVariable',]
import collections import collections
from typing import Tuple, Callable
import SCons.Util import SCons.Util
__all__ = ['ListVariable',]
class _ListVariable(collections.UserList): class _ListVariable(collections.UserList):
def __init__(self, initlist=[], allowedElems=[]): def __init__(self, initlist=None, allowedElems=None):
collections.UserList.__init__(self, [_f for _f in initlist if _f]) if initlist is None:
initlist = []
if allowedElems is None:
allowedElems = []
super().__init__([_f for _f in initlist if _f])
self.allowedElems = sorted(allowedElems) self.allowedElems = sorted(allowedElems)
def __cmp__(self, other): def __cmp__(self, other):
raise NotImplementedError raise NotImplementedError
def __eq__(self, other): def __eq__(self, other):
raise NotImplementedError raise NotImplementedError
def __ge__(self, other): def __ge__(self, other):
raise NotImplementedError raise NotImplementedError
def __gt__(self, other): def __gt__(self, other):
raise NotImplementedError raise NotImplementedError
def __le__(self, other): def __le__(self, other):
raise NotImplementedError raise NotImplementedError
def __lt__(self, other): def __lt__(self, other):
raise NotImplementedError raise NotImplementedError
def __str__(self): def __str__(self):
if len(self) == 0: if not len(self):
return 'none' return 'none'
self.data.sort() self.data.sort()
if self.data == self.allowedElems: if self.data == self.allowedElems:
return 'all' return 'all'
else: else:
return ','.join(self) return ','.join(self)
def prepare_to_store(self): def prepare_to_store(self):
return self.__str__() return self.__str__()
def _converter(val, allowedElems, mapdict): def _converter(val, allowedElems, mapdict) -> _ListVariable:
""" """ """
"""
if val == 'none': if val == 'none':
val = [] val = []
elif val == 'all': elif val == 'all':
val = allowedElems val = allowedElems
else: else:
val = [_f for _f in val.split(',') if _f] val = [_f for _f in val.split(',') if _f]
val = [mapdict.get(v, v) for v in val] val = [mapdict.get(v, v) for v in val]
notAllowed = [v for v in val if v not in allowedElems] notAllowed = [v for v in val if v not in allowedElems]
if notAllowed: if notAllowed:
raise ValueError("Invalid value(s) for option: %s" % raise ValueError(
','.join(notAllowed)) "Invalid value(s) for option: %s" % ','.join(notAllowed)
)
return _ListVariable(val, allowedElems) return _ListVariable(val, allowedElems)
## def _validator(key, val, env): # def _validator(key, val, env) -> None:
## """ # """ """
## """ # # TODO: write validator for pgk list
## # todo: write validator for pgk list # pass
## return 1
def ListVariable(key, help, default, names, map={}) -> Tuple[str, str, str, None
, Callable]:
"""Return a tuple describing a list SCons Variable.
The input parameters describe a 'list' option. Returns
a tuple including the correct converter and validator.
The result is usable for input to :meth:`Add`.
def ListVariable(key, help, default, names, map={}): *help* will have text appended indicating the legal values
""" (not including any extra names from *map*).
The input parameters describe a 'package list' option, thus they
are returned with the correct converter and validator appended. The *map* can be used to map alternative names to the ones in *names* -
result is usable for input to opts.Add() . that is, a form of alias.
A 'package list' option may either be 'all', 'none' or a list of A 'list' option may either be 'all', 'none' or a list of
package names (separated by space). names (separated by commas).
""" """
names_str = 'allowed names: %s' % ' '.join(names) names_str = 'allowed names: %s' % ' '.join(names)
if SCons.Util.is_List(default): if SCons.Util.is_List(default):
default = ','.join(default) default = ','.join(default)
help = '\n '.join( help = '\n '.join(
(help, '(all|none|comma-separated list of names)', names_str)) (help, '(all|none|comma-separated list of names)', names_str))
return (key, help, default, return (key, help, default, None, lambda val: _converter(val, names, map))
None, #_validator,
lambda val: _converter(val, names, map))
# 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. 20 change blocks. 
30 lines changed or deleted 45 lines changed or added

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