diff options
-rw-r--r-- | CHANGES.txt | 8 | ||||
-rw-r--r-- | distribute_setup.py | 133 | ||||
-rwxr-xr-x | setup.py | 9 | ||||
-rwxr-xr-x | setuptools/command/easy_install.py | 2 | ||||
-rw-r--r-- | setuptools/tests/test_easy_install.py | 20 | ||||
-rw-r--r-- | tests/test_distribute_setup.py | 61 |
6 files changed, 200 insertions, 33 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index a82857b3..2574300a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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. diff --git a/distribute_setup.py b/distribute_setup.py index a57fd2a8..fb274518 100644 --- a/distribute_setup.py +++ b/distribute_setup.py @@ -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 diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 9e1f8711..195139c7 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -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): diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py new file mode 100644 index 00000000..583c072b --- /dev/null +++ b/setuptools/tests/test_easy_install.py @@ -0,0 +1,20 @@ +"""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) + diff --git a/tests/test_distribute_setup.py b/tests/test_distribute_setup.py new file mode 100644 index 00000000..6c004bd7 --- /dev/null +++ b/tests/test_distribute_setup.py @@ -0,0 +1,61 @@ +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() |