[Checkins] SVN: zc.buildout/branches/gary-6/ integrate ability to control what eggs are accepted from site-packages into z3c.recipe.scripts. Without this, the ability to use z3c.recipe.scripts without site-packages was broken.

Gary Poster gary.poster at canonical.com
Fri Feb 19 20:54:36 EST 2010


Log message for revision 109167:
  integrate ability to control what eggs are accepted from site-packages into z3c.recipe.scripts.  Without this, the ability to use z3c.recipe.scripts without site-packages was broken.

Changed:
  A   zc.buildout/branches/gary-6/
  U   zc.buildout/branches/gary-6/z3c.recipe.scripts_/src/z3c/recipe/scripts/README.txt
  U   zc.buildout/branches/gary-6/z3c.recipe.scripts_/src/z3c/recipe/scripts/scripts.py
  U   zc.buildout/branches/gary-6/z3c.recipe.scripts_/src/z3c/recipe/scripts/tests.py
  U   zc.buildout/branches/gary-6/zc.recipe.egg_/src/zc/recipe/egg/egg.py

-=-
Modified: zc.buildout/branches/gary-6/z3c.recipe.scripts_/src/z3c/recipe/scripts/README.txt
===================================================================
--- zc.buildout/branches/gary-5/z3c.recipe.scripts_/src/z3c/recipe/scripts/README.txt	2010-02-20 01:54:01 UTC (rev 109166)
+++ zc.buildout/branches/gary-6/z3c.recipe.scripts_/src/z3c/recipe/scripts/README.txt	2010-02-20 01:54:35 UTC (rev 109167)
@@ -39,6 +39,35 @@
     from your eggs.  See the section on this option for motivations and
     warnings.
 
+allowed-eggs-from-site-packages
+    Sometimes you need or want to control what eggs from site-packages are
+    used. The allowed-eggs-from-site-packages option allows you to specify a
+    whitelist of project names that may be included from site-packages.  You
+    can use globs to specify the value.  It defaults to a single value of '*',
+    indicating that any package may come from site-packages.
+
+    Here's a usage example::
+
+        [buildout]
+        ...
+
+        allowed-eggs-from-site-packages =
+            demo
+            bigdemo
+            zope.*
+
+    This option interacts with the ``add-site-packages`` option in the
+    following ways.
+
+    If ``add-site-packages`` is true, then
+    ``allowed-eggs-from-site-packages`` filters what eggs from site-packages
+    may be chosen.  Therefore, if ``allowed-eggs-from-site-packages`` is an
+    empty list, then no eggs from site-packages are chosen, but site-packages
+    will still be included at the end of path lists.
+
+    If ``add-site-packages`` is false, the value of
+    ``allowed-eggs-from-site-packages`` is irrelevant.
+
 extends
     You can extend another section using this value.  It is intended to be
     used by extending a section that uses this package's scripts recipe.

Modified: zc.buildout/branches/gary-6/z3c.recipe.scripts_/src/z3c/recipe/scripts/scripts.py
===================================================================
--- zc.buildout/branches/gary-5/z3c.recipe.scripts_/src/z3c/recipe/scripts/scripts.py	2010-02-20 01:54:01 UTC (rev 109166)
+++ zc.buildout/branches/gary-6/z3c.recipe.scripts_/src/z3c/recipe/scripts/scripts.py	2010-02-20 01:54:35 UTC (rev 109167)
@@ -31,6 +31,11 @@
             b_options['parts-directory'], self.name)
 
         value = options.setdefault(
+            'allowed-eggs-from-site-packages',
+            '*')
+        self.allowed_eggs = tuple(name.strip() for name in value.split('\n'))
+
+        value = options.setdefault(
             'add-site-packages',
             b_options.get('add-site-packages', 'false'))
         if value not in ('true', 'false'):

