[Checkins] SVN: zc.buildout/branches/gary-support-system-python/ switch, um, back to include-site-packages. add first run at tests, with resulting fixes and changes.

Gary Poster gary.poster at canonical.com
Mon Jul 6 20:14:39 EDT 2009


Log message for revision 101673:
  switch, um, back to include-site-packages.  add first run at tests, with resulting fixes and changes.

Changed:
  U   zc.buildout/branches/gary-support-system-python/src/zc/buildout/buildout.py
  U   zc.buildout/branches/gary-support-system-python/src/zc/buildout/easy_install.py
  U   zc.buildout/branches/gary-support-system-python/src/zc/buildout/easy_install.txt
  U   zc.buildout/branches/gary-support-system-python/src/zc/buildout/testing.py
  U   zc.buildout/branches/gary-support-system-python/src/zc/buildout/tests.py
  U   zc.buildout/branches/gary-support-system-python/zc.recipe.egg_/src/zc/recipe/egg/egg.py

-=-
Modified: zc.buildout/branches/gary-support-system-python/src/zc/buildout/buildout.py
===================================================================
--- zc.buildout/branches/gary-support-system-python/src/zc/buildout/buildout.py	2009-07-06 19:22:49 UTC (rev 101672)
+++ zc.buildout/branches/gary-support-system-python/src/zc/buildout/buildout.py	2009-07-07 00:14:39 UTC (rev 101673)
@@ -217,12 +217,12 @@
                         prefer_final)
         zc.buildout.easy_install.prefer_final(prefer_final=='true')
 
-        exclude_site_packages = options.get('exclude-site-packages', 'false')
-        if exclude_site_packages not in ('true', 'false'):
-            self._error('Invalid value for exclude-site-packages option: %s',
-                        exclude_site_packages)
-        zc.buildout.easy_install.exclude_site_packages(
-            exclude_site_packages=='true')
+        include_site_packages = options.get('include-site-packages', 'true')
+        if include_site_packages not in ('true', 'false'):
+            self._error('Invalid value for include-site-packages option: %s',
+                        include_site_packages)
+        zc.buildout.easy_install.include_site_packages(
+            include_site_packages=='true')
 
         use_dependency_links = options.get('use-dependency-links', 'true')
         if use_dependency_links not in ('true', 'false'):

Modified: zc.buildout/branches/gary-support-system-python/src/zc/buildout/easy_install.py
===================================================================
--- zc.buildout/branches/gary-support-system-python/src/zc/buildout/easy_install.py	2009-07-06 19:22:49 UTC (rev 101672)
+++ zc.buildout/branches/gary-support-system-python/src/zc/buildout/easy_install.py	2009-07-07 00:14:39 UTC (rev 101673)
@@ -92,8 +92,13 @@
             cmd.insert(1, '-S')
         _proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
         _proc.wait();
-        res = eval(_proc.stdout.read())
+        raw = _proc.stdout.read()
+        _proc.stdout.close()
         try:
+            res = eval(raw)
+        except SyntaxError:
+            import pdb; pdb.set_trace()
+        try:
             res.remove('.')
         except ValueError:
             pass
@@ -148,7 +153,12 @@
 
 
 _indexes = {}
-def _get_index(executable, index_url, find_links, allow_hosts=('*',)):
+def _get_index(executable, index_url, find_links, allow_hosts=('*',),
+               path=None):
+    # If path is None, the index will use sys.path.  If you provide an empty
+    # path ([]), it will complain uselessly about missing index pages for
+    # packages found in the paths that you expect to use.  Therefore, this path
+    # is always the same as the _env path in the Installer.
     key = executable, index_url, tuple(find_links)
     index = _indexes.get(key)
     if index is not None:
@@ -156,11 +166,8 @@
 
     if index_url is None:
         index_url = default_index_url
-    # Specifying an empty search_path, rather than the default None, indicates
-    # that we do not want to include the sys.path in the index.  If we do want
-    # to include the sys.path, that is done in the Installer's _env.
     index = AllowHostsPackageIndex(
-        index_url, hosts=allow_hosts, search_path=[],
+        index_url, hosts=allow_hosts, search_path=path,
         python=_get_version(executable)
         )
 
