Commit 05a111b9 authored by jim's avatar jim

Added a runsetup command, to make egg generation a little easier.


git-svn-id: http://svn.zope.org/repos/main/zc.buildout/trunk@70201 62d5b8a3-27da-0310-9561-8e5933582275
parent 6b0d0bef
......@@ -23,6 +23,7 @@ import pprint
import re
import shutil
import sys
import tempfile
import ConfigParser
import pkg_resources
......@@ -618,7 +619,43 @@ class Buildout(dict):
)
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]*'
......@@ -842,7 +879,7 @@ def main(args=None):
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'
......
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@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
......@@ -512,7 +512,7 @@ def updateSetup(test):
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 @@ def test_suite():
(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')
])
),
......
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