[Checkins] SVN: zc.buildout/trunk/ - Added a new init command for creating a new buildout. This creates

Jim Fulton jim at zope.com
Sat May 12 13:00:50 EDT 2007


Log message for revision 75710:
  - Added a new init command for creating a new buildout. This creates
    an empty configuration file and then bootstraps.
  
  - Except when using the new init command, it is now an error to run
    buildout without a configuration file.
  
  - 75607: buildout should not run if it creates an empty buildout.cfg
  

Changed:
  U   zc.buildout/trunk/CHANGES.txt
  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/CHANGES.txt
===================================================================
--- zc.buildout/trunk/CHANGES.txt	2007-05-12 17:00:47 UTC (rev 75709)
+++ zc.buildout/trunk/CHANGES.txt	2007-05-12 17:00:49 UTC (rev 75710)
@@ -20,6 +20,12 @@
 - buildout changes to the buildout directory before running recipe
   install and update methods.
 
+- Added a new init command for creating a new buildout. This creates
+  an empty configuration file and then bootstraps.
+
+- Except when using the new init command, it is now an error to run
+  buildout without a configuration file.
+
 Bugs Fixed
 ----------
 
@@ -30,6 +36,8 @@
   setuptools requires that file urls that point to directories must
   end in a "/".  Added a workaround.
 
+- 75607: buildout should not run if it creates an empty buildout.cfg
+
 1.0.0b24 (2007-05-09)
 =====================
 

Modified: zc.buildout/trunk/src/zc/buildout/buildout.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/buildout.py	2007-05-12 17:00:47 UTC (rev 75709)
+++ zc.buildout/trunk/src/zc/buildout/buildout.py	2007-05-12 17:00:49 UTC (rev 75710)
@@ -67,7 +67,7 @@
 class Buildout(UserDict.DictMixin):
 
     def __init__(self, config_file, cloptions,
-                 user_defaults=True, windows_restart=False):
+                 user_defaults=True, windows_restart=False, command=None):
 
         __doing__ = 'Initializing'
         
@@ -80,9 +80,15 @@
             config_file = os.path.abspath(config_file)
             base = os.path.dirname(config_file)
             if not os.path.exists(config_file):
-                print 'Warning: creating', config_file
-                open(config_file, 'w').write('[buildout]\nparts = \n')
-            data['buildout']['directory'] = os.path.dirname(config_file)
+                if command == 'init':
+                    print 'Creating', config_file
+                    open(config_file, 'w').write('[buildout]\nparts = \n')
+                else:
+                    raise zc.buildout.UserError(
+                        "Couldn't open %s" % config_file)
+
+            if config_file:
+                data['buildout']['directory'] = os.path.dirname(config_file)
         else:
             base = None
 
@@ -95,7 +101,8 @@
                                     []))
 
         # load configuration files
-        _update(data, _open(os.path.dirname(config_file), config_file, []))
+        if config_file:
+            _update(data, _open(os.path.dirname(config_file), config_file, []))
 
         # apply command-line options
         for (section, option, value) in cloptions:
@@ -209,6 +216,8 @@
             ['zc.buildout'], ws, sys.executable,
             self['buildout']['bin-directory'])
 
+    init = bootstrap
+
     def install(self, install_args):
         __doing__ = 'Installing'
 
@@ -1211,12 +1220,34 @@
     definition from the configuration file is used.  Otherwise, the
     arguments specify the parts to be installed.
 
+    Note that the semantics differ depending on whether any parts are
+    specified.  If parts are specified, then only those parts will be
+    installed. If no parts are specified, then the parts specified by
+    the buildout parts option will be installed along with all of
+    their dependencies.
+
   bootstrap
 
     Create a new buildout in the current working directory, copying
     the buildout and setuptools eggs and, creating a basic directory
     structure and a buildout-local buildout script.
 