@@ -193,7 +200,7 @@
     _use_dependency_links = True
     _allow_picked_versions = True
     _always_unzip = False
-    _exclude_site_packages = False
+    _include_site_packages = False
 
     def __init__(self,
                  dest=None,
@@ -205,7 +212,7 @@
                  newest=True,
                  versions=None,
                  use_dependency_links=None,
-                 exclude_site_packages=None,
+                 include_site_packages=None,
                  allow_hosts=('*',)
                  ):
         self._dest = dest
@@ -229,10 +236,10 @@
         if always_unzip is not None:
             self._always_unzip = always_unzip
         path = (path and path[:] or [])
-        if exclude_site_packages is not None:
-            self._exclude_site_packages = exclude_site_packages
+        if include_site_packages is not None:
+            self._include_site_packages = include_site_packages
         stdlib, site_packages = _get_system_packages(executable)
-        if not self._exclude_site_packages:
+        if self._include_site_packages:
             path.extend(buildout_and_setuptools_path)
             path.extend(site_packages)
         # else we could try to still include the buildout_and_setuptools_path
@@ -246,7 +253,8 @@
         self._newest = newest
         self._env = pkg_resources.Environment(path,
                                               python=_get_version(executable))
-        self._index = _get_index(executable, index, links, self._allow_hosts)
+        self._index = _get_index(executable, index, links, self._allow_hosts,
+                                 self._path)
 
         if versions is not None:
             self._versions = versions
@@ -623,7 +631,7 @@
                         self._links.append(link)
                         self._index = _get_index(self._executable,
                                                  self._index_url, self._links,
-                                                 self._allow_hosts)
+                                                 self._allow_hosts, self._path)
 
         for dist in dists:
             # Check whether we picked a version and, if we did, report it:
@@ -825,10 +833,10 @@
         Installer._prefer_final = bool(setting)
     return old
 
-def exclude_site_packages(setting=None):
-    old = Installer._exclude_site_packages
+def include_site_packages(setting=None):
+    old = Installer._include_site_packages
     if setting is not None:
-        Installer._exclude_site_packages = bool(setting)
+        Installer._include_site_packages = bool(setting)
     return old
 
 def use_dependency_links(setting=None):
@@ -853,21 +861,21 @@
             links=(), index=None,
             executable=sys.executable, always_unzip=None,
             path=None, working_set=None, newest=True, versions=None,
-            use_dependency_links=None, exclude_site_packages=None,
+            use_dependency_links=None, include_site_packages=None,
             allow_hosts=('*',)):
     installer = Installer(dest, links, index, executable, always_unzip, path,
                           newest, versions, use_dependency_links,
-                          exclude_site_packages, allow_hosts=allow_hosts)
+                          include_site_packages, allow_hosts=allow_hosts)
     return installer.install(specs, working_set)
 
 
 def build(spec, dest, build_ext,
           links=(), index=None,
           executable=sys.executable,
-          path=None, newest=True, versions=None, exclude_site_packages,
+          path=None, newest=True, versions=None, include_site_packages=None,
           allow_hosts=('*',)):
     installer = Installer(dest, links, index, executable, True, path, newest,
-                          versions, exclude_site_packages, allow_hosts=allow_hosts)
+                          versions, include_site_packages, allow_hosts=allow_hosts)
     return installer.build(spec, build_ext)
 
 
@@ -963,12 +971,13 @@
         [f() for f in undo]
 
 
-def working_set(specs, executable, path, exclude_site_packages=None):
+def working_set(specs, executable, path, include_site_packages=None):
     return install(
         specs, None, executable=executable, path=path,
-        exclude_site_packages=exclude_site_packages)
+        include_site_packages=include_site_packages)
 
