Commit 96b9fe5b authored by Kai Lautaportti's avatar Kai Lautaportti

Fixed environment variable leaking between parts.

See http://github.com/hexagonit/hexagonit.recipe.cmmi/issues#issue/1
parent e306d1b2
......@@ -12,6 +12,10 @@ Change History
successful or not. Thanks to Jonathan Ballet for the report and preliminary
patch. [dokai]
- Fixed http://github.com/hexagonit/hexagonit.recipe.cmmi/issues#issue/1
Environment variables defined in one part will no longer leak to other
subsequent parts. [dokai]
1.3.0 (2009-09-20)
==================
......
......@@ -34,6 +34,8 @@ class Recipe(object):
options['compile-directory'] = options['path']
self.environ = {}
self.original_environment = os.environ.copy()
environment_section = self.options.get('environment-section', '').strip()
if environment_section and environment_section in buildout:
# Use environment variables from the designated config section.
......@@ -48,6 +50,14 @@ class Recipe(object):
for key in self.environ:
self.environ[key] = self.environ[key] % os.environ
def restore_environment(self):
"""Restores the original os.environ environment in case the recipe
made changes to it.
"""
if self.environ:
os.environ.clear()
os.environ.update(self.original_environment)
def update(self):
pass
......@@ -167,6 +177,7 @@ class Recipe(object):
'you can inspect what went wrong' % os.getcwd())
raise
finally:
self.restore_environment()
os.chdir(current_dir)
if self.options['url']:
......
......@@ -142,6 +142,29 @@ class NonInformativeTests(unittest.TestCase):
except:
pass
def test_environment_restored_after_building_a_part(self):
# Make sure the test variables do not exist beforehand
self.failIf('HRC_FOO' in os.environ)
self.failIf('HRC_BAR' in os.environ)
# Place a sentinel value to make sure the original environment is
# maintained
os.environ['HRC_SENTINEL'] = 'sentinel'
self.assertEquals(os.environ.get('HRC_SENTINEL'), 'sentinel')
recipe = self.make_recipe({}, 'test', {
'url' : 'file://%s/testdata/package-0.0.0.tar.gz' % os.path.dirname(__file__),
'environment' : 'HRC_FOO=bar\nHRC_BAR=foo'})
os.chdir(self.dir)
recipe.install()
# Make sure the test variables are not kept in the environment after
# the part has been built.
self.failIf('HRC_FOO' in os.environ)
self.failIf('HRC_BAR' in os.environ)
# Make sure the sentinel value is still in the environment
self.assertEquals(os.environ.get('HRC_SENTINEL'), 'sentinel')
def test_suite():
suite = unittest.TestSuite((
doctest.DocFileSuite(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment