Commit ddd787ae authored by Martin v. Löwis's avatar Martin v. Löwis

Merge upstream changes.

--HG--
branch : distribute
extra : rebase_source : d68cc866146d65e1951fe88f526f94a64f17b1da
parents 1a8b650f 3c6ebb2a
......@@ -6,6 +6,12 @@ CHANGES
0.6.2
-----
setuptools
==========
* Fixed invalid usage of requirement.parse, that broke develop -d.
closed http://bugs.python.org/setuptools/issue44.
-----
0.6.1
......@@ -18,7 +24,7 @@ setuptools
This closes http://bitbucket.org/tarek/distribute/issue/16 and
http://bitbucket.org/tarek/distribute/issue/18.
* zip_ok is now True by default. This closes
* zip_ok is now False by default. This closes
http://bugs.python.org/setuptools/issue33.
* Fixed invalid URL error catching. http://bugs.python.org/setuptools/issue20.
......
......@@ -23,17 +23,117 @@ import os
import time
import fnmatch
from distutils import log
import subprocess
is_jython = sys.platform.startswith('java')
if is_jython:
import subprocess
IS_JYTHON = sys.platform.startswith('java')
DEFAULT_VERSION = "0.6.2"
DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/"
def quote(c):
if sys.platform == 'win32':
if ' ' in c:
return '"%s"' % c
return c
DEFAULT_VERSION = "0.6.1"
DEFAULT_URL = "http://pypi.python.org/packages/source/d/distribute/"
def python_cmd(cmd):
python = quote(sys.executable)
cmd = quote(cmd)
if IS_JYTHON:
return subprocess.Popen([python, cmd]).wait() == 0
args = [os.P_WAIT, python, python] + cmd.split() + [os.environ]
return os.spawnle(*args) == 0
def _install(tarball):
# extracting the tarball
tmpdir = tempfile.mkdtemp()
log.warn('Extracting in %s' % tmpdir)
old_wd = os.getcwd()
try:
os.chdir(tmpdir)
tar = tarfile.open(tarball)
extractall(tar)
tar.close()
# going in the directory
subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
os.chdir(subdir)
log.warn('Now working in %s' % subdir)
# installing
log.warn('Installing Distribute')
assert python_cmd('setup.py install')
finally:
os.chdir(old_wd)
def _build_egg(tarball, to_dir=os.curdir):
# extracting the tarball
tmpdir = tempfile.mkdtemp()
log.warn('Extracting in %s' % tmpdir)
old_wd = os.getcwd()
try:
os.chdir(tmpdir)
tar = tarfile.open(tarball)
extractall(tar)
tar.close()
# going in the directory
subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
os.chdir(subdir)
log.warn('Now working in %s' % subdir)
# building an egg
log.warn('Building a Distribute egg in %s' % to_dir)
python_cmd('setup.py -q bdist_egg --dist-dir %s' % to_dir)
# returning the result
for file in os.listdir(to_dir):
if fnmatch.fnmatch(file, 'distribute-%s*.egg' % DEFAULT_VERSION):
return os.path.join(to_dir, file)
raise IOError('Could not build the egg.')
finally:
os.chdir(old_wd)
def _do_download(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
to_dir=os.curdir, download_delay=15):
tarball = download_setuptools(version, download_base,
to_dir, download_delay)
egg = _build_egg(tarball, to_dir)
sys.path.insert(0, egg)
import setuptools
setuptools.bootstrap_install_from = egg
def use_setuptools(
version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
download_delay=15
):
was_imported = 'pkg_resources' in sys.modules or 'setuptools' in sys.modules
try:
import pkg_resources
if not hasattr(pkg_resources, '_distribute'):
raise ImportError
except ImportError:
return _do_download(version, download_base, to_dir, download_delay)
try:
pkg_resources.require("distribute>="+version); return
except pkg_resources.VersionConflict, e:
if was_imported:
print >>sys.stderr, (
"The required version of distribute (>=%s) is not available, and\n"
"can't be installed while this script is running. Please install\n"
" a more recent version first, using 'easy_install -U distribute'."
"\n\n(Currently using %r)"
) % (version, e.args[0])
sys.exit(2)
else:
del pkg_resources, sys.modules['pkg_resources'] # reload ok
return _do_download(version, download_base, to_dir, download_delay)
except pkg_resources.DistributionNotFound:
return _do_download(version, download_base, to_dir, download_delay)
def download_setuptools(
version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir,
delay=15,
):
"""Download distribute from a specified location and return its filename
......@@ -256,7 +356,7 @@ def _relaunch():
log.warn('Relaunching...')
# we have to relaunch the process
args = [sys.executable] + sys.argv
if is_jython:
if IS_JYTHON:
sys.exit(subprocess.call(args))
else:
sys.exit(os.spawnv(os.P_WAIT, sys.executable, args))
......@@ -304,27 +404,6 @@ def extractall(self, path=".", members=None):
else:
self._dbg(1, "tarfile: %s" % e)
def _install(tarball):
# extracting the tarball
tmpdir = tempfile.mkdtemp()
log.warn('Extracting in %s' % tmpdir)
old_wd = os.getcwd()
try:
os.chdir(tmpdir)
tar = tarfile.open(tarball)
extractall(tar)
tar.close()
# going in the directory
subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
os.chdir(subdir)
log.warn('Now working in %s' % subdir)
# installing distribute
os.system('%s setup.py install' % sys.executable)
finally:
os.chdir(old_wd)
def main(argv, version=DEFAULT_VERSION):
"""Install or upgrade setuptools and EasyInstall"""
tarball = download_setuptools()
......
......@@ -44,12 +44,13 @@ scripts = []
# if we are installing Distribute using "python setup.py install"
# we need to get setuptools out of the way
def _easy_install_marker():
return (len(sys.argv) == 5 and sys.argv[2] == 'bdist_egg' and
sys.argv[3] == '--dist-dir' and 'egg-dist-tmp-' in sys.argv[-1])
def _being_installed():
# easy_install marker
if (len(sys.argv) == 5 and sys.argv[2] == 'bdist_egg' and
sys.argv[3] == '--dist-dir'):
return True
return 'install' in sys.argv[1:]
return 'install' in sys.argv[1:] or _easy_install_marker()
if _being_installed():
from distribute_setup import before_install
......
......@@ -1097,7 +1097,7 @@ Please make the appropriate changes for your system and try again.""" % (
return # already did it, or don't need to
sitepy = os.path.join(self.install_dir, "site.py")
source = resource_string(Requirement.parse("setuptools"), "site.py")
source = resource_string(Requirement.parse("distribute"), "site.py")
current = ""
if os.path.exists(sitepy):
......
"""Easy install Tests
"""
import os, shutil, tempfile, unittest
from setuptools.command.easy_install import easy_install
from setuptools.dist import Distribution
class TestEasyInstallTest(unittest.TestCase):
def test_install_site_py(self):
dist = Distribution()
cmd = easy_install(dist)
cmd.sitepy_installed = False
cmd.install_dir = tempfile.mkdtemp()
try:
cmd.install_site_py()
sitepy = os.path.join(cmd.install_dir, 'site.py')
self.assert_(os.path.exists(sitepy))
finally:
shutil.rmtree(cmd.install_dir)
import sys
import os
import tempfile
import unittest
import shutil
import copy
CURDIR = os.path.abspath(os.path.dirname(__file__))
TOPDIR = os.path.split(CURDIR)[0]
sys.path.insert(0, TOPDIR)
from distribute_setup import (use_setuptools, _build_egg, python_cmd,
_do_download, _install)
import distribute_setup
class TestSetup(unittest.TestCase):
def urlopen(self, url):
return open(self.tarball)
def setUp(self):
self.old_sys_path = copy.copy(sys.path)
self.cwd = os.getcwd()
self.tmpdir = tempfile.mkdtemp()
os.chdir(TOPDIR)
python_cmd("setup.py -q egg_info -RDb '' sdist --dist-dir %s" % \
self.tmpdir)
tarball = os.listdir(self.tmpdir)[0]
self.tarball = os.path.join(self.tmpdir, tarball)
import urllib2
urllib2.urlopen = self.urlopen
def tearDown(self):
shutil.rmtree(self.tmpdir)
os.chdir(self.cwd)
sys.path = copy.copy(self.old_sys_path)
def test_build_egg(self):
# making it an egg
egg = _build_egg(self.tarball, self.tmpdir)
# now trying to import it
sys.path[0] = egg
import setuptools
self.assert_(setuptools.__file__.startswith(egg))
def test_do_download(self):
tmpdir = tempfile.mkdtemp()
_do_download(to_dir=tmpdir)
import setuptools
self.assert_(setuptools.bootstrap_install_from.startswith(tmpdir))
def test_install(self):
def _faked(*args):
return True
distribute_setup.python_cmd = _faked
_install(self.tarball)
if __name__ == '__main__':
unittest.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