From: stevenknight Date: Sun, 27 Jul 2003 17:27:45 +0000 (+0000) Subject: Correct the spelling of validator. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6011667f7c321c4edcc19a20f93018fa0d43116a;p=scons.git Correct the spelling of validator. git-svn-id: http://scons.tigris.org/svn/scons/trunk@752 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/doc/man/scons.1 b/doc/man/scons.1 index 29b2bb2e..f8df0bd9 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -3819,7 +3819,7 @@ opts = Options(None, {FOO:'expansion', BAR:7}) 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. @@ -3827,7 +3827,7 @@ 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 diff --git a/src/CHANGES.txt b/src/CHANGES.txt index db99ddcb..acefe967 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -58,6 +58,9 @@ RELEASE 0.XX - XXX 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 diff --git a/src/RELEASE.txt b/src/RELEASE.txt index 298cfdaa..3cf87ca7 100644 --- a/src/RELEASE.txt +++ b/src/RELEASE.txt @@ -27,6 +27,11 @@ RELEASE 0.XX - XXX 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 diff --git a/src/engine/SCons/Options.py b/src/engine/SCons/Options.py index cbe642ac..45f607f4 100644 --- a/src/engine/SCons/Options.py +++ b/src/engine/SCons/Options.py @@ -29,9 +29,11 @@ variables to a scons build. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import os.path + import SCons.Errors import SCons.Util -import os.path +import SCons.Warnings class Options: @@ -55,14 +57,14 @@ 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. @@ -71,6 +73,13 @@ class Options: 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 @@ -78,7 +87,7 @@ class Options: option.key = key option.help = help option.default = default - option.validater = validater + option.validator = validator option.converter = converter self.options.append(option) @@ -129,8 +138,8 @@ class Options: # 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): """ diff --git a/src/engine/SCons/OptionsTests.py b/src/engine/SCons/OptionsTests.py index 90ff1538..87fbc9af 100644 --- a/src/engine/SCons/OptionsTests.py +++ b/src/engine/SCons/OptionsTests.py @@ -23,12 +23,14 @@ __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: @@ -73,14 +75,14 @@ class OptionsTestCase(unittest.TestCase): 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 @@ -93,6 +95,29 @@ class OptionsTestCase(unittest.TestCase): 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"""