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