-def get_path(working_set, executable, exclude_site_packages=True):
+def get_path(working_set, executable, extra_paths=(),
+             include_site_packages=False):
     """Given working set and path to executable, return value for sys.path.
     
     Distribution locations from the working set come first in the list.  Within
@@ -976,12 +985,12 @@
     locations to the end of the list, so that they don't mask eggs.
     
     This expects that the working_set has already been created to honor a
-    exclude_site_packages setting.  That is, if exclude_site_packages is True,
+    include_site_packages setting.  That is, if include_site_packages is False,
     this function does *not* verify that the working_set's distributions are
     not in site packages.
     
-    However, it does explicitly include site packages if exclude_site_packages
-    is False.
+    However, it does explicitly include site packages if include_site_packages
+    is True.
     
     The standard library (defined as what the given Python executable has on
     the path before its site.py is run) is always included.
@@ -1001,7 +1010,7 @@
     path.extend(postponed)
     path.extend(extra_paths)
     # now we add in all paths
-    if not exclude_site_packages:
+    if include_site_packages:
         path.extend(site_packages)
     path.extend(stdlib)
     path = map(realpath, path)
@@ -1013,10 +1022,11 @@
             arguments='',
             interpreter=None,
             initialization='',
-            exclude_site_packages=False,
+            include_site_packages=False,
             relative_paths=False
             ):
-    path = get_path(working_set, executable, exclude_site_packages)
+    path = get_path(
+        working_set, executable, extra_paths, include_site_packages)
     generated = []
 
     if isinstance(reqs, str):
@@ -1053,7 +1063,7 @@
 
         generated.extend(
             _script(module_name, attrs, spath, sname, executable, arguments,
-                    initialization, rpsetup, exclude_site_packages)
+                    initialization, rpsetup)
             )
 
     if interpreter:
@@ -1217,30 +1227,47 @@
     return generated
 
 py_script_template = script_header + '''\
+%(relative_paths_setup)s
 
-%(relative_paths_setup)s
 import sys
 
-sys.path[0:0] = [
-  %(path)s,
-  ]
+_set_path = _interactive = True
+_force_interactive = False
 
-_interactive = True
+_commands = []
+_args = None
+
 if len(sys.argv) > 1:
     import getopt
-    _options, _args = getopt.getopt(sys.argv[1:], 'ic:')
-    _interactive = False
+    _options, _args = getopt.getopt(sys.argv[1:], 'VSic:')
     for (_opt, _val) in _options:
         if _opt == '-i':
-            _interactive = True
+            _force_interactive = True
         elif _opt == '-c':
-            exec _val
+            _interactive = False
+            _commands.append(_val)
+        elif _opt == '-S':
+            # We'll approximate this.  It is mostly convenient for tests.
+            _set_path = False
+        elif _opt == '-V':
+            print 'Python ' + sys.version.split()[0]
+            _interactive = False
 
-    if _args:
-        sys.argv[:] = _args
-        execfile(sys.argv[0])
+if _set_path:
+    sys.path[:] = [
+    %(path)s,
+    ]
+sys.path.insert(0, '.')
 
-if _interactive:
+for _command in _commands:
+    exec _command
+
+if _args:
+    _interactive = False
+    sys.argv[:] = _args
+    execfile(sys.argv[0])
+
+if _interactive or _force_interactive:
     import code
     code.interact(banner="", local=globals())
 '''

Modified: zc.buildout/branches/gary-support-system-python/src/zc/buildout/easy_install.txt
===================================================================
--- zc.buildout/branches/gary-support-system-python/src/zc/buildout/easy_install.txt	2009-07-06 19:22:49 UTC (rev 101672)
+++ zc.buildout/branches/gary-support-system-python/src/zc/buildout/easy_install.txt	2009-07-07 00:14:39 UTC (rev 101673)
@@ -89,6 +89,10 @@
    for using dependency_links in preference to other
    locations. Defaults to true.
 
+include_site_packages
+    A flag indicating whether Python's non-standard-library packages should
+    be available for finding dependencies.  Defaults to true.
+
 relative_paths
    Adjust egg paths so they are relative to the script path.  This
    allows scripts to work when scripts and eggs are moved, as long as
@@ -399,6 +403,65 @@
     >>> [d.version for d in ws]
     ['0.3', '1.1']
 
+Dependencies in Site Packages
+-----------------------------
+
+Setuptools includes packages found in the Python executable's system path
+(sys.path) when searching for dependencies.  This can be disabled, so that
+a system Python can be used with buildout, cleaned of any packages installed
+by a user or system package manager.
+
+The default behavior can be controlled and introspected using
+zc.buildout.easy_install.include_site_packages.
+
+    >>> zc.buildout.easy_install.include_site_packages()
+    True
+
+Here's an example of using a Python executable that includes our dependencies.
+
+    >>> primed_executable = get_executable_with_site_packages()
+
+    >>> example_dest = tmpdir('site-packages-example-install')
+    >>> workingset = zc.buildout.easy_install.install(
+    ...     ['demo'], example_dest, links=[], executable=primed_executable,
+    ...     index=None)
+    >>> [dist.project_name for dist in workingset]
+    ['demo', 'demoneeded']
+
+That worked fine.  Let's try again with site packages not allowed.  We'll
+change the policy by changing the default.  Notice that the function for
+changing the default value returns the previous value.
+
+    >>> zc.buildout.easy_install.include_site_packages(False)
+    True
+
+    >>> zc.buildout.easy_install.include_site_packages()
+    False
+
+    >>> zc.buildout.easy_install.clear_index_cache()
+    >>> rmdir(example_dest)
+    >>> example_dest = tmpdir('site-packages-example-install')
+    >>> workingset = zc.buildout.easy_install.install(
+    ...     ['demo'], example_dest, links=[], executable=primed_executable,
+    ...     index=None)
+    Traceback (most recent call last):
+        ...
+    MissingDistribution: Couldn't find a distribution for 'demo'.
+
+Now we'll reset the default.
+
+    >>> zc.buildout.easy_install.include_site_packages(True)
+    False
+
+    >>> zc.buildout.easy_install.include_site_packages()
+    True
+
+We'll also reset a value expected by the rest of the test.
+
+    >>> # get_executable_with_site_packages resets the Installer
+    >>> zc.buildout.easy_install.prefer_final(True)
+    False
+
 Dependency links
 ----------------
 
@@ -580,13 +643,14 @@
 
 The demo script run the entry point defined in the demo egg:
 
-    >>> cat(bin, 'demo') # doctest: +NORMALIZE_WHITESPACE
+    >>> cat(bin, 'demo') # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
     #!/usr/local/bin/python2.4
     <BLANKLINE>
     import sys
-    sys.path[0:0] = [
+    sys.path[:] = [
       '/sample-install/demo-0.3-py2.4.egg',
       '/sample-install/demoneeded-1.1-py2.4.egg',
+      ...
       ]
     <BLANKLINE>
     import eggrecipedemo
@@ -596,7 +660,8 @@
 
 Some things to note:
 
-- The demo and demoneeded eggs are added to the beginning of sys.path.
+- The demo and demoneeded eggs are at the beginning of sys.path.  The script
+  controls the entire path.
 
 - The module for the script entry point is imported and the entry
   point, in this case, 'main', is run.
@@ -617,13 +682,14 @@
     ...     [('demo', 'eggrecipedemo', 'main')],
     ...     ws, sys.executable, bin)
 
-    >>> cat(bin, 'demo') # doctest: +NORMALIZE_WHITESPACE
+    >>> cat(bin, 'demo') # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
     #!/usr/local/bin/python2.4
     <BLANKLINE>
     import sys
-    sys.path[0:0] = [
+    sys.path[:] = [
       '/sample-install/demo-0.3-py2.4.egg',
       '/sample-install/demoneeded-1.1-py2.4.egg',
+      ...
       ]
     <BLANKLINE>
     import eggrecipedemo
@@ -661,31 +727,50 @@
 The py script simply runs the Python interactive interpreter with
 the path set:
 
-    >>> cat(bin, 'py') # doctest: +NORMALIZE_WHITESPACE
+    >>> cat(bin, 'py') # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
     #!/usr/local/bin/python2.4
+    <BLANKLINE>
     import sys
     <BLANKLINE>
-    sys.path[0:0] = [
-      '/sample-install/demo-0.3-py2.4.egg',
-      '/sample-install/demoneeded-1.1-py2.4.egg',
-      ]
+    _set_path = _interactive = True
+    _force_interactive = False
     <BLANKLINE>
-    _interactive = True
+    _commands = []
+    _args = None
+    <BLANKLINE>
     if len(sys.argv) > 1:
         import getopt
-        _options, _args = getopt.getopt(sys.argv[1:], 'ic:')
-        _interactive = False
+        _options, _args = getopt.getopt(sys.argv[1:], 'VSic:')
         for (_opt, _val) in _options:
             if _opt == '-i':
-                _interactive = True
+                _force_interactive = True
             elif _opt == '-c':
-                exec _val
+                _interactive = False
+                _commands.append(_val)
+            elif _opt == '-S':
+                # We'll approximate this.  It is mostly convenient for tests.
+                _set_path = False
+            elif _opt == '-V':
+                print 'Python ' + sys.version.split()[0]
+                _interactive = False
     <BLANKLINE>
-        if _args:
-            sys.argv[:] = _args
-            execfile(sys.argv[0])
+    if _set_path:
+        sys.path[:] = [
+        '/sample-install/demo-0.3-pyN.N.egg',
+      '/sample-install/demoneeded-1.1-pyN.N.egg',
+      ...
+        ]
+    sys.path.insert(0, '.')
     <BLANKLINE>
-    if _interactive:
+    for _command in _commands:
+        exec _command
+    <BLANKLINE>
+    if _args:
+        _interactive = False
+        sys.argv[:] = _args
+        execfile(sys.argv[0])
+    <BLANKLINE>
+    if _interactive or _force_interactive:
         import code
         code.interact(banner="", local=globals())
 
@@ -722,14 +807,15 @@
     ...    ['demo'], ws, sys.executable, bin, dict(demo='run'),
     ...    extra_paths=[foo])
 
-    >>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE
+    >>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
     #!/usr/local/bin/python2.4
     <BLANKLINE>
     import sys
-    sys.path[0:0] = [
+    sys.path[:] = [
       '/sample-install/demo-0.3-py2.4.egg',
       '/sample-install/demoneeded-1.1-py2.4.egg',
       '/foo',
+      ...
       ]
     <BLANKLINE>
     import eggrecipedemo
@@ -748,12 +834,13 @@
     ...    ['demo'], ws, sys.executable, bin, dict(demo='run'),
     ...    arguments='1, 2')
 
-    >>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE
+    >>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
     #!/usr/local/bin/python2.4
     import sys
-    sys.path[0:0] = [
+    sys.path[:] = [
       '/sample-install/demo-0.3-py2.4.egg',
       '/sample-install/demoneeded-1.1-py2.4.egg',
+      ...
       ]
     <BLANKLINE>
     import eggrecipedemo
@@ -771,12 +858,13 @@
     ...    arguments='1, 2',
     ...    initialization='import os\nos.chdir("foo")')
 
-    >>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE
+    >>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
     #!/usr/local/bin/python2.4
     import sys
-    sys.path[0:0] = [
+    sys.path[:] = [
       '/sample-install/demo-0.3-py2.4.egg',
       '/sample-install/demoneeded-1.1-py2.4.egg',
+      ...
       ]
     <BLANKLINE>
     import os
@@ -811,7 +899,7 @@
     ...    interpreter='py',
     ...    relative_paths=bo)
 
-    >>> cat(bo, 'bin', 'run')
+    >>> cat(bo, 'bin', 'run') # doctest: +ELLIPSIS
     #!/usr/local/bin/python2.4
     <BLANKLINE>
     import os
@@ -821,11 +909,12 @@
     base = os.path.dirname(base)
     <BLANKLINE>
     import sys
-    sys.path[0:0] = [
+    sys.path[:] = [
       join(base, 'eggs/demo-0.3-pyN.N.egg'),
       join(base, 'eggs/demoneeded-1.1-pyN.N.egg'),
       '/ba',
       join(base, 'bar'),
+      ...
       ]
     <BLANKLINE>
     import eggrecipedemo
@@ -843,44 +932,61 @@
 
 We specified an interpreter and its paths are adjusted too:
 
-    >>> cat(bo, 'bin', 'py')
+    >>> cat(bo, 'bin', 'py') # doctest: +ELLIPSIS
     #!/usr/local/bin/python2.4
-    <BLANKLINE>
     import os
     <BLANKLINE>
     join = os.path.join
     base = os.path.dirname(os.path.abspath(__file__))
     base = os.path.dirname(base)
     <BLANKLINE>
+    <BLANKLINE>
     import sys
     <BLANKLINE>
-    sys.path[0:0] = [
-      join(base, 'eggs/demo-0.3-pyN.N.egg'),
-      join(base, 'eggs/demoneeded-1.1-pyN.N.egg'),
-      '/ba',
-      join(base, 'bar'),
-      ]
+    _set_path = _interactive = True
+    _force_interactive = False
     <BLANKLINE>
-    _interactive = True
+    _commands = []
+    _args = None
+    <BLANKLINE>
     if len(sys.argv) > 1:
         import getopt
-        _options, _args = getopt.getopt(sys.argv[1:], 'ic:')
-        _interactive = False
+        _options, _args = getopt.getopt(sys.argv[1:], 'VSic:')
         for (_opt, _val) in _options:
             if _opt == '-i':
-                _interactive = True
+                _force_interactive = True
             elif _opt == '-c':
-                exec _val
+                _interactive = False
+                _commands.append(_val)
+            elif _opt == '-S':
+                # We'll approximate this.  It is mostly convenient for tests.
+                _set_path = False
+            elif _opt == '-V':
+                print 'Python ' + sys.version.split()[0]
+                _interactive = False
     <BLANKLINE>
-        if _args:
-            sys.argv[:] = _args
-            execfile(sys.argv[0])
+    if _set_path:
+        sys.path[:] = [
+        join(base, 'eggs/demo-0.3-pyN.N.egg'),
+      join(base, 'eggs/demoneeded-1.1-pyN.N.egg'),
+      '/ba',
+      join(base, 'bar'),
+      ...
+        ]
+    sys.path.insert(0, '.')
     <BLANKLINE>
-    if _interactive:
+    for _command in _commands:
+        exec _command
+    <BLANKLINE>
+    if _args:
+        _interactive = False
+        sys.argv[:] = _args
+        execfile(sys.argv[0])
+    <BLANKLINE>
+    if _interactive or _force_interactive:
         import code
         code.interact(banner="", local=globals())
 
-
 Handling custom build options for extensions provided in source distributions
 -----------------------------------------------------------------------------
 

Modified: zc.buildout/branches/gary-support-system-python/src/zc/buildout/testing.py
===================================================================
--- zc.buildout/branches/gary-support-system-python/src/zc/buildout/testing.py	2009-07-06 19:22:49 UTC (rev 101672)
+++ zc.buildout/branches/gary-support-system-python/src/zc/buildout/testing.py	2009-07-07 00:14:39 UTC (rev 101673)
@@ -272,7 +272,7 @@
 
 
     # Create the develop-eggs dir, which didn't get created the usual
-    # way due to thr trick above:
+    # way due to the trick above:
     os.mkdir('develop-eggs')
 
     def start_server(path):

Modified: zc.buildout/branches/gary-support-system-python/src/zc/buildout/tests.py
===================================================================
--- zc.buildout/branches/gary-support-system-python/src/zc/buildout/tests.py	2009-07-06 19:22:49 UTC (rev 101672)
+++ zc.buildout/branches/gary-support-system-python/src/zc/buildout/tests.py	2009-07-07 00:14:39 UTC (rev 101673)
@@ -16,7 +16,7 @@
 $Id$
 """
 
