Options objects have the following methods:
.TP
-.RI Add( key ", [" help ", " default ", " validater ", " converter ])
+.RI Add( key ", [" help ", " default ", " validator ", " converter ])
This adds a customizable construction variable to the Options object.
.I key
is the name of the variable.
is the help text for the variable.
.I default
is the default value of the variable.
-.I validater
+.I validator
is called to validate the value of the variable, and should take three
arguments: key, value, and environment
.I converter
distutils warning message about adding the (incorrect) library
directory to your search path.
+ - Correct the spelling of the "validater" option to "validator."
+ Add a DeprecatedWarning when the old spelling is used.
+
From Gary Oberbrunner:
- Report the target being built in error messages when building
Please note the following important changes since release 0.90:
+ - The spelling of the 'validater' keyword argument to the
+ Options.Add() method has been corrected to 'validator'. The old
+ spelling still works but has been deprecated and generates a
+ warning.
+
Please note the following important changes since release 0.14:
- SCons now tries to verify that Microsoft Visual Studio (including
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import os.path
+
import SCons.Errors
import SCons.Util
-import os.path
+import SCons.Warnings
class Options:
self.files = files
- def Add(self, key, help="", default=None, validater=None, converter=None):
+ def Add(self, key, help="", default=None, validator=None, converter=None, **kw):
"""
Add an option.
key - the name of the variable
help - optional help text for the options
default - optional default value
- validater - optional function that is called to validate the option's value
+ validator - optional function that is called to validate the option's value
Called with (key, value, environment)
converter - optional function that is called to convert the option's value before
putting it in the environment.
if not SCons.Util.is_valid_construction_var(key):
raise SCons.Errors.UserError, "Illegal Options.Add() key `%s'" % key
+ if kw.has_key('validater'):
+ SCons.Warnings.warn(SCons.Warnings.DeprecatedWarning,
+ "The 'validater' keyword of the Options.Add() method is deprecated\n" +\
+ "and should be changed to 'validator'.")
+ if validator is None:
+ validator = kw['validater']
+
class Option:
pass
option.key = key
option.help = help
option.default = default
- option.validater = validater
+ option.validator = validator
option.converter = converter
self.options.append(option)
# Finally validate the values:
for option in self.options:
- if option.validater:
- option.validater(option.key, env.subst('${%s}'%option.key), env)
+ if option.validator:
+ option.validator(option.key, env.subst('${%s}'%option.key), env)
def Save(self, filename, env):
"""
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import string
+import sys
import unittest
import TestSCons
+
import SCons.Options
import SCons.Util
-import sys
-import string
+import SCons.Warnings
class Environment:
assert o.key == 'VAR'
assert o.help == ''
assert o.default == None
- assert o.validater == None
+ assert o.validator == None
assert o.converter == None
o = opts.options[1]
assert o.key == 'ANSWER'
assert o.help == 'THE answer to THE question'
assert o.default == "42"
- o.validater(o.key, o.converter(o.default), {})
+ o.validator(o.key, o.converter(o.default), {})
def test_it(var, opts=opts):
exc_caught = None
test_it('foo-bar')
test_it('foo.bar')
+ save = {}
+ save['warn'] = SCons.Warnings.warn
+ save['DeprecatedWarning'] = SCons.Warnings.DeprecatedWarning
+ def warn(type, message, save=save):
+ save['type'] = type
+ save['message'] = message
+ SCons.Warnings.warn = warn
+ SCons.Warnings.DeprecatedWarning = "xyzzy"
+
+ try:
+ opts.Add('MISSPELLED',
+ 'test using the old validater keyword',
+ "42",
+ validater=check,
+ converter=lambda x: int(x) + 12)
+ finally:
+ SCons.Warnings.DeprecatedWarning = save['DeprecatedWarning']
+ SCons.Warnings.warn = save['warn']
+ assert save['type'] == "xyzzy", save['type']
+ assert string.find(save['message'], "keyword of the Options.Add() method", save['message'] != -1), save['message']
+ o = opts.options[2]
+ o.validator(o.key, o.converter(o.default), {})
+
def test_Update(self):
"""Test updating an Environment"""