From: stevenknight Date: Mon, 20 Sep 2004 19:33:34 +0000 (+0000) Subject: Allow ListOption to take a Python list of values asa default, not just a comma-separa... X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2598c91b75c58d9823f7b7d2075323379743dde0;p=scons.git Allow ListOption to take a Python list of values asa default, not just a comma-separated string containg the default values. git-svn-id: http://scons.tigris.org/svn/scons/trunk@1088 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/doc/man/scons.1 b/doc/man/scons.1 index c63a23a7..6399568f 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -7158,6 +7158,9 @@ or the values in the list. More than one value may be specified, with all values separated by commas. +The default may be a string of +comma-separated default values, +or a list of the default values. .TP .RI PackageOption( key ", " help ", " default ) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 1d015109..3fc014f3 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -57,6 +57,9 @@ RELEASE 0.97 - XXX so it prints a meaningful string, not the binary representation of the function contents. + - Allow a ListOption's default value(s) to be a Python list of specified + values, not just a string containing a comma-separated list of names. + From Elliot Murphy: - Enhance the tests to guarantee persistence of ListOption diff --git a/src/engine/SCons/Options/ListOption.py b/src/engine/SCons/Options/ListOption.py index 8a940370..903d52b1 100644 --- a/src/engine/SCons/Options/ListOption.py +++ b/src/engine/SCons/Options/ListOption.py @@ -57,6 +57,8 @@ __all__ = ('ListOption',) import string import UserList +import SCons.Util + class _ListOption(UserList.UserList): def __init__(self, initlist=[], allowedElems=[]): @@ -123,6 +125,8 @@ def ListOption(key, help, default, names): package names (separated by space). """ names_str = 'allowed names: %s' % string.join(names, ' ') + if SCons.Util.is_List(default): + default = string.join(default, ',') help = string.join( (help, '(all|none|comma-separated list of names)', names_str), '\n ') diff --git a/src/engine/SCons/Options/ListOptionTests.py b/src/engine/SCons/Options/ListOptionTests.py index ec339630..ec604f81 100644 --- a/src/engine/SCons/Options/ListOptionTests.py +++ b/src/engine/SCons/Options/ListOptionTests.py @@ -44,6 +44,14 @@ class ListOptionTestCase(unittest.TestCase): assert o.validator is None, o.validator assert not o.converter is None, o.converter + opts = SCons.Options.Options() + opts.Add(SCons.Options.ListOption('test2', 'test2 help', + ['one', 'three'], + ['one', 'two', 'three'])) + + o = opts.options[0] + assert o.default == 'one,three' + def test_converter(self): """Test the ListOption converter""" opts = SCons.Options.Options() diff --git a/test/OptionsTypes.py b/test/OptionsTypes.py index 5fef2579..41829053 100644 --- a/test/OptionsTypes.py +++ b/test/OptionsTypes.py @@ -201,6 +201,27 @@ Invalid value(s) for option: foo,bar File "SConstruct", line 14, in ? """, status=2) +test.write('SConstruct', """ +from SCons.Options import ListOption + +opts = Options(args=ARGUMENTS) +opts.AddOptions( + ListOption('gpib', + 'comment', + ['ENET', 'GPIB'], + names = ['ENET', 'GPIB', 'LINUX_GPIB', 'NO_GPIB']), + ) + +env = Environment(options=opts) +Help(opts.GenerateHelpText(env)) + +print env['gpib'] +Default(env.Alias('dummy', None)) +""") + +test.run(stdout=test.wrap_stdout(read_str="ENET,GPIB\n", build_str="""\ +scons: Nothing to be done for `dummy'. +""")) #### test PackageOption ####