Modified: zc.buildout/branches/gary-6/z3c.recipe.scripts_/src/z3c/recipe/scripts/tests.py
===================================================================
--- zc.buildout/branches/gary-5/z3c.recipe.scripts_/src/z3c/recipe/scripts/tests.py	2010-02-20 01:54:01 UTC (rev 109166)
+++ zc.buildout/branches/gary-6/z3c.recipe.scripts_/src/z3c/recipe/scripts/tests.py	2010-02-20 01:54:35 UTC (rev 109167)
@@ -235,10 +235,201 @@
             '/foo/bar',
             join(base, 'spam')
             ]...
+"""
 
+def add_site_packages_option_reusing_eggs():
+    """
+The add-site-packages buildout option not only controls whether
+site-packages are included in the path, but whether eggs in site-packages
+can be used to fulfill direct and indirect dependencies of your package.  If
+it did not, it might fail to exclude site-packages because one of the
+dependencies actually was supposed to be fulfilled with it.
 
-"""
+The default is ``add-site-packages = false``.  This makes it possible to
+easily use a system Python.  As a demonstration, we will start with a
+Python executable that has the "demoneeded" and "demo" eggs installed.
+The eggs are not found.
 
+    >>> from zc.buildout.tests import create_sample_sys_install
+    >>> py_path, site_packages_path = make_py()
+    >>> create_sample_sys_install(site_packages_path)
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... parts = eggs
+    ... find-links =
+    ...
+    ... [primed_python]
+    ... executable = %(py_path)s
+    ...
+    ... [eggs]
+    ... recipe = z3c.recipe.scripts
+    ... python = primed_python
+    ... eggs = demoneeded
+    ... ''' % globals())
+    >>> print system(py_path+" "+buildout)
+    Installing eggs.
+    Couldn't find index page for 'demoneeded' (maybe misspelled?)
+    Getting distribution for 'demoneeded'.
+    While:
+      Installing eggs.
+      Getting distribution for 'demoneeded'.
+    Error: Couldn't find a distribution for 'demoneeded'.
+    <BLANKLINE>
+
+However, if we set add-site-packages to true, the package will be found.
+Notice we do not set find-links, but the eggs are still found because
+they are in the executable's path.
+
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... parts = eggs
+    ... find-links =
+    ...
+    ... [primed_python]
+    ... executable = %(py_path)s
+    ...
+    ... [eggs]
+    ... recipe = z3c.recipe.scripts
+    ... python = primed_python
+    ... add-site-packages = true
+    ... eggs = demoneeded
+    ... ''' % globals())
+
+    >>> print system(py_path+" "+buildout)
+    Installing eggs.
+    <BLANKLINE>
+
+We get an error if we specify anything but true or false:
+
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... parts = eggs
+    ... find-links = %(link_server)s
+    ...
+    ... [eggs]
+    ... recipe = z3c.recipe.scripts
+    ... add-site-packages = no
+    ... eggs = other
+    ... ''' % globals())
+
+    >>> print system(py_path+" "+buildout)
+    While:
+      Installing.
+      Getting section eggs.
+      Initializing part eggs.
+    Error: Invalid value for add-site-packages option: no
+    <BLANKLINE>
+
+    """
+
+def allowed_eggs_from_site_packages_option():
+    """
+The allowed-eggs-from-site-packages option allows you to specify a
+whitelist of project names that may be included from site-packages.
+
+In the test below, our "py_path" has the "demoneeded" and "demo"
+packages available.  We'll simply be asking for "demoneeded" here.  The
+default value of '*' will allow it, as we've seen elsewhere. Here we
+explicitly use a "*" for the same result.  This also shows that we
+correctly parse a single-line value.
+
+
+    >>> from zc.buildout.tests import create_sample_sys_install
+    >>> py_path, site_packages_path = make_py()
+    >>> create_sample_sys_install(site_packages_path)
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... parts = eggs
+    ... find-links =
+    ...
+    ... [primed_python]
+    ... executable = %(py_path)s
+    ...
+    ... [eggs]
+    ... recipe = z3c.recipe.scripts
+    ... add-site-packages = true
+    ... allowed-eggs-from-site-packages = *
+    ... python = primed_python
+    ... eggs = demoneeded
+    ... ''' % globals())
+
+    >>> print system(py_path+" "+buildout)
+    Installing eggs.
+    <BLANKLINE>
+
+Specifying the egg exactly will work as well.  This shows we correctly
+parse a multi-line value.
+
+    >>> zc.buildout.easy_install.clear_index_cache()
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... parts = eggs
+    ... find-links =
+    ...
+    ... [primed_python]
+    ... executable = %(py_path)s
+    ...
+    ... [eggs]
+    ... recipe = z3c.recipe.scripts
+    ... add-site-packages = true
+    ... allowed-eggs-from-site-packages = other
+    ...                                   demoneeded
+    ... python = primed_python
+    ... eggs = demoneeded
+    ... ''' % globals())
+
+    >>> print system(py_path+" "+buildout)
+    Uninstalling eggs.
+    Installing eggs.
+    <BLANKLINE>
+
+It will also work if we use a glob ("*" or "?").  (We won't show that here
+because we already tested it in
+zc.buildout.tests.allowed_eggs_from_site_packages.)
+
+However, if we do not include "demoneeded" in the
+"allowed-eggs-from-site-packages" key, we get an error, because the
+packages are not available in any links, and they are not allowed to
+come from the executable's site packages. (We won't show that here
+because we already tested it in the same test mentioned above.)
+
+Finally, here's a test with an empty value.  It shows that we parse an empty
+value correctly, and verifies that we really are controlling what eggs are
+allowed, because we see that we were unable to get "other".
+
+    >>> zc.buildout.easy_install.clear_index_cache()
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... parts = eggs
+    ... find-links =
+    ...
+    ... [primed_python]
+    ... executable = %(py_path)s
+    ...
+    ... [eggs]
+    ... recipe = z3c.recipe.scripts
+    ... add-site-packages = true
+    ... allowed-eggs-from-site-packages =
+    ... eggs = demoneeded
+    ... ''' % globals())
+    >>> print system(py_path+" "+buildout)
+    Uninstalling eggs.
+    Installing eggs.
+    Getting distribution for 'demoneeded'.
+    While:
+      Installing eggs.
+      Getting distribution for 'demoneeded'.
+    Error: Couldn't find a distribution for 'demoneeded'.
+    <BLANKLINE>
+
+    """
+
 def setUp(test):
     zc.buildout.tests.easy_install_SetUp(test)
     zc.buildout.testing.install_develop('zc.recipe.egg', test)

