[Checkins] SVN: zc.buildout/trunk/src/zc/buildout/ Added a runsetup command, to make egg generation a little easier.

Jim Fulton jim at zope.com
Fri Sep 15 18:50:02 EDT 2006


Log message for revision 70201:
  Added a runsetup command, to make egg generation a little easier.
  

Changed:
  U   zc.buildout/trunk/src/zc/buildout/buildout.py
  A   zc.buildout/trunk/src/zc/buildout/runsetup.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-09-15 22:47:17 UTC (rev 70200)
+++ zc.buildout/trunk/src/zc/buildout/buildout.py	2006-09-15 22:50:01 UTC (rev 70201)
@@ -23,6 +23,7 @@
 import re
 import shutil
 import sys
+import tempfile
 import ConfigParser
 
 import pkg_resources
@@ -618,9 +619,45 @@
                 )
             for ep in pkg_resources.iter_entry_points('zc.buildout.extension'):
                 ep.load()(self)
-                    
 
+    def runsetup(self, args):
+        setup = args.pop(0)
+        if os.path.isdir(setup):
+            setup = os.path.join(setup, 'setup.py')
 
+        self._logger.info("Running setup script %s", setup)
+        setup = os.path.abspath(setup)
+
+        setuptools = pkg_resources.working_set.find(
+            pkg_resources.Requirement.parse('setuptools')
+            ).location
+        
+            
+        fd, tsetup = tempfile.mkstemp()
+        try:
+            os.write(fd, runsetup_template % dict(
+                setuptools=setuptools,
+                setupdir=os.path.dirname(setup),
+                setup=setup,
+                ))
+            os.spawnl(os.P_WAIT, sys.executable, sys.executable, tsetup,
+                      *[zc.buildout.easy_install._safe_arg(a)
+                        for a in args])
+        finally:
+            os.close(fd)
+            os.remove(tsetup)
+        
+runsetup_template = """
+import sys
+sys.path.insert(0, %(setuptools)r)
+import os, setuptools
+
+os.chdir(%(setupdir)r)
+sys.argv[0] = %(setup)r
+execfile(%(setup)r)
+"""
+
+
 _spacey_nl = re.compile('[ \t\r\f\v]*\n[ \t\r\f\v\n]*'
                         '|'
                         '^[ \t\r\f\v]+'
@@ -842,7 +879,7 @@
 
     if args:
         command = args.pop(0)
-        if command not in ('install', 'bootstrap'):
+        if command not in ('install', 'bootstrap', 'runsetup'):
             _error('invalid command:', command)
     else:
         command = 'install'

Added: zc.buildout/trunk/src/zc/buildout/runsetup.txt
===================================================================
--- zc.buildout/trunk/src/zc/buildout/runsetup.txt	2006-09-15 22:47:17 UTC (rev 70200)
+++ zc.buildout/trunk/src/zc/buildout/runsetup.txt	2006-09-15 22:50:01 UTC (rev 70201)
@@ -0,0 +1,46 @@
+Running setup scripts
+=====================
+
+Buildouts are often used to work on packages that will be distributed
+as eggs. During development, we use develop eggs.  When you've
+completed a development cycle, you'll need to run your setup script to
+generate a distribution and, perhaps, uploaded it to the Python
+package index.  If your script uses setuptools, you'll need setuptools
+in your Python path, which may be an issue if you haven't installed
+setuptools into your Python installation.
+
+The buildout runsetup command is helpful in a situation like this.  It
+can be used to run a setup script and it does so with the setuptools
+egg in the Python path and with setuptools already imported.  The fact
+that setuptools is imported means that you can use setuptools-based
+commands, like bdist_egg even with packages that don't use setuptools.
+To illustrate this, we'll create a package in a sample buildout:
+
+    >>> mkdir(sample_buildout, 'hello')
+    >>> write(sample_buildout, 'hello', 'hello.py', 'print "Hello World!"')
+    >>> write(sample_buildout, 'hello', 'README', 'This is hello')
+    >>> write(sample_buildout, 'hello', 'setup.py',
+    ... """
+    ... from distutils.core import setup
+    ... setup(name="hello",
+    ...       version="1.0",
+    ...       py_modules=["hello"],
+    ...       author="Bob",
+    ...       author_email="bob at foo.com",
+    ...       )
+    ... """)
+  
+We can use the buildout command to generate the hello egg:
+
+    >>> cd(sample_buildout)
+    >>> import os
+    >>> print system(os.path.join('bin', 'buildout')
+    ...              +' runsetup hello -q bdist_egg'),
+    buildout: Running setup script hello/setup.py
+    zip_safe flag not set; analyzing archive contents...
+
+The hello directory now has a hello egg in it's dist directory:
+
+    >>> ls(sample_buildout, 'hello', 'dist')
+    -  hello-1.0-py2.4.egg
+


Property changes on: zc.buildout/trunk/src/zc/buildout/runsetup.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: zc.buildout/trunk/src/zc/buildout/tests.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/tests.py	2006-09-15 22:47:17 UTC (rev 70200)
+++ zc.buildout/trunk/src/zc/buildout/tests.py	2006-09-15 22:50:01 UTC (rev 70201)
@@ -512,7 +512,7 @@
 def test_suite():
     return unittest.TestSuite((
         doctest.DocFileSuite(
-            'buildout.txt',
+            'buildout.txt', 'runsetup.txt',
             setUp=zc.buildout.testing.buildoutSetUp,
             tearDown=zc.buildout.testing.buildoutTearDown,
             checker=renormalizing.RENormalizing([
@@ -530,6 +530,8 @@
                (re.compile('(\n?)-  ([a-zA-Z_.-]+)-script.py\n-  \\2.exe\n'),
                 '\\1-  \\2\n'),
                (re.compile("(\w)%s(\w)" % os_path_sep), r"\1/\2"),
+               (re.compile('hello-1[.]0-py\d[.]\d[.]egg'),
+                'hello-1.0-py2.4.egg')
                ])
             ),
 



More information about the Checkins mailing list