Commit c32aa1b2 authored by Jim Fulton's avatar Jim Fulton

Removed multi-python support

parent b00423b2
......@@ -113,8 +113,6 @@ _buildout_default_options = _annotate_section({
'bin-directory': 'bin',
'parts-directory': 'parts',
'installed': '.installed.cfg',
'python': 'buildout',
'executable': sys.executable,
'log-level': 'INFO',
'log-format': '',
}, 'DEFAULT_VALUE')
......
......@@ -739,8 +739,6 @@ COMMAND_LINE_VALUE).
COMPUTED_VALUE
eggs-directory= eggs
DEFAULT_VALUE
executable= ...
DEFAULT_VALUE
installed= .installed.cfg
DEFAULT_VALUE
log-format=
......@@ -751,8 +749,6 @@ COMMAND_LINE_VALUE).
/sample-buildout/buildout.cfg
parts-directory= parts
DEFAULT_VALUE
python= buildout
DEFAULT_VALUE
<BLANKLINE>
[data-dir]
path= foo bins
......@@ -2209,7 +2205,6 @@ database is shown.
develop-eggs-directory = /sample-buildout/develop-eggs
directory = /sample-buildout
eggs-directory = /sample-buildout/eggs
executable = /usr/local/bin/python2.3
installed = /sample-buildout/.installed.cfg
log-format =
log-level = INFO
......@@ -2217,7 +2212,6 @@ database is shown.
offline = false
parts =
parts-directory = /sample-buildout/parts
python = buildout
verbosity = 20
<BLANKLINE>
......@@ -2245,10 +2239,6 @@ eggs-directory
*never* be modified. This can be a relative path, which is
interpreted relative to the directory option.
executable
The Python executable used to run the buildout. See the python
option below.
installed
The file path where information about the results of the previous
buildout run is written. This can be a relative path, which is
......@@ -2268,16 +2258,6 @@ parts
parts-directory
A working directory that parts can used to store data.
python
The name of a section containing information about the default
Python interpreter. Recipes that need a installation
typically have options to tell them which Python installation to
use. By convention, if a section-specific option isn't used, the
option is looked for in the buildout section. The option must
point to a section with an executable option giving the path to a
Python executable. By default, the buildout section defines the
default Python as the Python used to run the buildout.
verbosity
A log-level adjustment. Typically, this is set via the -q and -v
command-line options.
......
......@@ -72,31 +72,8 @@ class IncompatibleVersionError(zc.buildout.UserError):
"""A specified version is incompatible with a given requirement.
"""
_versions = {sys.executable: '%d.%d' % sys.version_info[:2]}
def _get_version(executable):
try:
return _versions[executable]
except KeyError:
cmd = executable + ' -V'
p = subprocess.Popen(cmd,
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
close_fds=not is_win32)
i, o = (p.stdin, p.stdout)
i.close()
version = o.read().strip()
o.close()
pystring, version = version.split()
assert pystring == 'Python'
version = re.match('(\d[.]\d)([.].*\d)?$', version).group(1)
_versions[executable] = version
return version
FILE_SCHEME = re.compile('file://', re.I).match
class AllowHostsPackageIndex(setuptools.package_index.PackageIndex):
"""Will allow urls that are local to the system.
......@@ -109,17 +86,15 @@ class AllowHostsPackageIndex(setuptools.package_index.PackageIndex):
_indexes = {}
def _get_index(executable, index_url, find_links, allow_hosts=('*',)):
key = executable, index_url, tuple(find_links)
def _get_index(index_url, find_links, allow_hosts=('*',)):
key = index_url, tuple(find_links)
index = _indexes.get(key)
if index is not None:
return index
if index_url is None:
index_url = default_index_url
index = AllowHostsPackageIndex(
index_url, hosts=allow_hosts, python=_get_version(executable)
)
index = AllowHostsPackageIndex(index_url, hosts=allow_hosts)
if find_links:
index.add_find_links(find_links)
......@@ -167,6 +142,7 @@ class Installer:
use_dependency_links=None,
allow_hosts=('*',)
):
assert executable == sys.executable, (executable, sys.executable)
self._dest = dest
self._allow_hosts = allow_hosts
......@@ -184,7 +160,6 @@ class Installer:
links.insert(0, self._download_cache)
self._index_url = index
self._executable = executable
if always_unzip is not None:
self._always_unzip = always_unzip
path = (path and path[:] or []) + buildout_and_setuptools_path
......@@ -194,9 +169,8 @@ class Installer:
if self._dest is None:
newest = False
self._newest = newest
self._env = pkg_resources.Environment(path,
python=_get_version(executable))
self._index = _get_index(executable, index, links, self._allow_hosts)
self._env = pkg_resources.Environment(path)
self._index = _get_index(index, links, self._allow_hosts)
if versions is not None:
self._versions = versions
......@@ -291,10 +265,7 @@ class Installer:
return best_we_have, None
def _load_dist(self, dist):
dists = pkg_resources.Environment(
dist.location,
python=_get_version(self._executable),
)[dist.project_name]
dists = pkg_resources.Environment(dist.location)[dist.project_name]
assert len(dists) == 1
return dists[0]
......@@ -304,7 +275,7 @@ class Installer:
try:
path = setuptools_loc
args = [self._executable, '-c', _easy_install_cmd, '-mUNxd', tmp]
args = [sys.executable, '-c', _easy_install_cmd, '-mUNxd', tmp]
if self._always_unzip:
args.append('-Z')
level = logger.getEffectiveLevel()
......@@ -316,8 +287,8 @@ class Installer:
args.append(spec)
if level <= logging.DEBUG:
logger.debug('Running easy_install:\n%s "%s"\npath=%s\n',
self._executable, '" "'.join(args), path)
logger.debug('Running easy_install:\n"%s"\npath=%s\n',
'" "'.join(args), path)
sys.stdout.flush() # We want any pending output first
......@@ -326,10 +297,7 @@ class Installer:
env=dict(os.environ, PYTHONPATH=path))
dists = []
env = pkg_resources.Environment(
[tmp],
python=_get_version(self._executable),
)
env = pkg_resources.Environment([tmp])
for project in env:
dists.extend(env[project])
......@@ -373,10 +341,7 @@ class Installer:
os.remove(newloc)
os.rename(d.location, newloc)
[d] = pkg_resources.Environment(
[newloc],
python=_get_version(self._executable),
)[d.project_name]
[d] = pkg_resources.Environment([newloc])[d.project_name]
result.append(d)
......@@ -525,10 +490,8 @@ class Installer:
# Getting the dist from the environment causes the
# distribution meta data to be read. Cloning isn't
# good enough.
dists = pkg_resources.Environment(
[newloc],
python=_get_version(self._executable),
)[dist.project_name]
dists = pkg_resources.Environment([newloc])[
dist.project_name]
else:
# It's some other kind of dist. We'll let easy_install
# deal with it:
......@@ -558,8 +521,7 @@ class Installer:
if link not in self._links:
logger.debug('Adding find link %r from %s', link, dist)
self._links.append(link)
self._index = _get_index(self._executable,
self._index_url, self._links,
self._index = _get_index(self._index_url, self._links,
self._allow_hosts)
for dist in dists:
......@@ -787,7 +749,9 @@ def install(specs, dest,
executable=sys.executable, always_unzip=None,
path=None, working_set=None, newest=True, versions=None,
use_dependency_links=None, allow_hosts=('*',)):
installer = Installer(dest, links, index, executable, always_unzip, path,
assert executable == sys.executable, (executable, sys.executable)
installer = Installer(dest, links, index, sys.executable,
always_unzip, path,
newest, versions, use_dependency_links,
allow_hosts=allow_hosts)
return installer.install(specs, working_set)
......@@ -797,7 +761,9 @@ def build(spec, dest, build_ext,
links=(), index=None,
executable=sys.executable,
path=None, newest=True, versions=None, allow_hosts=('*',)):
installer = Installer(dest, links, index, executable, True, path, newest,
assert executable == sys.executable, (executable, sys.executable)
installer = Installer(dest, links, index, sys.executable,
True, path, newest,
versions, allow_hosts=allow_hosts)
return installer.build(spec, build_ext)
......@@ -828,7 +794,7 @@ def _copyeggs(src, dest, suffix, undo):
def develop(setup, dest,
build_ext=None,
executable=sys.executable):
assert executable == sys.executable, (executable, sys.executable)
if os.path.isdir(setup):
directory = setup
setup = os.path.join(directory, 'setup.py')
......@@ -866,7 +832,7 @@ def develop(setup, dest,
tmp3 = tempfile.mkdtemp('build', dir=dest)
undo.append(lambda : shutil.rmtree(tmp3))
args = [executable, tsetup, '-q', 'develop', '-mxN', '-d', tmp3]
args = [sys.executable, tsetup, '-q', 'develop', '-mxN', '-d', tmp3]
log_level = logger.getEffectiveLevel()
if log_level <= 0:
......@@ -886,10 +852,15 @@ def develop(setup, dest,
[f() for f in undo]
def working_set(specs, executable, path):
return install(specs, None, executable=executable, path=path)
def working_set(specs, executable, path=None):
# Backward compat:
if path is None:
path = executable
else:
assert executable == sys.executable, (executable, sys.executable)
return install(specs, None, path=path)
def scripts(reqs, working_set, executable, dest,
def scripts(reqs, working_set, executable, dest=None,
scripts=None,
extra_paths=(),
arguments='',
......@@ -897,6 +868,7 @@ def scripts(reqs, working_set, executable, dest,
initialization='',
relative_paths=False,
):
assert executable == sys.executable, (executable, sys.executable)
path = [dist.location for dist in working_set]
path.extend(extra_paths)
......@@ -942,14 +914,14 @@ def scripts(reqs, working_set, executable, dest,
spath, rpsetup = _relative_path_and_setup(sname, path, relative_paths)
generated.extend(
_script(module_name, attrs, spath, sname, executable, arguments,
_script(module_name, attrs, spath, sname, arguments,
initialization, rpsetup)
)
if interpreter:
sname = os.path.join(dest, interpreter)
spath, rpsetup = _relative_path_and_setup(sname, path, relative_paths)
generated.extend(_pyscript(spath, sname, executable, rpsetup))
generated.extend(_pyscript(spath, sname, rpsetup))
return generated
......@@ -1014,15 +986,14 @@ join = os.path.join
base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
"""
def _script(module_name, attrs, path, dest, executable, arguments,
initialization, rsetup):
def _script(module_name, attrs, path, dest, arguments, initialization, rsetup):
generated = []
script = dest
if is_win32:
dest += '-script.py'
contents = script_template % dict(
python = _safe_arg(executable),
python = _safe_arg(sys.executable),
path = path,
module_name = module_name,
attrs = attrs,
......@@ -1074,14 +1045,14 @@ if __name__ == '__main__':
'''
def _pyscript(path, dest, executable, rsetup):
def _pyscript(path, dest, rsetup):
generated = []
script = dest
if is_win32:
dest += '-script.py'
contents = py_script_template % dict(
python = _safe_arg(executable),
python = _safe_arg(sys.executable),
path = path,
relative_paths_setup = rsetup,
)
......
......@@ -53,10 +53,6 @@ index
we'll just point to an empty directory on our link server. This
will make our examples run a little bit faster.
executable
A path to a Python executable. Distributions will be installed
using this executable and will be for the matching Python version.
path
A list of additional directories to search for locally-installed
distributions.
......@@ -547,7 +543,7 @@ from the demo egg:
>>> scripts = zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, bin)
the four arguments we passed were:
the three arguments we passed were:
1. A sequence of distribution requirements. These are of the same
form as setuptools requirements. Here we passed a single
......@@ -555,8 +551,6 @@ the four arguments we passed were:
2. A working set,
3. The Python executable to use, and
3. The destination directory.
The bin directory now contains a generated script:
......@@ -582,7 +576,7 @@ interpreter and without having to provide a '.py' suffix.
The demo script run the entry point defined in the demo egg:
>>> cat(bin, 'demo') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.4
#!/usr/local/bin/python2.7
<BLANKLINE>
import sys
sys.path[0:0] = [
......@@ -615,11 +609,11 @@ For example, we could have passed entry point information directly
rather than passing a requirement:
>>> scripts = zc.buildout.easy_install.scripts(
... [('demo', 'eggrecipedemo', 'main')],
... ws, sys.executable, bin)
... [('demo', 'eggrecipedemo', 'main')], ws,
... sys.executable, bin)
>>> cat(bin, 'demo') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.4
#!/usr/local/bin/python2.7
<BLANKLINE>
import sys
sys.path[0:0] = [
......@@ -663,7 +657,7 @@ The py script simply runs the Python interactive interpreter with
the path set:
>>> cat(bin, 'py') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.4
#!/usr/local/bin/python2.7
<BLANKLINE>
import sys
<BLANKLINE>
......@@ -723,7 +717,7 @@ original script names to new script names.
>>> bin = tmpdir('bin2')
>>> scripts = zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, bin, dict(demo='run'))
... ['demo'], ws, sys.executable, bin, dict(demo='run'))
>>> if sys.platform == 'win32':
... scripts == [os.path.join(bin, 'run.exe'),
......@@ -749,7 +743,7 @@ to be included in the a generated script:
... extra_paths=[foo])
>>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.4
#!/usr/local/bin/python2.7
<BLANKLINE>
import sys
sys.path[0:0] = [
......@@ -775,7 +769,7 @@ parentheses in the call:
... arguments='1, 2')
>>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.4
#!/usr/local/bin/python2.7
import sys
sys.path[0:0] = [
'/sample-install/demo-0.3-py2.4.egg',
......@@ -798,7 +792,7 @@ You can also pass script initialization code:
... initialization='import os\nos.chdir("foo")')
>>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.4
#!/usr/local/bin/python2.7
import sys
sys.path[0:0] = [
'/sample-install/demo-0.3-py2.4.egg',
......@@ -838,7 +832,7 @@ to pass a common base directory of the scripts and eggs:
... relative_paths=bo)
>>> cat(bo, 'bin', 'run')
#!/usr/local/bin/python2.4
#!/usr/local/bin/python2.7
<BLANKLINE>
import os
<BLANKLINE>
......@@ -870,7 +864,7 @@ Of course, running the script works:
We specified an interpreter and its paths are adjusted too:
>>> cat(bo, 'bin', 'py')
#!/usr/local/bin/python2.4
#!/usr/local/bin/python2.7
<BLANKLINE>
import os
<BLANKLINE>
......@@ -950,10 +944,6 @@ index
we'll just point to an empty directory on our link server. This
will make our examples run a little bit faster.
executable
A path to a Python executable. Distributions will be installed
using this executable and will be for the matching Python version.
path
A list of additional directories to search for locally-installed
distributions.
......@@ -1122,10 +1112,6 @@ build_ext
A dictionary of options to be passed to the distutils build_ext
command when building extensions.
executable
A path to a Python executable. Distributions will be installed
using this executable and will be for the matching Python version.
We have a local directory containing the extdemo source:
>>> ls(extdemo)
......
......@@ -108,7 +108,7 @@ def system(command, input=''):
def get(url):
return urllib2.urlopen(url).read()
def _runsetup(setup, executable, *args):
def _runsetup(setup, *args):
if os.path.isdir(setup):
setup = os.path.join(setup, 'setup.py')
args = list(args)
......@@ -117,7 +117,7 @@ def _runsetup(setup, executable, *args):
try:
os.chdir(os.path.dirname(setup))
zc.buildout.easy_install.call_subprocess(
[executable, setup] + args,
[sys.executable, setup] + args,
env=dict(os.environ, PYTHONPATH=setuptools_location))
if os.path.exists('build'):
rmtree('build')
......@@ -125,64 +125,15 @@ def _runsetup(setup, executable, *args):
os.chdir(here)
def sdist(setup, dest):
_runsetup(setup, sys.executable, 'sdist', '-d', dest, '--formats=zip')
def bdist_egg(setup, executable, dest):
_runsetup(setup, executable, 'bdist_egg', '-d', dest)
def find_python(version):
e = os.environ.get('PYTHON%s' % version)
if e is not None:
return e
if is_win32:
e = '\Python%s%s\python.exe' % tuple(version.split('.'))
if os.path.exists(e):
return e
_runsetup(setup, 'sdist', '-d', dest, '--formats=zip')
def bdist_egg(setup, executable, dest=None):
# Backward compat:
if dest is None:
dest = executable
else:
cmd = 'python%s -c "import sys; print sys.executable"' % version
p = subprocess.Popen(cmd,
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
close_fds=MUST_CLOSE_FDS)
i, o = (p.stdin, p.stdout)
i.close()
e = o.read().strip()
o.close()
if os.path.exists(e):
return e
cmd = 'python -c "import sys; print \'%s.%s\' % sys.version_info[:2]"'
p = subprocess.Popen(cmd,
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
close_fds=MUST_CLOSE_FDS)
i, o = (p.stdin, p.stdout)
i.close()
e = o.read().strip()
o.close()
if e == version:
cmd = 'python -c "import sys; print sys.executable"'
p = subprocess.Popen(cmd,
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
close_fds=MUST_CLOSE_FDS)
i, o = (p.stdin, p.stdout)
i.close()
e = o.read().strip()
o.close()
if os.path.exists(e):
return e
raise ValueError(
"Couldn't figure out the executable for Python %(version)s.\n"
"Set the environment variable PYTHON%(version)s to the location\n"
"of the Python %(version)s executable before running the tests."
% {'version': version})
assert executable == sys.executable, (executable, sys.executable)
_runsetup(setup, 'bdist_egg', '-d', dest)
def wait_until(label, func, *args, **kw):
if 'timeout' in kw:
......
......@@ -109,26 +109,12 @@ number of names to the test namespace:
setup argument is a directory, the thge setup.py file in that
directory is used.
``bdist_egg(setup, executable, dest)``
Create an egg by running the given setup file with the given
Python executable and placing the result in the given destination
``bdist_egg(setup, dest)``
Create an egg by running the given setup file
and placing the result in the given destination
directory. If the setup argument is a directory, then the
setup.py file in that directory is used.
``find_python(version)``
Find a Python executable for the given version, where version is a
string like "2.4".
This function uses the following strategy to find a Python of the
given version:
- Look for an environment variable of the form PYTHON%(version)s.
- On windows, look for \Pythonm%(version)s\python
- on Unix, try running python%(version)s or just python to get the
executable
``zc.buildout.testing.buildoutTearDown(test)``
----------------------------------------------
......
......@@ -22,7 +22,6 @@ import tempfile
import unittest
import zc.buildout.easy_install
import zc.buildout.testing
import zc.buildout.testselectingpython
import zipfile
os_path_sep = os.path.sep
......@@ -499,55 +498,6 @@ Then try to install it again:
"""
def make_sure__get_version_works_with_2_digit_python_versions():
"""
This is a test of an internal function used by higher-level machinery.
We'll start by creating a faux 'python' that executable that prints a
2-digit version. This is a bit of a pain to do portably. :(
>>> mkdir('demo')
>>> write('demo', 'setup.py',
... '''
... from setuptools import setup
... setup(name='demo',
... entry_points = {'console_scripts': ['demo = demo:main']},
... )
... ''')
>>> write('demo', 'demo.py',
... '''
... def main():
... print 'Python 2.5'
... ''')
>>> write('buildout.cfg',
... '''
... [buildout]
... develop = demo
... parts =
... ''')
>>> print system(join('bin', 'buildout')),
Develop: '/sample-buildout/demo'
>>> import zc.buildout.easy_install
>>> ws = zc.buildout.easy_install.working_set(
... ['demo'], sys.executable, ['develop-eggs'])
>>> bool(zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, 'bin'))
True
>>> print system(join('bin', 'demo')),
Python 2.5
Now, finally, let's test _get_version:
>>> zc.buildout.easy_install._get_version(join('bin', 'demo'))
'2.5'
"""
def create_sections_on_command_line():
"""
>>> write('buildout.cfg',
......@@ -2655,6 +2605,7 @@ def increment_on_command_line():
######################################################################
def create_sample_eggs(test, executable=sys.executable):
assert executable == sys.executable, (executable, sys.executable)
write = test.globs['write']
dest = test.globs['sample_eggs']
tmp = tempfile.mkdtemp()
......@@ -2680,7 +2631,7 @@ def create_sample_eggs(test, executable=sys.executable):
"setup(name='other', zip_safe=False, version='1.0', "
"py_modules=['eggrecipedemoneeded'])\n"
)
zc.buildout.testing.bdist_egg(tmp, executable, dest)
zc.buildout.testing.bdist_egg(tmp, sys.executable, dest)
os.remove(os.path.join(tmp, 'eggrecipedemoneeded.py'))
......@@ -2701,7 +2652,7 @@ def create_sample_eggs(test, executable=sys.executable):
"['demo = eggrecipedemo:main']},"
" zip_safe=True, version='0.%s%s')\n" % (i, c1)
)
zc.buildout.testing.bdist_egg(tmp, executable, dest)
zc.buildout.testing.bdist_egg(tmp, dest)
write(tmp, 'eggrecipebigdemo.py', 'import eggrecipedemo')
write(
......@@ -2712,7 +2663,7 @@ def create_sample_eggs(test, executable=sys.executable):
" py_modules=['eggrecipebigdemo'], "
" zip_safe=True, version='0.1')\n"
)
zc.buildout.testing.bdist_egg(tmp, executable, dest)
zc.buildout.testing.bdist_egg(tmp, sys.executable, dest)
finally:
shutil.rmtree(tmp)
......@@ -2858,7 +2809,7 @@ def bootstrapSetup(test):
normalize_bang = (
re.compile(re.escape('#!'+
zc.buildout.easy_install._safe_arg(sys.executable))),
'#!/usr/local/bin/python2.4',
'#!/usr/local/bin/python2.7',
)
def test_suite():
......@@ -2874,8 +2825,6 @@ def test_suite():
zc.buildout.testing.normalize_egg_py,
(re.compile('__buildout_signature__ = recipes-\S+'),
'__buildout_signature__ = recipes-SSSSSSSSSSS'),
(re.compile('executable = [\S ]+python\S*', re.I),
'executable = python'),
(re.compile('[-d] setuptools-\S+[.]egg'), 'setuptools.egg'),
(re.compile('zc.buildout(-\S+)?[.]egg(-link)?'),
'zc.buildout.egg'),
......@@ -2989,7 +2938,6 @@ def test_suite():
(re.compile(r'^[*]...'), '...'),
]),
),
zc.buildout.testselectingpython.test_suite(),
zc.buildout.rmtree.test_suite(),
doctest.DocFileSuite(
'windows.txt',
......
##############################################################################
#
# Copyright (c) 2006 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import os, re, sys, unittest
from zope.testing import doctest, renormalizing
import zc.buildout.tests
import zc.buildout.testing
if sys.version_info[:2] == (2, 4):
other_version = "2.5"
else:
other_version = "2.4"
__test__ = dict(
test_selecting_python_via_easy_install=
"""\
We can specify a specific Python executable.
>>> dest = tmpdir('sample-install')
>>> ws = zc.buildout.easy_install.install(
... ['demo'], dest, links=[link_server],
... index='http://www.python.org/pypi/',
... always_unzip=True, executable=other_executable)
>>> ls(dest)
d demo-0.3-py%(other_version)s.egg
d demoneeded-1.1-py%(other_version)s.egg
""" % dict(other_version=other_version)
)
def multi_python(test):
other_executable = zc.buildout.testing.find_python(other_version)
sample_eggs = test.globs['tmpdir']('sample_eggs')
os.mkdir(os.path.join(sample_eggs, 'index'))
test.globs['sample_eggs'] = sample_eggs
zc.buildout.tests.create_sample_eggs(test, executable=other_executable)
test.globs['other_executable'] = other_executable
def setup(test):
zc.buildout.testing.buildoutSetUp(test)
multi_python(test)
zc.buildout.tests.add_source_dist(test)
test.globs['link_server'] = test.globs['start_server'](
test.globs['sample_eggs'])
def test_suite():
return doctest.DocTestSuite(
setUp=setup,
tearDown=zc.buildout.testing.buildoutTearDown,
checker=renormalizing.RENormalizing([
(re.compile('setuptools-\S+-py%s.egg' % other_version),
'setuptools-V-py%s.egg' % other_version),
]),
)
......@@ -89,7 +89,7 @@ Our buildout script has been updated to use the new eggs (HACK: only for
setuptools):
>>> cat(sample_buildout, 'bin', 'buildout')
#!/usr/local/bin/python2.4
#!/usr/local/bin/python2.7
<BLANKLINE>
import sys
sys.path[0:0] = [
......
......@@ -47,7 +47,6 @@ test: we only want to test that ``_get_dist()`` isn't getting called:
... dest=dest,
... links=[link_server],
... index=link_server+'index/',
... executable=sys.executable,
... always_unzip=True)
>>> installer._get_dist = mock_get_dist
>>> installer._call_easy_install('setuptools', None, dest, dist)
......
......@@ -23,12 +23,6 @@ index
we'll just point to an empty directory on our link server. This
will make our examples run a little bit faster.
python
The name of a section to get the Python executable from.
If not specified, then the buildout python option is used. The
Python executable is found in the executable option of the named
section.
We have a link server that has a number of distributions:
>>> print get(link_server),
......@@ -373,7 +367,7 @@ extra-paths option:
Let's look at the script that was generated:
>>> cat(sample_buildout, 'bin', 'foo') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.4
#!/usr/local/bin/python2.7
<BLANKLINE>
import sys
sys.path[0:0] = [
......@@ -420,7 +414,7 @@ breaking scripts.
Let's look at the script that was generated:
>>> cat(sample_buildout, 'bin', 'foo') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.4
#!/usr/local/bin/python2.7
<BLANKLINE>
import os
<BLANKLINE>
......@@ -467,7 +461,7 @@ each individual script section:
Generated script '/sample-buildout/bin/foo'.
>>> cat(sample_buildout, 'bin', 'foo') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.4
#!/usr/local/bin/python2.7
<BLANKLINE>
import os
<BLANKLINE>
......@@ -520,7 +514,7 @@ to be included in generated scripts:
Generated script '/sample-buildout/bin/foo'.
>>> cat(sample_buildout, 'bin', 'foo') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.4
#!/usr/local/bin/python2.7
<BLANKLINE>
import sys
sys.path[0:0] = [
......@@ -578,7 +572,7 @@ declare entry points using the entry-points option:
- other
>>> cat(sample_buildout, 'bin', 'other')
#!/usr/local/bin/python2.4
#!/usr/local/bin/python2.7
<BLANKLINE>
import sys
sys.path[0:0] = [
......
......@@ -6,7 +6,7 @@ and generate scripts based on the resulting working sets. The egg
recipe provides an API that other recipes can use.
A recipe can reuse the egg recipe, supporting the eggs, find-links,
index, extra-paths, and python options. This is done by creating an
index, and extra-paths options. This is done by creating an
egg recipe instance in a recipes's contructor. In the recipe's
install script, the egg-recipe instance's working_set method is used
to collect the requested eggs and working set.
......@@ -112,7 +112,6 @@ computed by the egg recipe by looking at .installed.cfg:
develop-eggs-directory = /sample-buildout/develop-eggs
eggs = demo<0.3
eggs-directory = /sample-buildout/eggs
executable = /usr/local/bin/python2.3
extras = other
find-links = http://localhost:27071/
index = http://localhost:27071/index
......
......@@ -16,8 +16,12 @@
$Id$
"""
import logging, os, re, zipfile
import logging
import os
import re
import sys
import zc.buildout.easy_install
import zipfile
logger = logging.getLogger(__name__)
......@@ -29,9 +33,6 @@ class Base:
options['_d'] = buildout['buildout']['develop-eggs-directory']
python = options.get('python', buildout['buildout']['python'])
options['executable'] = buildout[python]['executable']
self.build_ext = build_ext(buildout, options)
def update(self):
......@@ -92,8 +93,8 @@ class Custom(Base):
try:
return zc.buildout.easy_install.build(
distribution, options['_d'], self.build_ext,
self.links, self.index, options['executable'], [options['_e']],
newest=self.newest,
self.links, self.index, sys.executable,
[options['_e']], newest=self.newest,
)
finally:
self._restore_environment()
......@@ -130,9 +131,7 @@ class Develop(Base):
def install(self):
options = self.options
return zc.buildout.easy_install.develop(
options['setup'], options['_d'], self.build_ext,
options['executable'],
)
options['setup'], options['_d'], self.build_ext)
def build_ext(buildout, options):
......
......@@ -50,7 +50,7 @@ compiler
swig
The path to the swig executable
swig-cpp
swig-cpp
Make SWIG create C++ files (default is C)
swig-opts
......@@ -73,15 +73,9 @@ index
alternate index with this option. If you use the links option and
if the links point to the needed distributions, then the index can
be anything and will be largely ignored. In the examples, here,
we'll just point to an empty directory on our link server. This
we'll just point to an empty directory on our link server. This
will make our examples run a little bit faster.
python
The name of a section to get the Python executable from.
If not specified, then the buildout python option is used. The
Python executable is found in the executable option of the named
section.
environment
The name of a section with additional environment variables. The
environment variables are set before the egg is built.
......@@ -188,7 +182,7 @@ Let's define a script that uses out ext demo:
...
... [demo]
... recipe = zc.recipe.egg
... eggs = demo
... eggs = demo
... extdemo
... entry-points = demo=demo:main
... """ % dict(server=link_server))
......@@ -270,7 +264,7 @@ We can specify a specific version using the egg option:
...
... [demo]
... recipe = zc.recipe.egg
... eggs = demo
... eggs = demo
... extdemo ==1.4
... entry-points = demo=demo:main
... """ % dict(server=link_server))
......@@ -440,7 +434,7 @@ Create a clean buildout.cfg w/o the checkenv recipe, and delete the recipe:
Uninstalling extdemo.
Installing extdemo.
zip_safe flag not set; analyzing archive contents...
>>> rmdir(sample_buildout, 'recipes')
......@@ -496,18 +490,12 @@ compiler
swig
The path to the swig executable
swig-cpp
swig-cpp
Make SWIG create C++ files (default is C)
swig-opts
List of SWIG command line options
python
The name of a section to get the Python executable from.
If not specified, then the buildout python option is used. The
Python executable is found in the executable option of the named
section.
To illustrate this, we'll use a directory containing the extdemo
example from the earlier section:
......@@ -532,7 +520,7 @@ example from the earlier section:
...
... [demo]
... recipe = zc.recipe.egg
... eggs = demo
... eggs = demo
... extdemo
... entry-points = demo=demo:main
... """ % dict(extdemo=extdemo))
......
......@@ -12,12 +12,14 @@
#
##############################################################################
"""Install packages as eggs
$Id$
"""
import logging, os, re, zipfile
import logging
import os
import re
import sys
import zc.buildout.easy_install
import zipfile
class Eggs(object):
......@@ -52,9 +54,6 @@ class Eggs(object):
assert options.get('unzip') in ('true', 'false', None)
python = options.get('python', buildout['buildout']['python'])
options['executable'] = buildout[python]['executable']
def working_set(self, extra=()):
"""Separate method to just get the working set
......@@ -71,7 +70,7 @@ class Eggs(object):
if self.buildout['buildout'].get('offline') == 'true':
ws = zc.buildout.easy_install.working_set(
distributions, options['executable'],
distributions,
[options['develop-eggs-directory'], options['eggs-directory']]
)
else:
......@@ -83,7 +82,6 @@ class Eggs(object):
distributions, options['eggs-directory'],
links=self.links,
index=self.index,
executable=options['executable'],
path=[options['develop-eggs-directory']],
newest=self.buildout['buildout'].get('newest') == 'true',
allow_hosts=self.allow_hosts,
......@@ -159,8 +157,7 @@ class Scripts(Eggs):
reqs.append(name)
return zc.buildout.easy_install.scripts(
reqs, ws, options['executable'],
options['bin-directory'],
reqs, ws, sys.executable, options['bin-directory'],
scripts=scripts,
extra_paths=self.extra_paths,
interpreter=options.get('interpreter'),
......
Controlling which Python to use
-------------------------------
The following assumes that you have Python 2.4 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="bigdemo-0.1-py2.4.egg">bigdemo-0.1-py2.4.egg</a><br>
<a href="demo-0.1-py2.4.egg">demo-0.1-py2.4.egg</a><br>
<a href="demo-0.2-py2.4.egg">demo-0.2-py2.4.egg</a><br>
<a href="demo-0.3-py2.4.egg">demo-0.3-py2.4.egg</a><br>
<a href="demo-0.4c1-py2.4.egg">demo-0.4c1-py2.4.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="demoneeded-1.2c1.zip">demoneeded-1.2c1.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.4.egg">other-1.0-py2.4.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.4.
>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... parts = demo
... eggs-directory = eggs
... index = http://www.python.org/pypi/
...
... [python2.4]
... executable = %(python23)s
...
... [demo]
... recipe = zc.recipe.egg
... eggs = demo <0.3
... find-links = %(server)s
... python = python2.4
... interpreter = py-demo
... """ % dict(server=link_server, python23=other_executable))
Now, if we run the buildout:
>>> import os
>>> os.chdir(sample_buildout)
>>> buildout = os.path.join(sample_buildout, 'bin', 'buildout')
>>> print system(buildout),
Installing demo.
Getting distribution for 'demo<0.3'.
Got demo 0.2.
Getting distribution for 'demoneeded'.
Getting distribution for 'setuptools'.
Got setuptools 0.6.
Got demoneeded 1.2c1.
Generated script '/sample-buildout/bin/demo'.
Generated interpreter '/sample-buildout/bin/py-demo'.
we'll get the Python 2.4 eggs for demo and demoneeded:
>>> ls(sample_buildout, 'eggs')
- demo-0.2-py2.4.egg
- demoneeded-1.2c1-py2.4.egg
d setuptools-0.6-py2.4.egg
d setuptools-0.6-py2.5.egg
- zc.buildout-1.0-py2.5.egg
And the generated scripts invoke Python 2.4:
>>> 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))
>>> shebang = f.readline().strip()
>>> if shebang[:3] == '#!"' and shebang[-1] == '"':
... shebang = '#!'+shebang[3:-1]
>>> shebang == '#!' + other_executable
True
>>> print f.read(), # doctest: +NORMALIZE_WHITESPACE
<BLANKLINE>
import sys
sys.path[0:0] = [
'/sample-buildout/eggs/demo-0.2-py2.4.egg',
'/sample-buildout/eggs/demoneeded-1.2c1-py2.4.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'))
>>> shebang = f.readline().strip()
>>> if shebang[:3] == '#!"' and shebang[-1] == '"':
... shebang = '#!'+shebang[3:-1]
>>> shebang == '#!' + other_executable
True
>>> print f.read(), # doctest: +NORMALIZE_WHITESPACE
<BLANKLINE>
import sys
<BLANKLINE>
sys.path[0:0] = [
'/sample-buildout/eggs/demo-0.2-py2.4.egg',
'/sample-buildout/eggs/demoneeded-1.2c1-py2.4.egg',
]
<BLANKLINE>
_interactive = True
if len(sys.argv) > 1:
_options, _args = __import__("getopt").getopt(sys.argv[1:], 'ic:m:')
_interactive = False
for (_opt, _val) in _options:
if _opt == '-i':
_interactive = True
elif _opt == '-c':
exec _val
elif _opt == '-m':
sys.argv[1:] = _args
_args = []
__import__("runpy").run_module(
_val, {}, "__main__", alter_sys=True)
<BLANKLINE>
if _args:
sys.argv[:] = _args
__file__ = _args[0]
del _options, _args
execfile(__file__)
<BLANKLINE>
if _interactive:
del _interactive
__import__("code").interact(banner="", local=globals())
>>> f.close()
......@@ -14,7 +14,6 @@
import os, re, shutil, sys
import zc.buildout.tests
import zc.buildout.testselectingpython
import zc.buildout.testing
import unittest
......@@ -33,10 +32,6 @@ def setUp(test):
zc.buildout.tests.easy_install_SetUp(test)
zc.buildout.testing.install_develop('zc.recipe.egg', test)
def setUpSelecting(test):
zc.buildout.testselectingpython.setup(test)
zc.buildout.testing.install_develop('zc.recipe.egg', test)
def test_suite():
suite = unittest.TestSuite((
doctest.DocFileSuite(
......@@ -68,8 +63,6 @@ def test_suite():
'zc.buildout-\S+\s*'
),
'__buildout_signature__ = sample- zc.recipe.egg-'),
(re.compile('executable = [\S ]+python\S*', re.I),
'executable = python'),
(re.compile('find-links = http://localhost:\d+/'),
'find-links = http://localhost:8080/'),
(re.compile('index = http://localhost:\d+/index'),
......@@ -89,33 +82,7 @@ def test_suite():
(re.compile('extdemo[.]pyd'), 'extdemo.so')
]),
),
))
if sys.version_info[:2] == (2, 5):
# Only run selecting python tests if not 2.4, since
# 2.4 is the alternate python used in the tests.
suite.addTest(
doctest.DocFileSuite(
'selecting-python.txt',
setUp=setUpSelecting,
tearDown=zc.buildout.testing.buildoutTearDown,
checker=renormalizing.RENormalizing([
zc.buildout.testing.normalize_path,
zc.buildout.testing.normalize_endings,
zc.buildout.testing.normalize_script,
(re.compile('Got setuptools \S+'), 'Got setuptools V'),
(re.compile('([d-] )?setuptools-\S+-py'),
'setuptools-V-py'),
(re.compile('-py2[.][0-35-9][.]'), 'py2.5.'),
(re.compile('zc.buildout-\S+[.]egg'),
'zc.buildout.egg'),
(re.compile('zc.buildout[.]egg-link'),
'zc.buildout.egg'),
]),
),
)
return suite
if __name__ == '__main__':
......
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