Commit f951c678 authored by Jim Fulton's avatar Jim Fulton

Fixed a bug in building from source releases with alternate Python

versions.

Fixed a bug in installing by direct egg download.
parent 17ab02f8
...@@ -20,7 +20,7 @@ installed. ...@@ -20,7 +20,7 @@ installed.
$Id$ $Id$
""" """
import glob, logging, os, re, tempfile, shutil, sys, zipimport import glob, logging, os, re, shutil, sys, tempfile, urlparse, zipimport
import distutils.errors import distutils.errors
import pkg_resources import pkg_resources
import setuptools.command.setopt import setuptools.command.setopt
...@@ -32,20 +32,14 @@ default_index_url = os.environ.get('buildout-testing-index-url') ...@@ -32,20 +32,14 @@ default_index_url = os.environ.get('buildout-testing-index-url')
logger = logging.getLogger('zc.buildout.easy_install') logger = logging.getLogger('zc.buildout.easy_install')
url_match = re.compile('[a-z0-9+.-]+://').match
# Include buildout and setuptools eggs in paths # Include buildout and setuptools eggs in paths
buildout_and_setuptools_path = [ buildout_and_setuptools_path = [
(('.egg' in m.__file__) pkg_resources.working_set.find(
and m.__file__[:m.__file__.rfind('.egg')+4] pkg_resources.Requirement.parse('setuptools')).location,
or os.path.dirname(m.__file__) pkg_resources.working_set.find(
) pkg_resources.Requirement.parse('zc.buildout')).location,
for m in (pkg_resources,)
]
buildout_and_setuptools_path += [
(('.egg' in m.__file__)
and m.__file__[:m.__file__.rfind('.egg')+4]
or os.path.dirname(os.path.dirname(os.path.dirname(m.__file__)))
)
for m in (zc.buildout,)
] ]
_versions = {sys.executable: '%d.%d' % sys.version_info[:2]} _versions = {sys.executable: '%d.%d' % sys.version_info[:2]}
...@@ -175,13 +169,12 @@ _easy_install_cmd = _safe_arg( ...@@ -175,13 +169,12 @@ _easy_install_cmd = _safe_arg(
'from setuptools.command.easy_install import main; main()' 'from setuptools.command.easy_install import main; main()'
) )
def _call_easy_install(spec, dest, def _call_easy_install(spec, env, ws, dest, links, index,
executable=sys.executable, executable, always_unzip):
always_unzip=False,
):
prefix = sys.exec_prefix + os.path.sep
path = os.pathsep.join([p for p in sys.path if not p.startswith(prefix)])
path = _get_dist(pkg_resources.Requirement.parse('setuptools'),
env, ws, dest, links, index, executable, False).location
args = ('-c', _easy_install_cmd, '-mUNxd', _safe_arg(dest)) args = ('-c', _easy_install_cmd, '-mUNxd', _safe_arg(dest))
if always_unzip: if always_unzip:
args += ('-Z', ) args += ('-Z', )
...@@ -204,24 +197,29 @@ def _call_easy_install(spec, dest, ...@@ -204,24 +197,29 @@ def _call_easy_install(spec, dest,
def _get_dist(requirement, env, ws, def _get_dist(requirement, env, ws,
dest, links, index, executable, always_unzip): dest, links, index_url, executable, always_unzip):
# Maybe an existing dist is already the best dist that satisfies the # Maybe an existing dist is already the best dist that satisfies the
# requirement # requirement
dist = _satisfied(requirement, env, dest, executable, index, links) dist = _satisfied(requirement, env, dest, executable, index_url, links)
if dist is None: if dist is None:
if dest is not None: if dest is not None:
logger.info("Getting new distribution for %s", requirement) logger.info("Getting new distribution for %s", requirement)
# Retrieve the dist: # Retrieve the dist:
index = _get_index(executable, index, links) index = _get_index(executable, index_url, links)
dist = index.obtain(requirement) dist = index.obtain(requirement)
if dist is None: if dist is None:
raise zc.buildout.UserError( raise zc.buildout.UserError(
"Couln't find a distribution for %s." "Couldn't find a distribution for %s."
% requirement) % requirement)
if dist.location.endswith('.egg'):
fname = dist.location
if url_match(fname):
fname = urlparse.urlparse(fname)[2]
if fname.endswith('.egg'):
# It's already an egg, just fetch it into the dest # It's already an egg, just fetch it into the dest
tmp = tempfile.mkdtemp('get_dist') tmp = tempfile.mkdtemp('get_dist')
try: try:
...@@ -266,8 +264,9 @@ def _get_dist(requirement, env, ws, ...@@ -266,8 +264,9 @@ def _get_dist(requirement, env, ws,
dist = index.fetch_distribution(requirement, tmp) dist = index.fetch_distribution(requirement, tmp)
# May need a new one. Call easy_install # May need a new one. Call easy_install
_call_easy_install(dist.location, dest, _call_easy_install(
executable, always_unzip) dist.location, env, ws, dest, links, index_url,
executable, always_unzip)
finally: finally:
shutil.rmtree(tmp) shutil.rmtree(tmp)
...@@ -357,6 +356,8 @@ def build(spec, dest, build_ext, ...@@ -357,6 +356,8 @@ def build(spec, dest, build_ext,
executable=sys.executable, executable=sys.executable,
path=None): path=None):
index_url = index
logger.debug('Building %r', spec) logger.debug('Building %r', spec)
path = path and path[:] or [] path = path and path[:] or []
...@@ -373,7 +374,7 @@ def build(spec, dest, build_ext, ...@@ -373,7 +374,7 @@ def build(spec, dest, build_ext,
env = pkg_resources.Environment(path, python=_get_version(executable)) env = pkg_resources.Environment(path, python=_get_version(executable))
requirement = pkg_resources.Requirement.parse(spec) requirement = pkg_resources.Requirement.parse(spec)
dist = _satisfied(requirement, env, dest, executable, index, links) dist = _satisfied(requirement, env, dest, executable, index_url, links)
if dist is not None: if dist is not None:
return dist return dist
...@@ -381,11 +382,11 @@ def build(spec, dest, build_ext, ...@@ -381,11 +382,11 @@ def build(spec, dest, build_ext,
tmp = tempfile.mkdtemp('editable') tmp = tempfile.mkdtemp('editable')
tmp2 = tempfile.mkdtemp('editable') tmp2 = tempfile.mkdtemp('editable')
try: try:
index = _get_index(executable, index, links) index = _get_index(executable, index_url, links)
dist = index.fetch_distribution(requirement, tmp2, False, True) dist = index.fetch_distribution(requirement, tmp2, False, True)
if dist is None: if dist is None:
raise zc.buildout.UserError( raise zc.buildout.UserError(
"Couln't find a source distribution for %s." "Couldn't find a source distribution for %s."
% requirement) % requirement)
setuptools.archive_util.unpack_archive(dist.location, tmp) setuptools.archive_util.unpack_archive(dist.location, tmp)
...@@ -414,7 +415,8 @@ def build(spec, dest, build_ext, ...@@ -414,7 +415,8 @@ def build(spec, dest, build_ext,
setup_cfg, dict(build_ext=build_ext)) setup_cfg, dict(build_ext=build_ext))
# Now run easy_install for real: # Now run easy_install for real:
_call_easy_install(base, dest, executable, True) _call_easy_install(base, env, pkg_resources.WorkingSet(),
dest, links, index_url, executable, True)
finally: finally:
shutil.rmtree(tmp) shutil.rmtree(tmp)
shutil.rmtree(tmp2) shutil.rmtree(tmp2)
......
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