Modified: zc.buildout/branches/gary-6/zc.recipe.egg_/src/zc/recipe/egg/egg.py
===================================================================
--- zc.buildout/branches/gary-5/zc.recipe.egg_/src/zc/recipe/egg/egg.py	2010-02-20 01:54:01 UTC (rev 109166)
+++ zc.buildout/branches/gary-6/zc.recipe.egg_/src/zc/recipe/egg/egg.py	2010-02-20 01:54:35 UTC (rev 109167)
@@ -22,6 +22,8 @@
 
 class Eggs(object):
 
+    add_site_packages = allowed_eggs = None
+
     def __init__(self, buildout, name, options):
         self.buildout = buildout
         self.name = self.default_eggs = name
@@ -76,6 +78,8 @@
                 distributions, options['executable'],
                 [options['develop-eggs-directory'],
                  options['eggs-directory']],
+                include_site_packages=self.add_site_packages,
+                allowed_eggs_from_site_packages=self.allowed_eggs,
                 )
         else:
             kw = {}
@@ -88,6 +92,8 @@
                 executable=options['executable'],
                 path=[options['develop-eggs-directory']],
                 newest=b_options.get('newest') == 'true',
+                include_site_packages=self.add_site_packages,
+                allowed_eggs_from_site_packages=self.allowed_eggs,
                 allow_hosts=self.allow_hosts,
                 **kw)
 



More information about the checkins mailing list