[Checkins] SVN: zc.buildout/branches/aaron-testing-changes/src/zc/buildout/ Checkpoint commit in preparation for freshening.
Aaron Lehmann
aaron at zope.com
Sat Nov 8 15:16:10 EST 2008
Log message for revision 92836:
Checkpoint commit in preparation for freshening.
Changed:
U zc.buildout/branches/aaron-testing-changes/src/zc/buildout/buildout.py
U zc.buildout/branches/aaron-testing-changes/src/zc/buildout/buildout.txt
U zc.buildout/branches/aaron-testing-changes/src/zc/buildout/testing.py
U zc.buildout/branches/aaron-testing-changes/src/zc/buildout/testing.txt
-=-
Modified: zc.buildout/branches/aaron-testing-changes/src/zc/buildout/buildout.py
===================================================================
--- zc.buildout/branches/aaron-testing-changes/src/zc/buildout/buildout.py 2008-11-08 03:17:20 UTC (rev 92835)
+++ zc.buildout/branches/aaron-testing-changes/src/zc/buildout/buildout.py 2008-11-08 20:16:08 UTC (rev 92836)
@@ -68,6 +68,9 @@
class Buildout(UserDict.DictMixin):
+ root_handler = None
+ zc_buildout_handler = None
+
def __init__(self, config_file, cloptions,
user_defaults=True, windows_restart=False, command=None):
@@ -677,12 +680,14 @@
root_logger = logging.getLogger()
self._logger = logging.getLogger('zc.buildout')
handler = logging.StreamHandler(sys.stdout)
+ Buildout.root_handler = handler
log_format = self['buildout']['log-format']
if not log_format:
# No format specified. Use different formatter for buildout
# and other modules, showing logger name except for buildout
log_format = '%(name)s: %(message)s'
buildout_handler = logging.StreamHandler(sys.stdout)
+ Buildout.zc_buildout_handler = buildout_handler
buildout_handler.setFormatter(logging.Formatter('%(message)s'))
self._logger.propagate = False
self._logger.addHandler(buildout_handler)
@@ -1384,7 +1389,7 @@
print _usage
sys.exit(0)
-def main(args=None):
+def parse(args):
if args is None:
args = sys.argv[1:]
@@ -1472,6 +1477,11 @@
else:
command = 'install'
+ return (config_file, options, user_defaults, windows_restart, command, debug)
+
+def main(args=None):
+ config_file, options, user_defaults, windows_restart, command, debug = parse(args)
+
try:
try:
buildout = Buildout(config_file, options,
Modified: zc.buildout/branches/aaron-testing-changes/src/zc/buildout/buildout.txt
===================================================================
--- zc.buildout/branches/aaron-testing-changes/src/zc/buildout/buildout.txt 2008-11-08 03:17:20 UTC (rev 92835)
+++ zc.buildout/branches/aaron-testing-changes/src/zc/buildout/buildout.txt 2008-11-08 20:16:08 UTC (rev 92836)
@@ -113,8 +113,7 @@
and then we'll create a source file for our mkdir recipe:
- >>> write(sample_buildout, 'recipes', 'mkdir.py',
- ... """
+ >>> mkdir_py = """
... import logging, os, zc.buildout
...
... class Mkdir:
@@ -141,7 +140,8 @@
...
... def update(self):
... pass
- ... """)
+ ... """
+ >>> write(sample_buildout, 'recipes', 'mkdir.py', mkdir_py)
Currently, recipes must define 3 methods [#future_recipe_methods]_:
@@ -401,8 +401,7 @@
clean up any system side effects, such as files created. Let's update
the mkdir recipe to support multiple paths:
- >>> write(sample_buildout, 'recipes', 'mkdir.py',
- ... """
+ >>> mkdir_py_bad = """
... import logging, os, zc.buildout
...
... class Mkdir:
@@ -433,13 +432,12 @@
...
... def update(self):
... pass
- ... """)
+ ... """
If there is an error creating a path, the install method will exit and
leave previously created paths in place:
- >>> write(sample_buildout, 'buildout.cfg',
- ... """
+ >>> buildout_cfg = """
... [buildout]
... develop = recipes
... parts = data-dir
@@ -447,9 +445,16 @@
... [data-dir]
... recipe = recipes:mkdir
... path = foo bin
- ... """)
-
- >>> print system(buildout), # doctest: +ELLIPSIS
+ ... """
+ >>> cleanBuildout(sample_buildout)
+ >>> bo = setupConfig(
+ ... buildout_cfg,
+ ... sample_buildout,
+ ... 'zc.buildout',
+ ... 'recipes',
+ ... {'Mkdir': ('mkdir', mkdir_py_bad)})
+ >>> bootstrapBuildout(bo)
+ >>> installBuildout(bo)
Develop: '/sample-buildout/recipes'
Uninstalling data-dir.
Installing data-dir.
@@ -502,8 +507,7 @@
Let's fix the recipe:
- >>> write(sample_buildout, 'recipes', 'mkdir.py',
- ... """
+ >>> mkdir_py_good = """
... import logging, os, zc.buildout
...
... class Mkdir:
@@ -542,7 +546,8 @@
...
... def update(self):
... pass
- ... """)
+ ... """
+ >>> write(sample_buildout, 'recipes', 'mkdir.py', mkdir_py_good)
And put back the typo:
Modified: zc.buildout/branches/aaron-testing-changes/src/zc/buildout/testing.py
===================================================================
--- zc.buildout/branches/aaron-testing-changes/src/zc/buildout/testing.py 2008-11-08 03:17:20 UTC (rev 92835)
+++ zc.buildout/branches/aaron-testing-changes/src/zc/buildout/testing.py 2008-11-08 20:16:08 UTC (rev 92836)
@@ -199,17 +199,16 @@
)
# Use the buildout bootstrap command to create a buildout
- zc.buildout.buildout.Buildout(
+ bo = zc.buildout.buildout.Buildout(
'buildout.cfg',
[('buildout', 'log-level', 'WARNING'),
# trick bootstrap into putting the buildout develop egg
# in the eggs dir.
('buildout', 'develop-eggs-directory', 'eggs'),
]
- ).bootstrap([])
+ )
+ bo.bootstrap([])
-
-
# Create the develop-eggs dir, which didn't get created the usual
# way due to thr trick above:
os.mkdir('develop-eggs')
@@ -220,64 +219,108 @@
register_teardown(lambda: stop_server(url, thread))
return url
- def setupBuildout(test, *args):
- """ setupBuildout -- Sets up a Buildout for testing
+ def bootstrapBuildout(test, buildout):
+ """ bootstrapBuildout -- bootstraps a Buildout, first silencing
+ annoying log stuff
+
test - The test suite in which this will be used, this is expected
to be baked in via a curry
- args - This will be split up as follows:
- dir1..dirN, filename, buildout_cfg
- dir1..dirN - directories in the path to the buildout
- to bootstrap
- filename - the filename to write the configuration into
- buildout_cfg - the configuration to be used to buildout.
+ buildout - the Buildout to be bootstrapped
"""
- args = list(args)
- cfg = args.pop()
- filename = args.pop()
- directory = os.path.join(*args)
- eggs = os.path.join(os.path.join(directory, 'eggs'))
- eggs = os.path.join(os.path.join(directory, 'eggs'))
- path = os.path.join(directory, filename)
- install_eggs = test.globs.get('eggs', tuple())
- sample_buildout = test.globs['sample_buildout']
- rmdir(directory)
- test.globs['sample_buildout'] = sample_buildout = tmpdir(sample_buildout)
- write(path, cfg)
- os.chdir(sample_buildout)
- buildout = zc.buildout.buildout.Buildout(
- path,
- [# trick bootstrap into putting the buildout develop egg
- # in the eggs dir.
- ('buildout', 'develop-eggs-directory', 'eggs'),
- ],
- user_defaults=False
- )
+ # Raise the log threshold for the bootstrap, because we don't care about
+ # it
+ logger = logging.getLogger('zc.buildout')
+ level = logger.level
+ logger.setLevel(99999)
+ # trick bootstrap into putting the buildout develop egg
+ # in the eggs dir.
+ buildout['buildout']['develop-eggs-directory'] = 'eggs'
+ buildout['buildout']['log-level'] = 'WARNING'
+ buildout.bootstrap([])
+
# Create the develop-eggs dir, which didn't get created the usual
# way due to the trick above:
os.mkdir('develop-eggs')
- #Raise the log threshold for the bootstrap, because we don't care about
- #it
- logger = logging.getLogger('zc.buildout')
- level = logging.getLogger('zc.buildout').level
- logging.getLogger('zc.buildout').setLevel(99999)
- buildout.bootstrap([])
- logging.getLogger('zc.buildout').setLevel(level)
+ #Set the log threshhold back where it belongs.
+ logger.setLevel(level)
- #Remove extra log handlers that dump output outside of the test or mess
- #the test up.
- logger.removeHandler(logger.handlers[0])
- if logger.parent:
- logger.parent.removeHandler(logger.parent.handlers[1])
+ def installBuildout(test,
+ buildout, install_args=None, uninstall_args=None):
+ """ installBuildout -- installs a Buildout, first silencing
+ annoying log stuff
+
+ test - The test suite in which this will be used, this is expected
+ to be baked in via a curry
+ buildout - the Buildout to be installed
+ """
+ install_args = install_args or []
+ uninstall_args = uninstall_args or []
+ eggs = os.path.join(test.globs['sample_buildout'], 'eggs')
+ install_eggs = test.globs.get('eggs', tuple())
+
#Install the eggs we need.
for egg in install_eggs:
zc.buildout.testing.install(egg, eggs)
- return buildout
+ # install the builodut
+ buildout.install(install_args, uninstall_args)
+
+ def cleanBuildout(test, sample_buildout=None):
+ """ Cleans the sample buildout by deleting the directory, then
+ recreating it."""
+
+ sample_buildout = sample_buildout or test.globs['sample_buildout']
+ rmdir, mkdir, cd = (
+ test.globs['rmdir'], test.globs['mkdir'], test.globs['cd'])
+ start_dir = os.getcwd()
+ here_dir = os.path.split(os.path.abspath(__file__))[0]
+ cd(here_dir)
+ rmdir(sample_buildout)
+ mkdir(sample_buildout)
+ cd(start_dir)
+
+ # Clear out the Buildout-related logging
+ logging.getLogger().removeHandler(
+ zc.buildout.buildout.Buildout.root_handler)
+ logging.getLogger('zc.buildout').removeHandler(
+ zc.buildout.buildout.Buildout.zc_buildout_handler)
+ zc.buildout.buildout.Buildout.root_handler = None
+ zc.buildout.buildout.Buildout.zc_buildout_handler = None
+
+
+ def setupConfig(
+ test, cfg, sample_buildout=None, recipe_name='', recipe_dir='', recipes=None):
+
+ """ Sets up the configuration of for a buildout, as well as any Recipes
+ for testing. Returns an unbootstrapped
+ zc.buildout.buildout.Buildout."""
+
+ sample_buildout = sample_buildout or test.globs['sample_buildout']
+ recipes = recipes or {}
+ mkdir, write = test.globs['mkdir'], test.globs['write']
+
+ if recipe_dir:
+ mkdir(sample_buildout, recipe_dir)
+ entries = ''
+ for recipe, (modulename, contents) in recipes.items():
+ write(sample_buildout, recipe_dir, modulename + '.py', contents)
+ entries += " '%s': ['%s = %s:%s'],\n" % (
+ recipe_name, modulename, modulename, recipe)
+ write(sample_buildout, recipe_dir, 'setup.py',
+ ("from setuptools import setup\n"
+ "setup(\n"
+ " name = \"%s\",\n"
+ " entry_points = {\n"
+ "%s\n }\n"
+ ")\n") % (recipe_dir, entries))
+ write(sample_buildout, 'buildout.cfg', cfg)
+ return zc.buildout.buildout.Buildout(*(zc.buildout.buildout.parse([])[:5]))
+
test.globs.update(dict(
sample_buildout = sample,
ls = ls,
@@ -295,9 +338,26 @@
bdist_egg = bdist_egg,
start_server = start_server,
buildout = os.path.join(sample, 'bin', 'buildout'),
- setupBuildout = lambda *args:setupBuildout(test, *args),
+ bootstrapBuildout = lambda buildout:bootstrapBuildout(test, buildout),
+ installBuildout = (
+ lambda buildout,
+ install_args=None,
+ uninstall_args=None:installBuildout(
+ test, buildout, install_args, uninstall_args)),
+ setupConfig = (
+ lambda cfg,
+ sample_buildout=None,
+ recipe_name='',
+ recipe_dir='',
+ recipes=None:setupConfig(test,
+ cfg,
+ sample_buildout,
+ recipe_name,
+ recipe_dir,
+ recipes)),
+ cleanBuildout = (
+ lambda sample_buildout=None:cleanBuildout(test, sample_buildout)),
))
-
zc.buildout.easy_install.prefer_final(prefer_final)
def buildoutTearDown(test):
Modified: zc.buildout/branches/aaron-testing-changes/src/zc/buildout/testing.txt
===================================================================
--- zc.buildout/branches/aaron-testing-changes/src/zc/buildout/testing.txt 2008-11-08 03:17:20 UTC (rev 92835)
+++ zc.buildout/branches/aaron-testing-changes/src/zc/buildout/testing.txt 2008-11-08 20:16:08 UTC (rev 92836)
@@ -129,17 +129,31 @@
- on Unix, try running python%(version)s or just python to get the
executable
-``setupBuildout(dir1...dirN, filename, buildout_cfg)``
- This function writes the configuration in buildout_cfg into
- os.path.join(dir1...dirN, filename). It then chdirs into the same
- directory, bootstraps a Buildout object, and returns the object. This
- allows recipe writers to test their recipes in process, and allows the
- Buildout to be introspected more easily.
+``bootstrapBuildout(buildout)``
+ This function bootstraps a buildout, first setting up the logging
+ environment so that it won't spam the test runner.
*DISCLAIMER*: There is currently no promise of backward compatibility in
the API between versions of zc.buildout, and its methods are not to be
viewed as a public API.
+``installBuildout(buildout,
+ install_args=[],
+ uninstall_args=[])``
+ This function installs the buildout and its eggs, first setting up the
+ logging so it won't spam the test runner.
+
+ install_args and uninstall_args indicate what parts should be installed and
+ uninstalled.
+
+ *DISCLAIMER*: There is currently no promise of backward compatibility in
+ the API between versions of zc.buildout, and its methods are not to be
+ viewed as a public API.
+
+``cleanBuildout(test, sample_buildout=sample)``
+ This function cleans the sample buildout by deleting the directory, then
+ recreating it.
+
``zc.buildout.testing.buildoutTearDown(test)``
----------------------------------------------
More information about the Checkins
mailing list