[Checkins] SVN: zc.buildout/trunk/src/zc/buildout/ - Now create a minimal setup.py if it doesn't exist and issue a

Jim Fulton jim at zope.com
Mon Jul 10 05:42:52 EDT 2006


Log message for revision 69065:
  - Now create a minimal setup.py if it doesn't exist and issue a
    warning that it is being created.
  
  - Fixed bug in saving installed configuration data.  %'s and extra
    spaces weren't quoted.
  

Changed:
  U   zc.buildout/trunk/src/zc/buildout/buildout.py
  U   zc.buildout/trunk/src/zc/buildout/buildout.txt
  U   zc.buildout/trunk/src/zc/buildout/tests.py

-=-
Modified: zc.buildout/trunk/src/zc/buildout/buildout.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/buildout.py	2006-07-10 09:20:06 UTC (rev 69064)
+++ zc.buildout/trunk/src/zc/buildout/buildout.py	2006-07-10 09:42:52 UTC (rev 69065)
@@ -60,6 +60,9 @@
     def __init__(self, config_file, cloptions):
         config_file = os.path.abspath(config_file)
         self._config_file = config_file
+        if not os.path.exists(config_file):
+            print 'Warning: creating', config_file
+            open(config_file, 'w').write('[buildout]\nparts = \n')
 
         super(Buildout, self).__init__()
 
@@ -376,10 +379,15 @@
     def _read_installed_part_options(self):
         old = self._installed_path()
         if os.path.isfile(old):
-            parser = ConfigParser.SafeConfigParser()
+            parser = ConfigParser.SafeConfigParser(_spacey_defaults)
             parser.read(old)
             return dict([
-                (section, Options(self, section, parser.items(section)))
+                (section,
+                 Options(self, section,
+                         [item for item in parser.items(section)
+                          if item[0] not in _spacey_defaults]
+                         )
+                 )
                 for section in parser.sections()])
         else:
             return {'buildout': Options(self, 'buildout', {'parts': ''})}
@@ -453,13 +461,44 @@
             for section in sections:
                 _save_options(section, self[section], sys.stdout)
             print    
-        
+
+_spacey_nl = re.compile('^[ \t\r\f\v]+'
+                        '|''[ \t\r\f\v]*\n[ \t\r\f\v\n]*'
+                        '|'
+                        '[ \t\r\f\v]+$'
+                        )
+
+def _quote_spacey_nl(match):
+    match = match.group(0).split('\n', 1)
+    result = '\n\t'.join(
+        [(s
+          .replace(' ', '%(__buildout_space__)s')
+          .replace('\r', '%(__buildout_space_r__)s')
+          .replace('\f', '%(__buildout_space_f__)s')
+          .replace('\v', '%(__buildout_space_v__)s')
+          .replace('\n', '%(__buildout_space_n__)s')
+          )
+         for s in match]
+        )
+    return result
+
+_spacey_defaults = dict(
+    __buildout_space__   = ' ',
+    __buildout_space_r__ = '\r',
+    __buildout_space_f__ = '\f',
+    __buildout_space_v__ = '\v',
+    __buildout_space_n__ = '\n',
+    )
+
 def _save_options(section, options, f):
     print >>f, '[%s]' % section
     items = options.items()
     items.sort()
     for option, value in items:
-        print >>f, option, '=', str(value).replace('\n', '\n\t')
+        value = value.replace('%', '%%')
+        value = _spacey_nl.sub(_quote_spacey_nl, value)
+        print >>f, option, '=', value
+            
     
 
 def _open(base, filename, seen):

Modified: zc.buildout/trunk/src/zc/buildout/buildout.txt
===================================================================
--- zc.buildout/trunk/src/zc/buildout/buildout.txt	2006-07-10 09:20:06 UTC (rev 69064)
+++ zc.buildout/trunk/src/zc/buildout/buildout.txt	2006-07-10 09:42:52 UTC (rev 69065)
@@ -1066,7 +1066,7 @@
     eggs-directory = /tmp/sample-buildout/eggs
     executable = /usr/local/bin/python2.3
     installed = /tmp/sample-buildout/.installed.cfg
-    log-format = %(name)s: %(message)s
+    log-format = %%(name)s: %%(message)s
     log-level = WARNING
     parts = 
     parts-directory = /tmp/sample-buildout/parts
@@ -1141,19 +1141,17 @@
 
 If zc.buildout is installed, you can use it to create a new buildout
 with it's own local copies of zc.buildout and setuptools and with