+  init
+
+    Initialize a buildout, creating a buildout.cfg file if it doesn't
+    exist and then performing the same actions as for the buildout
+    command.
+
+  setup script [setup command and options]
+
+    Run a given setup script arranging that setuptools is in the
+    script's path and and that it has been imported so that
+    setuptools-provided commands (like bdist_egg) can be used even if
+    the setup script doesn't import setuptools itself.
+
+    The script can be given either as a script path or a path to a
+    directory containing a setup.py script.
+    
 """
 def _help():
     print _usage
@@ -1288,7 +1319,9 @@
 
     if args:
         command = args.pop(0)
-        if command not in ('install', 'bootstrap', 'runsetup', 'setup'):
+        if command not in (
+            'install', 'bootstrap', 'runsetup', 'setup', 'init',
+            ):
             _error('invalid command:', command)
     else:
         command = 'install'
@@ -1296,7 +1329,7 @@
     try:
         try:
             buildout = Buildout(config_file, options,
-                                user_defaults, windows_restart)
+                                user_defaults, windows_restart, command)
             getattr(buildout, command)(args)
         except SystemExit:
             pass

Modified: zc.buildout/trunk/src/zc/buildout/buildout.txt
===================================================================
--- zc.buildout/trunk/src/zc/buildout/buildout.txt	2007-05-12 17:00:47 UTC (rev 75709)
+++ zc.buildout/trunk/src/zc/buildout/buildout.txt	2007-05-12 17:00:49 UTC (rev 75710)
@@ -1968,8 +1968,8 @@
    command-line options.
 
 
-Bootstrapping
--------------
+Creating new buildouts and bootstrapping
+----------------------------------------
 
 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
@@ -1979,8 +1979,8 @@
 
    >>> print system(buildout
    ...              +' -c'+os.path.join(sample_bootstrapped, 'setup.cfg')
-   ...              +' bootstrap'),
-   Warning: creating /sample-bootstrapped/setup.cfg
+   ...              +' init'),
+   Creating /sample-bootstrapped/setup.cfg
    buildout: Creating directory /sample-bootstrapped/bin
    buildout: Creating directory /sample-bootstrapped/parts
    buildout: Creating directory /sample-bootstrapped/eggs
@@ -2012,6 +2012,36 @@
 Note that the buildout script was installed but not run.  To run
 the buildout, we'd have to run the installed buildout script.
 
+If we have an existing buildout that already has a buildout.cfg, we'll
+normally use the bootstrap command instead of init.  It will complain
+if there isn't a configuration file:
+
+    >>> sample_bootstrapped2 = tmpdir('sample-bootstrapped2')
+
+    >>> print system(buildout
+    ...              +' -c'+os.path.join(sample_bootstrapped2, 'setup.cfg')
+    ...              +' bootstrap'),
+    While:
+      Initializing
+    Error: Couldn't open /sample-bootstrapped2/setup.cfg
+
+    >>> write(sample_bootstrapped2, 'setup.cfg',
+    ... """
+    ... [buildout]
+    ... parts =
+    ... """)
+
+   >>> print system(buildout
+   ...              +' -c'+os.path.join(sample_bootstrapped2, 'setup.cfg')
+   ...              +' bootstrap'),
+   buildout: Creating directory /sample-bootstrapped2/bin
+   buildout: Creating directory /sample-bootstrapped2/parts
+   buildout: Creating directory /sample-bootstrapped2/eggs
+   buildout: Creating directory /sample-bootstrapped2/develop-eggs
+   zc.buildout.easy_install: Generated script /sample-bootstrapped2/bin/buildout.
+
+
+
 Newest and Offline Modes
 ------------------------
 

Modified: zc.buildout/trunk/src/zc/buildout/tests.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/tests.py	2007-05-12 17:00:47 UTC (rev 75709)
+++ zc.buildout/trunk/src/zc/buildout/tests.py	2007-05-12 17:00:49 UTC (rev 75710)
@@ -606,170 +606,24 @@
 
 def test_help():
     """
->>> print system(os.path.join(sample_buildout, 'bin', 'buildout')+' -h'),
-Usage: buildout [options] [assignments] [command [command arguments]]
-<BLANKLINE>
-Options:
-<BLANKLINE>
-  -h, --help
-<BLANKLINE>
-     Print this message and exit.
-<BLANKLINE>
-  -v
-<BLANKLINE>
-     Increase the level of verbosity.  This option can be used multiple times.
-<BLANKLINE>
-  -q
-<BLANKLINE>
-     Decrease the level of verbosity.  This option can be used multiple times.
-<BLANKLINE>
-  -c config_file
-<BLANKLINE>
-     Specify the path to the buildout configuration file to be used.
-     This defaults to the file named "buildout.cfg" in the current
-     working directory.
-<BLANKLINE>
-  -U
-<BLANKLINE>
-     Don't read user defaults.
-<BLANKLINE>
-  -o
-<BLANKLINE>
-    Run in off-line mode.  This is equivalent to the assignment 
-    buildout:offline=true.
-<BLANKLINE>
-  -O
-<BLANKLINE>
-    Run in non-off-line mode.  This is equivalent to the assignment 
-    buildout:offline=false.  This is the default buildout mode.  The
-    -O option would normally be used to override a true offline
-    setting in a configuration file.
-<BLANKLINE>
-  -n
-<BLANKLINE>
-    Run in newest mode.  This is equivalent to the assignment
-    buildout:newest=true.  With this setting, which is the default,
-    buildout will try to find the newest versions of distributions
-    available that satisfy its requirements.
-<BLANKLINE>
-  -N
-<BLANKLINE>
-    Run in non-newest mode.  This is equivalent to the assignment 
-    buildout:newest=false.  With this setting, buildout will not seek
-    new distributions if installed distributions satisfy it's
-    requirements. 
-<BLANKLINE>
-  -D
-<BLANKLINE>
-    Debug errors.  If an error occurs, then the post-mortem debugger
-    will be started. This is especially useful for debuging recipe
-    problems.
-<BLANKLINE>
-Assignments are of the form: section:option=value and are used to
-provide configuration options that override those given in the
-configuration file.  For example, to run the buildout in offline mode,
-use buildout:offline=true.
-<BLANKLINE>
-Options and assignments can be interspersed.
-<BLANKLINE>
-Commands:
-<BLANKLINE>
-  install [parts]
-<BLANKLINE>
-    Install parts.  If no command arguments are given, then the parts
-    definition from the configuration file is used.  Otherwise, the
-    arguments specify the parts to be installed.
-<BLANKLINE>
-  bootstrap
-<BLANKLINE>
-    Create a new buildout in the current working directory, copying
-    the buildout and setuptools eggs and, creating a basic directory
-    structure and a buildout-local buildout script.
-<BLANKLINE>
-<BLANKLINE>
+    >>> print system(os.path.join(sample_buildout, 'bin', 'buildout')+' -h'),
+    ... # doctest: +ELLIPSIS
+    Usage: buildout [options] [assignments] [command [command arguments]]
+    <BLANKLINE>
+    Options:
+    <BLANKLINE>
+      -h, --help
+    ...
 
