Commit 57787791 authored by Gary Poster's avatar Gary Poster

support dicts passed as options to zc.recipe.egg, with a test.

parent c6da22cc
Change History Change History
************** **************
1.3.1 (unreleased) 1.3.1 (2010-08-23)
================== ==================
(no changes so far) - Support recipes that are using zc.recipe.egg by passing in a dict, rather
than a zc.buildout.buildout.Options object as was expected/tested.
1.3.0 (2010-08-23) 1.3.0 (2010-08-23)
================== ==================
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
"""Setup for zc.recipe.egg package """Setup for zc.recipe.egg package
""" """
version = '1.3.1dev' version = '1.3.1'
import os import os
from setuptools import setup, find_packages from setuptools import setup, find_packages
......
...@@ -122,7 +122,6 @@ computed by the egg recipe by looking at .installed.cfg: ...@@ -122,7 +122,6 @@ computed by the egg recipe by looking at .installed.cfg:
If we use the extra-paths option: If we use the extra-paths option:
>>> write(sample_buildout, 'buildout.cfg', >>> write(sample_buildout, 'buildout.cfg',
... """ ... """
... [buildout] ... [buildout]
...@@ -151,4 +150,3 @@ recipe instance: ...@@ -151,4 +150,3 @@ recipe instance:
other 1.0 other 1.0
demoneeded 1.2c1 demoneeded 1.2c1
extra paths: ['/foo/bar', '/spam/eggs'] extra paths: ['/foo/bar', '/spam/eggs']
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
$Id$ $Id$
""" """
import logging, os, re, zipfile import UserDict, logging, os, re, zipfile
import zc.buildout
import zc.buildout.easy_install import zc.buildout.easy_install
...@@ -27,6 +28,11 @@ class Eggs(object): ...@@ -27,6 +28,11 @@ class Eggs(object):
def __init__(self, buildout, name, options): def __init__(self, buildout, name, options):
self.buildout = buildout self.buildout = buildout
self.name = self.default_eggs = name self.name = self.default_eggs = name
if getattr(options, 'query_bool', None) is None:
# Someone is not passing us a zc.buildout.buildout.Options
# object. Maybe we should have a deprecation warning.
# Whatever.
options = _BackwardsSupportOption(options)
self.options = options self.options = options
b_options = buildout['buildout'] b_options = buildout['buildout']
links = options.get('find-links', b_options['find-links']) links = options.get('find-links', b_options['find-links'])
...@@ -190,3 +196,32 @@ class Scripts(ScriptBase): ...@@ -190,3 +196,32 @@ class Scripts(ScriptBase):
) )
Egg = Scripts Egg = Scripts
class _BackwardsSupportOption(UserDict.UserDict):
def query_bool(self, name, default=None):
"""Given a name, return a boolean value for that name.
``default``, if given, should be 'true', 'false', or None.
"""
if default is not None:
value = self.setdefault(name, default)
else:
value = self.get(name)
if value is None:
return value
return _convert_bool(name, value)
def get_bool(self, name):
"""Given a name, return a boolean value for that name.
"""
return _convert_bool(name, self[name])
def _convert_bool(name, value):
if value not in ('true', 'false'):
raise zc.buildout.UserError(
'Invalid value for %s option: %s' % (name, value))
else:
return value == 'true'
...@@ -29,6 +29,40 @@ def dirname(d, level=1): ...@@ -29,6 +29,40 @@ def dirname(d, level=1):
return d return d
return dirname(os.path.dirname(d), level-1) return dirname(os.path.dirname(d), level-1)
def testUsingDictAsOptions():
"""
Some recipes using zc.recipe.egg have been passing dictionaries rather than
zc.buildout.buildout.Options objects. That's unexpected, but to save
complaints, we'll support it.
Note that this test intends to show that a dictionary can be used as an
options object. It also uses a dictionary for the buildout object, which is
not intended.
>>> import zc.buildout.buildout
>>> import zc.recipe.egg
>>> faux_egg_options = {
... 'find-links': 'example.com',
... 'bin-directory': '/somewhere/over/rainbow'}
>>> faux_buildout_options = zc.buildout.buildout._unannotate_section(
... zc.buildout.buildout._buildout_default_options.copy())
>>> faux_buildout = {
... 'faux': faux_egg_options, 'buildout': faux_buildout_options}
>>> scripts = zc.recipe.egg.Scripts(
... faux_buildout, 'faux', faux_egg_options)
>>> scripts.links
['example.com']
>>> import zc.buildout.easy_install
>>> old_install = zc.buildout.easy_install.install
>>> old_scripts = zc.buildout.easy_install.scripts
>>> def whatever(*args, **kwargs): pass
>>> zc.buildout.easy_install.install = whatever
>>> zc.buildout.easy_install.scripts = whatever
>>> scripts.install() # This used to fail!
>>> zc.buildout.easy_install.install = old_install
>>> zc.buildout.easy_install.scripts = old_scripts
"""
def setUp(test): def setUp(test):
zc.buildout.tests.easy_install_SetUp(test) zc.buildout.tests.easy_install_SetUp(test)
zc.buildout.testing.install_develop('zc.recipe.egg', test) zc.buildout.testing.install_develop('zc.recipe.egg', test)
...@@ -96,7 +130,9 @@ def test_suite(): ...@@ -96,7 +130,9 @@ def test_suite():
(re.compile('extdemo[.]pyd'), 'extdemo.so') (re.compile('extdemo[.]pyd'), 'extdemo.so')
]), ]),
), ),
doctest.DocTestSuite(
setUp=setUp, tearDown=zc.buildout.testing.buildoutTearDown,
),
)) ))
if sys.version_info[:2] != (2, 4): if sys.version_info[:2] != (2, 4):
......
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