env = Environment(options=opts)
.EE
+.IP
+The text file(s) that were specified
+when the Options object was created
+are executed as Python scripts,
+and the values of (global) Python variables set in the file
+are added to the construction environment.
+Example:
+
+.ES
+CC = 'my_cc'
+.EE
+
.TP
.RI Save( filename ", " env )
This saves the currently set options into a script file named
Help(opts.GenerateHelpText(env, sort=cmp))
.EE
-The text based SConscript file is executed as a Python script, and the
-global variables are queried for customizable construction
-variables. Example:
+.TP
+.RI FormatOptionHelpText( env ", " opt ", " help ", " default ", " actual )
+This method returns a formatted string
+containing the printable help text
+for one option.
+It is normally not called directly,
+but is called by the
+.IR GenerateHelpText ()
+method to create the returned help text.
+It may be overridden with your own
+function that takes the arguments specified above
+and returns a string of help text formatted to your liking.
+Note that the
+.IR GenerateHelpText ()
+will not put any blank lines or extra
+characters in between the entries,
+so you must add those characters to the returned
+string if you want the entries separated.
.ES
-CC = 'my_cc'
+def my_format(env, opt, help, default, actual):
+ fmt = "\n%s: default=%s actual=%s (%s)\n"
+ return fmt % (opt, default. actual, help)
+opts.FormatOptionHelpText = my_format
.EE
To make it more convenient to work with customizable Options,
- Enhanced the SCons setup.py script to install man pages on
UNIX/Linux systems.
+ - Add support for an Options.FormatOptionHelpText() method that can
+ be overridden to customize the format of Options help text.
+
From Wayne Lee:
- Avoid "maximum recursion limit" errors when removing $(-$) pairs
'THIS_SHOULD_WORK' : 'baz' })
def test_GenerateHelpText(self):
+ """Test generating the default format help text"""
opts = SCons.Options.Options()
opts.Add('ANSWER',
"""
text = opts.GenerateHelpText(env, sort=cmp)
assert text == expectAlpha, text
+
+ def test_FormatOptionHelpText(self):
+ """Test generating custom format help text"""
+ opts = SCons.Options.Options()
+
+ def my_format(env, opt, help, default, actual):
+ return '%s %s %s %s\n' % (opt, default, actual, help)
+
+ opts.FormatOptionHelpText = my_format
+
+ opts.Add('ANSWER',
+ 'THE answer to THE question',
+ "42",
+ check,
+ lambda x: int(x) + 12)
+
+ opts.Add('B',
+ 'b - alpha test',
+ "42",
+ check,
+ lambda x: int(x) + 12)
+
+ opts.Add('A',
+ 'a - alpha test',
+ "42",
+ check,
+ lambda x: int(x) + 12)
+
+ env = Environment()
+ opts.Update(env, {})
+
+ expect = """\
+ANSWER 42 54 THE answer to THE question
+B 42 54 b - alpha test
+A 42 54 a - alpha test
+"""
+
+ text = opts.GenerateHelpText(env)
+ assert text == expect, text
+
+ expectAlpha = """\
+A 42 54 a - alpha test
+ANSWER 42 54 THE answer to THE question
+B 42 54 b - alpha test
+"""
+ text = opts.GenerateHelpText(env, sort=cmp)
+ assert text == expectAlpha, text
+
+
+
if __name__ == "__main__":
suite = unittest.makeSuite(OptionsTestCase, 'test_')
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import os.path
+import string
import SCons.Errors
import SCons.Util
else:
options = self.options
- for option in options:
- help_text = help_text + '\n%s: %s\n default: %s\n'%(option.key, option.help, option.default)
- if env.has_key(option.key):
- help_text = help_text + ' actual: %s\n'%env.subst('${%s}'%option.key)
+ def format(opt, self=self, env=env):
+ if env.has_key(opt.key):
+ actual = env.subst('${%s}' % opt.key)
else:
- help_text = help_text + ' actual: None\n'
+ actual = None
+ return self.FormatOptionHelpText(env, opt.key, opt.help, opt.default, actual)
+ lines = filter(None, map(format, options))
- return help_text
+ return string.join(lines, '')
+
+ format = '\n%s: %s\n default: %s\n actual: %s\n'
+
+ def FormatOptionHelpText(self, env, key, help, default, actual):
+ return self.format % (key, help, default, actual)