Commit 7302ee89 authored by Jim Fulton's avatar Jim Fulton

Changed the run_buildout api to always write output and print it if

there is an error.  I'd been trying to avoid writing a file, but that
made things too complicated.  I've seen some hard to reproduce test
failures that make turning on debugging in response to a failure
impractical.  Hopefully, if we get a test failure now, we'll be able
to see WTF.
parent 7a90f15b
......@@ -51,7 +51,7 @@ with a parts option. If we run Buildout::
>>> import os
>>> ls = lambda d='.': os.listdir(d)
>>> eqs(ls(), 'buildout.cfg', 'bin', 'eggs', 'develop-eggs', 'parts')
>>> eqs(ls(), 'buildout.cfg', 'bin', 'eggs', 'develop-eggs', 'parts', 'out')
>>> eqs(ls('bin'))
>>> eqs(ls('develop-eggs'))
......@@ -398,9 +398,9 @@ where you list them, as in::
>>> import shutil
>>> shutil.rmtree('eggs')
>>> run_buildout('buildout show-picked-versions=true', debug='o')
>>> run_buildout('buildout show-picked-versions=true')
>>> yup([n for n in ls('eggs') if n.startswith('ZEO-4.3.1-')])
>>> yup('ZEO = 4.3.1' in read('o'))
>>> yup('ZEO = 4.3.1' in read('out'))
In this example, we've requested a version of ZEO less than 5.0.
......@@ -427,9 +427,9 @@ The more common way to pin version is using a ``versions`` section::
>>> write(src, 'buildout.cfg')
>>> shutil.rmtree('eggs')
>>> run_buildout('buildout show-picked-versions=true', debug='o')
>>> run_buildout('buildout show-picked-versions=true')
>>> yup([n for n in ls('eggs') if n.startswith('ZEO-4.3.1-')])
>>> nope('ZEO = 4.3.1' in read('o'))
>>> nope('ZEO = 4.3.1' in read('out'))
Larger projects may need to pin many versions, so it's common to put
versions in their own file::
......@@ -466,9 +466,9 @@ might look like::
>>> write(versions_cfg, 'versions.cfg')
>>> shutil.rmtree('eggs')
>>> run_buildout('buildout show-picked-versions=true', debug='o')
>>> run_buildout('buildout show-picked-versions=true')
>>> yup([n for n in ls('eggs') if n.startswith('ZEO-4.3.1-')])
>>> nope('ZEO = 4.3.1' in read('o'))
>>> nope('ZEO = 4.3.1' in read('out'))
We can use the ``update-versions-file`` option to ask Buildout to
maintain our ``versions.cfg`` file for us::
......@@ -495,7 +495,7 @@ maintain our ``versions.cfg`` file for us::
>>> write(src, 'buildout.cfg')
>>> eq(versions_cfg, read('versions.cfg'))
>>> run_buildout('buildout show-picked-versions=true', debug='o')
>>> run_buildout('buildout show-picked-versions=true')
>>> yup([n for n in ls('eggs') if n.startswith('ZEO-4.3.1-')])
>>> yup('ZODB = ' in read('versions.cfg'))
......@@ -636,8 +636,8 @@ something like this::
>>> eq(src.strip().split('\n')[:2], develop_snippet.strip().split('\n')[:2])
>>> write(src, 'buildout.cfg')
>>> run_buildout(debug='o')
>>> yup('Develop: ' in read('o'))
>>> run_buildout()
>>> yup('Develop: ' in read('out'))
>>> eq(os.getcwd(), read('develop-eggs/main.egg-link').split()[0])
......
......@@ -19,6 +19,7 @@ import doctest
import manuel.capture
import manuel.doctest
import manuel.testing
from multiprocessing import Process
import os
import pkg_resources
import re
......@@ -3406,19 +3407,13 @@ normalize_S = (
'#!/usr/local/bin/python2.7',
)
def run_buildout(command, debug):
import sys
if debug:
if isinstance(debug, str):
sys.stdout = sys.stderr = open(debug, 'w')
else:
sys.stdout = sys.stderr
else:
sys.stderr = sys.stdout
def run_buildout(command):
os.environ['HOME'] = os.getcwd() # Make sure we don't get .buildout
args = command.strip().split()
import pkg_resources
buildout = pkg_resources.load_entry_point(
'zc.buildout', 'console_scripts', args[0])
sys.stdout = sys.stderr = open('out', 'w')
buildout(args[1:])
def test_suite():
......@@ -3688,36 +3683,41 @@ def test_suite():
# to test the documentation, not to test buildout.
def docSetUp(test):
index=" index=" + os.path.join(ancestor(__file__, 4), 'doc')
def run_buildout_in_process(command='buildout', debug=False):
from multiprocessing import Process, Queue
queue = Queue()
extra_options = (
" use-dependency-links=false"
" index=" + os.path.join(ancestor(__file__, 4), 'doc')
)
def run_buildout_in_process(command='buildout'):
process = Process(
target=run_buildout,
args=(command + index, debug),
args=(command + extra_options, ),
)
process.daemon = True
process.start()
process.join(9)
assert not process.is_alive()
return process.exitcode or None
if process.exitcode:
print(out())
def read(path):
with open(path) as f:
return f.read()
def out():
read('out')
def write(text, path):
with open(path, 'w') as f:
f.write(text)
test.globs.update(
indexarg=index,
run_buildout=run_buildout_in_process,
yup=lambda cond, orelse='Nope': None if cond else orelse,
nope=lambda cond, orelse='Nope': orelse if cond else None,
eq=lambda a, b: None if a == b else (a, b),
eqs=lambda a, *b: None if set(a) == set(b) else (a, b),
read=read,
out=out,
write=write,
)
setupstack.setUpDirectory(test)
......
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