-local buildout scripts.  There must be an existing setup.cfg:
+local buildout scripts. 
 
     >>> sample_bootstrapped = mkdtemp('sample-bootstrapped')
-    >>> write(sample_bootstrapped, 'setup.cfg',
-    ... '''
-    ... [buildout]
-    ... parts = foo this will not be read :)
-    ... ''')
 
     >>> print system(buildout
     ...              +' -c'+os.path.join(sample_bootstrapped, 'setup.cfg')
     ...              +' bootstrap'),
+    Warning: creating /sample-bootstrapped/setup.cfg
 
+Note that a basic setup.cfg was created for us.
+
     >>> ls(sample_bootstrapped)
     d  bin
     d  develop-eggs
@@ -1173,7 +1171,7 @@
 
 
 Note that, in this example, we were using a development egg for the
-buildout, and the ac.buildout egg ended up as an egg link.
+buildout, and the zc.buildout egg ended up as an egg link.
 
 Also not that the buildout script was installed but not run.  To run
 the buildout, we'd have to run the installed buildout script.

Modified: zc.buildout/trunk/src/zc/buildout/tests.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/tests.py	2006-07-10 09:20:06 UTC (rev 69064)
+++ zc.buildout/trunk/src/zc/buildout/tests.py	2006-07-10 09:42:52 UTC (rev 69065)
@@ -61,7 +61,72 @@
            [('buildout', 'y'), ('buildout', 'z'), ('buildout', 'x')],
            ('buildout', 'y'))
 """
+ 
+def test_comparing_saved_options_with_funny_characters():
+    """
+    If an option has newlines, extra/odd spaces or a %, we need to make
+    sure the comparison with the saved value works correctly.
 
+    >>> mkdir(sample_buildout, 'recipes')
+    >>> write(sample_buildout, 'recipes', 'debug.py', 
+    ... '''
+    ... class Debug:
+    ...     def __init__(self, buildout, name, options):
+    ...         options['debug'] = \"\"\"  <zodb>
+    ...
+    ...   <filestorage>
+    ...     path foo
+    ...   </filestorage>
+    ...
+    ... </zodb>  
+    ...      \"\"\"
+    ...         options['debug2'] = '  x  '
+    ...         options['debug3'] = '42'
+    ...         options['format'] = '%3d'
+    ...
+    ...     def install(self):
+    ...         open('t', 'w').write('t')
+    ...         return 't'
+    ... ''')
+
+
+    >>> write(sample_buildout, 'recipes', 'setup.py',
+    ... '''
+    ... from setuptools import setup
+    ... setup(
+    ...     name = "recipes",
+    ...     entry_points = {'zc.buildout': ['default = debug:Debug']},
+    ...     )
+    ... ''')
+
+    >>> write(sample_buildout, 'recipes', 'README.txt', " ")
+
+    >>> write(sample_buildout, 'buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... develop = recipes
+    ... parts = debug
+    ...
+    ... [debug]
+    ... recipe = recipes
+    ... ''')
+
+    >>> os.chdir(sample_buildout)
+    >>> buildout = os.path.join(sample_buildout, 'bin', 'buildout')
+
+    >>> print system(buildout+' -v'), # doctest: +ELLIPSIS
+    buildout: Running ...setup.py -q develop ...
+    buildout: Installing debug
+
+If we run the buildout again, we shoudn't get a message about
+uninstalling anything because the configuration hasn't changed.
+
+    >>> print system(buildout+' -v'),
+    buildout: Running setup.py -q develop ...
+    buildout: Installing debug
+"""
+
+
 def linkerSetUp(test):
     zc.buildout.testing.buildoutSetUp(test, clear_home=False)
     zc.buildout.testing.multi_python(test)
@@ -136,6 +201,7 @@
                (re.compile('executable = \S+python\S*'),
                 'executable = python'),
                (re.compile('setuptools-\S+[.]egg'), 'setuptools.egg'),
+               (re.compile('creating \S*setup.cfg'), 'creating setup.cfg'),
                ])
             ),
         
@@ -154,7 +220,13 @@
             ),
         doctest.DocTestSuite(
             setUp=zc.buildout.testing.buildoutSetUp,
-            tearDown=zc.buildout.testing.buildoutTearDown),
+            tearDown=zc.buildout.testing.buildoutTearDown,
+
+            checker=PythonNormalizing([
+               (re.compile("buildout: Running \S*setup.py"),
+                'buildout: Running setup.py'),
+               ]),
+            )
         ))
 
 if __name__ == '__main__':



More information about the Checkins mailing list