From 79b0f2445f2ff41bad792c5105ce1f6f142b21d9 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Fri, 22 Mar 2002 17:21:00 +0000 Subject: [PATCH] Make env['FOO'] by shorthand for env.Dictionary()['FOO'] (Anthony Roach) git-svn-id: http://scons.tigris.org/svn/scons/trunk@302 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- doc/man/scons.1 | 6 ++++++ src/engine/SCons/Environment.py | 9 +++++++++ src/engine/SCons/EnvironmentTests.py | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/doc/man/scons.1 b/doc/man/scons.1 index 5d8a0a5a..16c5e6b4 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -994,6 +994,12 @@ dict = env.Dictionary() dict["CC"] = "cc" .EE +or using the [] operator: + +.ES +env["CC"] = "cc" +.EE + Construction variables can also be passed to the construction environment constructor: diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index d997d6f5..65af179e 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -227,6 +227,15 @@ class Environment: dlist = dlist[0] return dlist + def __setitem__(self, key, value): + self._dict[key] = value + + def __getitem__(self, key): + return self._dict[key] + + def __delitem__(self, key): + del self._dict[key] + def Command(self, target, source, action): """Builds the supplied target files from the supplied source files using the supplied action. Action may diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index 86f179a5..654d432f 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -195,6 +195,12 @@ class EnvironmentTestCase(unittest.TestCase): assert env.Dictionary().has_key('CCFLAGS') assert env.Dictionary().has_key('ENV') + assert env['XXX'] == 'x' + env['XXX'] = 'foo' + assert env.Dictionary('XXX') == 'foo' + del env['XXX'] + assert not env.Dictionary().has_key('XXX') + def test_ENV(self): """Test setting the external ENV in Environments """ -- 2.26.2