[Checkins] SVN: zc.recipe.cmmi/trunk/src/zc/recipe/cmmi/ - Fixed: Spaces weren't allowed in environment variables.

Jim Fulton jim at zope.com
Sat Aug 6 11:57:38 EDT 2011


Log message for revision 122481:
  - Fixed: Spaces weren't allowed in environment variables.
  

Changed:
  U   zc.recipe.cmmi/trunk/src/zc/recipe/cmmi/__init__.py
  U   zc.recipe.cmmi/trunk/src/zc/recipe/cmmi/misc.txt
  U   zc.recipe.cmmi/trunk/src/zc/recipe/cmmi/tests.py

-=-
Modified: zc.recipe.cmmi/trunk/src/zc/recipe/cmmi/__init__.py
===================================================================
--- zc.recipe.cmmi/trunk/src/zc/recipe/cmmi/__init__.py	2011-08-05 21:52:16 UTC (rev 122480)
+++ zc.recipe.cmmi/trunk/src/zc/recipe/cmmi/__init__.py	2011-08-06 15:57:37 UTC (rev 122481)
@@ -19,12 +19,15 @@
 import logging
 import os
 import os.path
+import re
 import setuptools.archive_util
 import shutil
 import tempfile
 import zc.buildout
 import zc.buildout.download
 
+almost_environment_setting = re.compile('\w+=').match
+not_starting_with_digit = re.compile('\D').match
 
 def system(c):
     if os.system(c):
@@ -49,9 +52,19 @@
         self.patch = self.options.get('patch', '')
         self.patch_options = self.options.get('patch_options', '-p0')
 
-        self.environ = self.options.get('environment', '').split()
-        if self.environ:
-            self.environ = dict([x.split('=', 1) for x in self.environ])
+        environ = []
+        for token in self.options.get('environment', '').split():
+            if (almost_environment_setting(token) and
+                not_starting_with_digit(token)):
+                environ.append(token)
+            else:
+                if environ:
+                    environ[-1] += ' ' + token
+                else:
+                    raise ValueError('Bad environment setting', token)
+
+        if environ:
+            self.environ = dict([x.split('=', 1) for x in environ])
         else:
             self.environ = {}
 
@@ -72,7 +85,8 @@
             else:
                 if not download_cache:
                     raise ValueError(
-                        "Set the 'shared' option of zc.recipe.cmmi to an existing"
+                        "Set the 'shared' option of zc.recipe.cmmi"
+                        " to an existing"
                         " directory, or set ${buildout:download-cache}")
 
                 self.shared = os.path.join(
@@ -128,7 +142,7 @@
             if is_temp:
                 os.remove(fname)
 
-        for key, value in self.environ.items():
+        for key, value in sorted(self.environ.items()):
             logger.info('Updating environment: %s=%s' % (key, value))
         os.environ.update(self.environ)
 

Modified: zc.recipe.cmmi/trunk/src/zc/recipe/cmmi/misc.txt
===================================================================
--- zc.recipe.cmmi/trunk/src/zc/recipe/cmmi/misc.txt	2011-08-05 21:52:16 UTC (rev 122480)
+++ zc.recipe.cmmi/trunk/src/zc/recipe/cmmi/misc.txt	2011-08-06 15:57:37 UTC (rev 122481)
@@ -72,3 +72,37 @@
 
     >>> os.path.isdir(join(sample_buildout, "parts", "foo"))
     False
+
+Spaces in environment variables
+-------------------------------
+
+Unfortunately, environment option parsing is simplistic and makes it
+hard to include spaces.  We allow spaces if the tokens after spaves
+aren't of the form NAME=.....
+
+
+    >>> distros_url = start_server(distros)
+
+    >>> write('buildout.cfg',
+    ... """
+    ... [buildout]
+    ... parts = foo
+    ...
+    ... [foo]
+    ... recipe = zc.recipe.cmmi
+    ... url = %sfoo.tgz
+    ... environment =
+    ...   CFLAGS=-I/yyy -I/xxx --x=y 2=1+1 a=b
+    ... """ % distros_url)
+
+    >>> print system('bin/buildout'),
+    Installing foo.
+    foo: Downloading http://localhost/foo.tgz
+    foo: Unpacking and configuring
+    foo: Updating environment: CFLAGS=-I/yyy -I/xxx --x=y 2=1+1
+    foo: Updating environment: a=b
+    configuring foo --prefix=/sample_buildout/parts/foo
+    echo building foo
+    building foo
+    echo installing foo
+    installing foo

Modified: zc.recipe.cmmi/trunk/src/zc/recipe/cmmi/tests.py
===================================================================
--- zc.recipe.cmmi/trunk/src/zc/recipe/cmmi/tests.py	2011-08-05 21:52:16 UTC (rev 122480)
+++ zc.recipe.cmmi/trunk/src/zc/recipe/cmmi/tests.py	2011-08-06 15:57:37 UTC (rev 122481)
@@ -98,25 +98,36 @@
                ]),
             optionflags = doctest.ELLIPSIS
             ),
-
         doctest.DocFileSuite(
             'downloadcache.txt',
-            'misc.txt',
             'patching.txt',
             'shared.txt',
             setUp=setUp,
             tearDown=zc.buildout.testing.buildoutTearDown,
 
             checker=renormalizing.RENormalizing([
-               zc.buildout.testing.normalize_path,
-               zc.buildout.testing.normalize_script,
-               zc.buildout.testing.normalize_egg_py,
-               normalize_bang,
-               (re.compile('http://localhost:[0-9]{4,5}/'),
-                'http://localhost/'),
-               (re.compile('extdemo[.]pyd'), 'extdemo.so'),
-               (re.compile('[0-9a-f]{40}'), '<BUILDID>'),
-               ]),
+                zc.buildout.testing.normalize_path,
+                zc.buildout.testing.normalize_script,
+                zc.buildout.testing.normalize_egg_py,
+                normalize_bang,
+                (re.compile('http://localhost:[0-9]{4,5}/'),
+                 'http://localhost/'),
+                (re.compile('extdemo[.]pyd'), 'extdemo.so'),
+                (re.compile('[0-9a-f]{40}'), '<BUILDID>'),
+                ]),
             optionflags = doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE
             ),
+        doctest.DocFileSuite(
+            'misc.txt',
+            setUp=setUp,
+            tearDown=zc.buildout.testing.buildoutTearDown,
+
+            checker=renormalizing.RENormalizing([
+                (re.compile('--prefix=\S+sample-buildout'),
+                 '--prefix=/sample_buildout'),
+                (re.compile('http://localhost:[0-9]{4,5}/'),
+                 'http://localhost/'),
+                ]),
+            optionflags = doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE
+            ),
         ))



More information about the checkins mailing list