Controlling which Python to use
-------------------------------

The following assumes that you have Python 2.3 installed.

We can specify the python to use by specifying the name of a section
to read the Python executable from.  The default is the section
defined by the python buildout option.

We have a link server:

    >>> print get(link_server),
    <html><body>
    <a href="demo-0.1-py2.3.egg">demo-0.1-py2.3.egg</a><br>
    <a href="demo-0.2-py2.3.egg">demo-0.2-py2.3.egg</a><br>
    <a href="demo-0.3-py2.3.egg">demo-0.3-py2.3.egg</a><br>
    <a href="demoneeded-1.0.zip">demoneeded-1.0.zip</a><br>
    <a href="demoneeded-1.1.zip">demoneeded-1.1.zip</a><br>
    <a href="extdemo-1.4.zip">extdemo-1.4.zip</a><br>
    <a href="index/">index/</a><br>
    <a href="other-1.0-py2.3.egg">other-1.0-py2.3.egg</a><br>
    </body></html>

We have a sample buildout.  Let's update it's configuration file to
install the demo package using Python 2.3. 

    >>> write(sample_buildout, 'buildout.cfg',
    ... """
    ... [buildout]
    ... parts = demo
    ... eggs-directory = eggs
    ... index = http://www.python.org/pypi/
    ...
    ... [python2.3]
    ... executable = %(python23)s
    ...
    ... [demo]
    ... recipe = zc.recipe.egg
    ... eggs = demo <0.3
    ... find-links = %(server)s
    ... python = python2.3
    ... interpreter = py-demo
    ... """ % dict(server=link_server, python23=python2_3_executable))

Now, if we run the buildout:

    >>> import os
    >>> os.chdir(sample_buildout)
    >>> buildout = os.path.join(sample_buildout, 'bin', 'buildout')
    >>> print system(buildout),
    buildout: Installing demo
    zc.buildout.easy_install: Getting new distribution for demo<0.3
    zc.buildout.easy_install: Got demo 0.2
    zc.buildout.easy_install: Getting new distribution for demoneeded
    zc.buildout.easy_install: Getting new distribution for setuptools
    zc.buildout.easy_install: Got setuptools 0.6
    zc.buildout.easy_install: Got demoneeded 1.1

we'll get the Python 2.3 eggs for demo and demoneeded:

    >>> ls(sample_buildout, 'eggs')
    -  demo-0.2-py2.3.egg
    -  demoneeded-1.1-py2.3.egg
    d  setuptools-0.6-py2.3.egg
    d  setuptools-0.6-py2.4.egg
    -  zc.buildout-1.0-py2.4.egg
 
And the generated scripts invoke Python 2.3:

    >>> import sys
    >>> if sys.platform == 'win32':
    ...    script_name = 'demo-script.py'
    ... else:
    ...    script_name = 'demo'
    >>> f = open(os.path.join(sample_buildout, 'bin', script_name))
    >>> f.readline().strip() == '#!' + python2_3_executable
    True
    >>> print f.read(), # doctest: +NORMALIZE_WHITESPACE
    <BLANKLINE>
    import sys
    sys.path[0:0] = [
      '/sample-buildout/eggs/demo-0.2-py2.3.egg',
      '/sample-buildout/eggs/demoneeded-1.1-py2.3.egg',
      ]
    <BLANKLINE>
    import eggrecipedemo
    <BLANKLINE>
    if __name__ == '__main__':
        eggrecipedemo.main()

    >>> if sys.platform == 'win32':
    ...     f = open(os.path.join(sample_buildout, 'bin', 'py-demo-script.py'))
    ... else:
    ...     f = open(os.path.join(sample_buildout, 'bin', 'py-demo'))
    >>> f.readline().strip() == '#!' + python2_3_executable
    True
    >>> print f.read(), # doctest: +NORMALIZE_WHITESPACE
    import sys
    <BLANKLINE>
    sys.path[0:0] = [
      '/sample-buildout/eggs/demo-0.2-py2.3.egg',
      '/sample-buildout/eggs/demoneeded-1.1-py2.3.egg',
      ]
    <BLANKLINE>
    _interactive = True
    if len(sys.argv) > 1:
        import getopt
        _options, _args = getopt.getopt(sys.argv[1:], 'ic:')
        _interactive = False
        for (_opt, _val) in _options:
            if _opt == '-i':
                _interactive = True
            elif _opt == '-c':
                exec _val
    <BLANKLINE>
        if _args:
            sys.argv[:] = _args
            execfile(sys.argv[0])
    <BLANKLINE>
    if _interactive:
        import code
        code.interact(banner="", local=globals())

    >>> f.close()