->>> print system(os.path.join(sample_buildout, 'bin', 'buildout')
-...              +' --help'),
-Usage: buildout [options] [assignments] [command [command arguments]]
-<BLANKLINE>
-Options:
-<BLANKLINE>
-  -h, --help
-<BLANKLINE>
-     Print this message and exit.
-<BLANKLINE>
-  -v
-<BLANKLINE>
-     Increase the level of verbosity.  This option can be used multiple times.
-<BLANKLINE>
-  -q
-<BLANKLINE>
-     Decrease the level of verbosity.  This option can be used multiple times.
-<BLANKLINE>
-  -c config_file
-<BLANKLINE>
-     Specify the path to the buildout configuration file to be used.
-     This defaults to the file named "buildout.cfg" in the current
-     working directory.
-<BLANKLINE>
-  -U
-<BLANKLINE>
-     Don't read user defaults.
-<BLANKLINE>
-  -o
-<BLANKLINE>
-    Run in off-line mode.  This is equivalent to the assignment 
-    buildout:offline=true.
-<BLANKLINE>
-  -O
-<BLANKLINE>
-    Run in non-off-line mode.  This is equivalent to the assignment 
-    buildout:offline=false.  This is the default buildout mode.  The
-    -O option would normally be used to override a true offline
-    setting in a configuration file.
-<BLANKLINE>
-  -n
-<BLANKLINE>
-    Run in newest mode.  This is equivalent to the assignment
-    buildout:newest=true.  With this setting, which is the default,
-    buildout will try to find the newest versions of distributions
-    available that satisfy its requirements.
-<BLANKLINE>
-  -N
-<BLANKLINE>
-    Run in non-newest mode.  This is equivalent to the assignment 
-    buildout:newest=false.  With this setting, buildout will not seek
-    new distributions if installed distributions satisfy it's
-    requirements. 
-<BLANKLINE>
-  -D
-<BLANKLINE>
-    Debug errors.  If an error occurs, then the post-mortem debugger
-    will be started. This is especially useful for debuging recipe
-    problems.
-<BLANKLINE>
-Assignments are of the form: section:option=value and are used to
-provide configuration options that override those given in the
-configuration file.  For example, to run the buildout in offline mode,
-use buildout:offline=true.
-<BLANKLINE>
-Options and assignments can be interspersed.
-<BLANKLINE>
-Commands:
-<BLANKLINE>
-  install [parts]
-<BLANKLINE>
-    Install parts.  If no command arguments are given, then the parts
-    definition from the configuration file is used.  Otherwise, the
-    arguments specify the parts to be installed.
-<BLANKLINE>
-  bootstrap
-<BLANKLINE>
-    Create a new buildout in the current working directory, copying
-    the buildout and setuptools eggs and, creating a basic directory
-    structure and a buildout-local buildout script.
-<BLANKLINE>
-<BLANKLINE>
+    >>> print system(os.path.join(sample_buildout, 'bin', 'buildout')
+    ...              +' --help'),
+    ... # doctest: +ELLIPSIS
+    Usage: buildout [options] [assignments] [command [command arguments]]
+    <BLANKLINE>
+    Options:
+    <BLANKLINE>
+      -h, --help
+    ...
     """
 
 def test_bootstrap_with_extension():
@@ -2061,6 +1915,18 @@
     
     """
 
+def bug_75607_buildout_should_not_run_if_it_creates_an_empty_buildout_cfg():
+    """
+    >>> remove('buildout.cfg')
+    >>> print system(buildout),
+    While:
+      Initializing
+    Error: Couldn't open /sample-buildout/buildout.cfg
+
+
+    
+    """
+
 ######################################################################
     
 def create_sample_eggs(test, executable=sys.executable):



More information about the Checkins mailing list