-import os, re, shutil, sys, tempfile, unittest, zipfile
+import os, re, shutil, sys, tempfile, textwrap, unittest, zipfile
 from zope.testing import doctest, renormalizing
 import pkg_resources
 import zc.buildout.testing, zc.buildout.easy_install
@@ -2156,7 +2156,7 @@
     """
 This test tests several permutations:
 
-Using different version numbers to work around zip impporter cache problems. :(
+Using different version numbers to work around zip importer cache problems. :(
 
 - With prefer final:
 
@@ -2338,6 +2338,122 @@
 
     """
 
+def isolated_include_site_packages():
+    """
+
+This is an isolated test of the include_site_packages functionality, passing
+the argument directly to install, overriding a default.
+
+    >>> primed_executable = get_executable_with_site_packages()
+    >>> zc.buildout.easy_install.include_site_packages(False)
+    True
+
+    >>> example_dest = tmpdir('site-packages-example-install')
+    >>> workingset = zc.buildout.easy_install.install(
+    ...     ['demo'], example_dest, links=[], executable=primed_executable,
+    ...     index=None, include_site_packages=True)
+    >>> [dist.project_name for dist in workingset]
+    ['demo', 'demoneeded']
+
+That worked fine.  Let's try again with site packages not allowed (and
+reversing the default).
+
+    >>> zc.buildout.easy_install.include_site_packages(True)
+    False
+
+    >>> zc.buildout.easy_install.clear_index_cache()
+    >>> rmdir(example_dest)
+    >>> example_dest = tmpdir('site-packages-example-install')
+    >>> workingset = zc.buildout.easy_install.install(
+    ...     ['demo'], example_dest, links=[], executable=primed_executable,
+    ...     index=None, include_site_packages=False)
+    Traceback (most recent call last):
+        ...
+    MissingDistribution: Couldn't find a distribution for 'demo'.
+
+That's a failure, as expected.
+
+    """
+
+def buildout_include_site_packages_option():
+    """
+The include-site-packages buildout option can be used to override the default
+behavior of using site packages.
+
+The default is include-site-packages = true.  As a demonstration, notice we do
+not set find-links, but the eggs are still found because they are in the
+executable's path.
+
+    >>> primed_executable = get_executable_with_site_packages()
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... parts = eggs
+    ...
+    ... [primed_python]
+    ... executable = %(primed_executable)s
+    ...
+    ... [eggs]
+    ... recipe = zc.recipe.egg:eggs
+    ... python = primed_python
+    ... eggs = demo
+    ... ''' % globals())
+
+    >>> print system(primed_executable+" "+buildout)
+    Installing eggs.
+    <BLANKLINE>
+
+However, if we set include-site-packages to false, we get an error, because
+the packages are not available in any links, and they are not allowed to be
+obtained from the executable's site packages.
+
+    >>> zc.buildout.easy_install.clear_index_cache()
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... parts = eggs
+    ... include-site-packages = false
+    ...
+    ... [primed_python]
+    ... executable = %(primed_executable)s
+    ...
+    ... [eggs]
+    ... recipe = zc.recipe.egg:eggs
+    ... eggs = demo
+    ... ''' % globals())
+    >>> print system(primed_executable+" "+buildout)
+    Uninstalling eggs.
+    Installing eggs.
+    Couldn't find index page for 'demo' (maybe misspelled?)
+    Getting distribution for 'demo'.
+    While:
+      Installing eggs.
+      Getting distribution for 'demo'.
+    Error: Couldn't find a distribution for 'demo'.
+    <BLANKLINE>
+
+We get an error if we specify anything but true or false:
+
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... parts = eggs
+    ... find-links = %(link_server)s
+    ... include-site-packages = no
+    ...
+    ... [eggs]
+    ... recipe = zc.recipe.egg:eggs
+    ... eggs = demo
+    ... ''' % globals())
+
+    >>> print system(primed_executable+" "+buildout)
+    While:
+      Initializing.
+    Error: Invalid value for include-site-packages option: no
+    <BLANKLINE>
+
+    """
+
 def develop_with_modules():
     """
 Distribution setup scripts can import modules in the distribution directory:
@@ -2652,7 +2768,42 @@
         test.globs['sample_eggs'])
     test.globs['update_extdemo'] = lambda : add_source_dist(test, 1.5)
     zc.buildout.testing.install_develop('zc.recipe.egg', test)
+    # most tests don't need this set up, and it takes some time, so we just
+    # make it available as a convenience.
+    def get_executable_with_site_packages():
+        executable_buildout = test.globs['tmpdir']('executable')
+        old_wd = os.getcwd()
+        os.chdir(executable_buildout)
+        test.globs['write']('buildout.cfg', textwrap.dedent(
+            '''
+            [buildout]
+            parts = interpreter
+            find-links = %(link_server)s
 
+            [interpreter]
+            recipe = zc.recipe.egg
+            interpreter = py
+            eggs = demo
+            ''' % test.globs))
+        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([])
+        os.mkdir('develop-eggs')
+        zc.buildout.testing.install_develop(
+            'zc.recipe.egg',
+            os.path.join(executable_buildout, 'develop-eggs'))
+        test.globs['system'](
+            os.path.join(executable_buildout, 'bin', 'buildout'))
+        os.chdir(old_wd)
+        return os.path.join(executable_buildout, 'bin', 'py')
+    test.globs['get_executable_with_site_packages'] = (
+        get_executable_with_site_packages)
+
 egg_parse = re.compile('([0-9a-zA-Z_.]+)-([0-9a-zA-Z_.]+)-py(\d[.]\d).egg$'
                        ).match
 def makeNewRelease(project, ws, dest):

Modified: zc.buildout/branches/gary-support-system-python/zc.recipe.egg_/src/zc/recipe/egg/egg.py
===================================================================
--- zc.buildout/branches/gary-support-system-python/zc.recipe.egg_/src/zc/recipe/egg/egg.py	2009-07-06 19:22:49 UTC (rev 101672)
+++ zc.buildout/branches/gary-support-system-python/zc.recipe.egg_/src/zc/recipe/egg/egg.py	2009-07-07 00:14:39 UTC (rev 101673)
@@ -54,13 +54,13 @@
 
         python = options.get('python', buildout['buildout']['python'])
         options['executable'] = buildout[python]['executable']
-        exclude_site_packages = self.options.get(
-            'exclude-site-packages',
-            self.buildout['buildout'].get('exclude-site-packages', 'false')
-        if exclude_site_packages not in ('true', 'false'):
-            self._error('Invalid value for exclude-site-packages option: %s',
-                        exclude_site_packages)
-        self.exclude_site_packages = (exclude_site_packages=='true')
+        include_site_packages = self.options.get(
+            'include-site-packages',
+            self.buildout['buildout'].get('include-site-packages', 'true'))
+        if include_site_packages not in ('true', 'false'):
+            self._error('Invalid value for include-site-packages option: %s',
+                        include_site_packages)
+        self.include_site_packages = (include_site_packages=='true')
 
     def working_set(self, extra=()):
         """Separate method to just get the working set
@@ -80,7 +80,7 @@
             ws = zc.buildout.easy_install.working_set(
                 distributions, options['executable'],
                 [options['develop-eggs-directory'], options['eggs-directory']],
-                exclude_site_packages=self.exclude_site_packages
+                include_site_packages=self.include_site_packages
                 )
         else:
             kw = {}
@@ -95,7 +95,7 @@
                 path=[options['develop-eggs-directory']],
                 newest=self.buildout['buildout'].get('newest') == 'true',
                 allow_hosts=self.allow_hosts,
-                exclude_site_packages=self.exclude_site_packages,
+                include_site_packages=self.include_site_packages,
                 **kw)
 
         return orig_distributions, ws
@@ -175,7 +175,7 @@
                 interpreter=options.get('interpreter'),
                 initialization=options.get('initialization', ''),
                 arguments=options.get('arguments', ''),
-                exclude_site_packages=self.exclude_site_packages,
+                include_site_packages=self.include_site_packages,
                 relative_paths=self._relative_paths
                 )
 



More information about the Checkins mailing list