aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--distribute.egg-info/entry_points.txt124
-rwxr-xr-xsetup.py28
-rw-r--r--setuptools/tests/__init__.py67
-rw-r--r--setuptools/tests/server.py56
-rw-r--r--setuptools/tests/test_easy_install.py120
5 files changed, 253 insertions, 142 deletions
diff --git a/distribute.egg-info/entry_points.txt b/distribute.egg-info/entry_points.txt
index 663882d6..29654589 100644
--- a/distribute.egg-info/entry_points.txt
+++ b/distribute.egg-info/entry_points.txt
@@ -1,62 +1,62 @@
-[distutils.commands]
-bdist_rpm = setuptools.command.bdist_rpm:bdist_rpm
-rotate = setuptools.command.rotate:rotate
-develop = setuptools.command.develop:develop
-setopt = setuptools.command.setopt:setopt
-build_py = setuptools.command.build_py:build_py
-saveopts = setuptools.command.saveopts:saveopts
-egg_info = setuptools.command.egg_info:egg_info
-register = setuptools.command.register:register
-upload_docs = setuptools.command.upload_docs:upload_docs
-install_egg_info = setuptools.command.install_egg_info:install_egg_info
-alias = setuptools.command.alias:alias
-easy_install = setuptools.command.easy_install:easy_install
-install_scripts = setuptools.command.install_scripts:install_scripts
-bdist_wininst = setuptools.command.bdist_wininst:bdist_wininst
-bdist_egg = setuptools.command.bdist_egg:bdist_egg
-install = setuptools.command.install:install
-test = setuptools.command.test:test
-install_lib = setuptools.command.install_lib:install_lib
-build_ext = setuptools.command.build_ext:build_ext
-sdist = setuptools.command.sdist:sdist
-
-[egg_info.writers]
-dependency_links.txt = setuptools.command.egg_info:overwrite_arg
-requires.txt = setuptools.command.egg_info:write_requirements
-PKG-INFO = setuptools.command.egg_info:write_pkg_info
-eager_resources.txt = setuptools.command.egg_info:overwrite_arg
-top_level.txt = setuptools.command.egg_info:write_toplevel_names
-namespace_packages.txt = setuptools.command.egg_info:overwrite_arg
-entry_points.txt = setuptools.command.egg_info:write_entries
-depends.txt = setuptools.command.egg_info:warn_depends_obsolete
-
-[console_scripts]
-easy_install = setuptools.command.easy_install:main
-easy_install-2.7 = setuptools.command.easy_install:main
-
-[setuptools.file_finders]
-svn_cvs = setuptools.command.sdist:_default_revctrl
-
-[distutils.setup_keywords]
-dependency_links = setuptools.dist:assert_string_list
-entry_points = setuptools.dist:check_entry_points
-extras_require = setuptools.dist:check_extras
-use_2to3_exclude_fixers = setuptools.dist:assert_string_list
-package_data = setuptools.dist:check_package_data
-install_requires = setuptools.dist:check_requirements
-use_2to3 = setuptools.dist:assert_bool
-use_2to3_fixers = setuptools.dist:assert_string_list
-include_package_data = setuptools.dist:assert_bool
-exclude_package_data = setuptools.dist:check_package_data
-namespace_packages = setuptools.dist:check_nsp
-test_suite = setuptools.dist:check_test_suite
-eager_resources = setuptools.dist:assert_string_list
-zip_safe = setuptools.dist:assert_bool
-test_loader = setuptools.dist:check_importable
-packages = setuptools.dist:check_packages
-convert_2to3_doctests = setuptools.dist:assert_string_list
-tests_require = setuptools.dist:check_requirements
-
-[setuptools.installation]
-eggsecutable = setuptools.command.easy_install:bootstrap
-
+[distutils.commands]
+bdist_rpm = setuptools.command.bdist_rpm:bdist_rpm
+rotate = setuptools.command.rotate:rotate
+develop = setuptools.command.develop:develop
+setopt = setuptools.command.setopt:setopt
+build_py = setuptools.command.build_py:build_py
+saveopts = setuptools.command.saveopts:saveopts
+egg_info = setuptools.command.egg_info:egg_info
+register = setuptools.command.register:register
+upload_docs = setuptools.command.upload_docs:upload_docs
+install_egg_info = setuptools.command.install_egg_info:install_egg_info
+alias = setuptools.command.alias:alias
+easy_install = setuptools.command.easy_install:easy_install
+install_scripts = setuptools.command.install_scripts:install_scripts
+bdist_wininst = setuptools.command.bdist_wininst:bdist_wininst
+bdist_egg = setuptools.command.bdist_egg:bdist_egg
+install = setuptools.command.install:install
+test = setuptools.command.test:test
+install_lib = setuptools.command.install_lib:install_lib
+build_ext = setuptools.command.build_ext:build_ext
+sdist = setuptools.command.sdist:sdist
+
+[egg_info.writers]
+dependency_links.txt = setuptools.command.egg_info:overwrite_arg
+requires.txt = setuptools.command.egg_info:write_requirements
+PKG-INFO = setuptools.command.egg_info:write_pkg_info
+eager_resources.txt = setuptools.command.egg_info:overwrite_arg
+top_level.txt = setuptools.command.egg_info:write_toplevel_names
+namespace_packages.txt = setuptools.command.egg_info:overwrite_arg
+entry_points.txt = setuptools.command.egg_info:write_entries
+depends.txt = setuptools.command.egg_info:warn_depends_obsolete
+
+[console_scripts]
+easy_install = setuptools.command.easy_install:main
+easy_install-2.7 = setuptools.command.easy_install:main
+
+[setuptools.file_finders]
+svn_cvs = setuptools.command.sdist:_default_revctrl
+
+[distutils.setup_keywords]
+dependency_links = setuptools.dist:assert_string_list
+entry_points = setuptools.dist:check_entry_points
+extras_require = setuptools.dist:check_extras
+use_2to3_exclude_fixers = setuptools.dist:assert_string_list
+package_data = setuptools.dist:check_package_data
+install_requires = setuptools.dist:check_requirements
+use_2to3 = setuptools.dist:assert_bool
+use_2to3_fixers = setuptools.dist:assert_string_list
+include_package_data = setuptools.dist:assert_bool
+exclude_package_data = setuptools.dist:check_package_data
+namespace_packages = setuptools.dist:check_nsp
+test_suite = setuptools.dist:check_test_suite
+eager_resources = setuptools.dist:assert_string_list
+zip_safe = setuptools.dist:assert_bool
+test_loader = setuptools.dist:check_importable
+packages = setuptools.dist:check_packages
+convert_2to3_doctests = setuptools.dist:assert_string_list
+tests_require = setuptools.dist:check_requirements
+
+[setuptools.installation]
+eggsecutable = setuptools.command.easy_install:bootstrap
+
diff --git a/setup.py b/setup.py
index f576b520..d6c8ee0d 100755
--- a/setup.py
+++ b/setup.py
@@ -2,6 +2,7 @@
"""Distutils setup file, used to install or test 'setuptools'"""
import sys
import os
+import textwrap
src_root = None
if sys.version_info >= (3,):
@@ -197,23 +198,22 @@ dist = setup(
},
- classifiers = [f.strip() for f in """
- Development Status :: 5 - Production/Stable
- Intended Audience :: Developers
- License :: OSI Approved :: Python Software Foundation License
- License :: OSI Approved :: Zope Public License
- Operating System :: OS Independent
- Programming Language :: Python
- Programming Language :: Python :: 3
- Topic :: Software Development :: Libraries :: Python Modules
- Topic :: System :: Archiving :: Packaging
- Topic :: System :: Systems Administration
- Topic :: Utilities""".splitlines() if f.strip()],
+ classifiers = textwrap.dedent("""
+ Development Status :: 5 - Production/Stable
+ Intended Audience :: Developers
+ License :: OSI Approved :: Python Software Foundation License
+ License :: OSI Approved :: Zope Public License
+ Operating System :: OS Independent
+ Programming Language :: Python
+ Programming Language :: Python :: 3
+ Topic :: Software Development :: Libraries :: Python Modules
+ Topic :: System :: Archiving :: Packaging
+ Topic :: System :: Systems Administration
+ Topic :: Utilities
+ """).strip().splitlines(),
scripts = scripts,
)
if _being_installed():
from distribute_setup import _after_install
_after_install(dist)
-
-
diff --git a/setuptools/tests/__init__.py b/setuptools/tests/__init__.py
index 9af44a88..7a3d6eb5 100644
--- a/setuptools/tests/__init__.py
+++ b/setuptools/tests/__init__.py
@@ -1,19 +1,21 @@
"""Tests for the 'setuptools' package"""
-from unittest import TestSuite, TestCase, makeSuite, defaultTestLoader
-import distutils.core, distutils.cmd
+import sys
+import os
+import doctest
+import distutils.core
+import distutils.cmd
from distutils.errors import DistutilsOptionError, DistutilsPlatformError
from distutils.errors import DistutilsSetupError
-import setuptools, setuptools.dist
-from setuptools import Feature
from distutils.core import Extension
-extract_constant, get_module_constant = None, None
-from setuptools.depends import *
-from distutils.version import StrictVersion, LooseVersion
-from distutils.util import convert_path
-import sys, os.path
+from distutils.version import LooseVersion
+
+import unittest
+
+import setuptools.dist
+from setuptools import Feature
+from setuptools.depends import Require, find_module, get_module_constant, extract_constant
def additional_tests():
- import doctest, unittest
suite = unittest.TestSuite((
doctest.DocFileSuite(
os.path.join('tests', 'api_tests.txt'),
@@ -38,15 +40,13 @@ def makeSetup(**args):
distutils.core_setup_stop_after = None
-
-
-class DependsTests(TestCase):
+class DependsTests(unittest.TestCase):
def testExtractConst(self):
if not extract_constant: return # skip on non-bytecode platforms
def f1():
- global x,y,z
+ global x, y, z
x = "test"
y = z
@@ -62,11 +62,11 @@ class DependsTests(TestCase):
# recognized name, not assigned
self.assertEqual(extract_constant(f1.func_code,'z', -1), None)
-
def testFindModule(self):
self.assertRaises(ImportError, find_module, 'no-such.-thing')
self.assertRaises(ImportError, find_module, 'setuptools.non-existent')
- f,p,i = find_module('setuptools.tests'); f.close()
+ f,p,i = find_module('setuptools.tests')
+ f.close()
def testModuleExtract(self):
if not get_module_constant: return # skip on non-bytecode platforms
@@ -122,7 +122,7 @@ class DependsTests(TestCase):
self.assert_(req.is_current(paths))
-class DistroTests(TestCase):
+class DistroTests(unittest.TestCase):
def setUp(self):
self.e1 = Extension('bar.ext',['bar.c'])
@@ -135,11 +135,9 @@ class DistroTests(TestCase):
package_dir = {},
)
-
def testDistroType(self):
self.assert_(isinstance(self.dist,setuptools.dist.Distribution))
-
def testExcludePackage(self):
self.dist.exclude_package('a')
self.assertEqual(self.dist.packages, ['b','c'])
@@ -157,12 +155,6 @@ class DistroTests(TestCase):
# test removals from unspecified options
makeSetup().exclude_package('x')
-
-
-
-
-
-
def testIncludeExclude(self):
# remove an extension
self.dist.exclude(ext_modules=[self.e1])
@@ -201,9 +193,6 @@ class DistroTests(TestCase):
self.dist.exclude_package('c')
self.assert_(not self.dist.has_contents_for('c'))
-
-
-
def testInvalidIncludeExclude(self):
self.assertRaises(DistutilsSetupError,
self.dist.include, nonexistent_option='x'
@@ -232,20 +221,7 @@ class DistroTests(TestCase):
)
-
-
-
-
-
-
-
-
-
-
-
-
-
-class FeatureTests(TestCase):
+class FeatureTests(unittest.TestCase):
def setUp(self):
self.req = Require('Distutils','1.0.3','distutils')
@@ -327,7 +303,7 @@ class FeatureTests(TestCase):
SystemExit, makeSetup, features = {'x':Feature('x', remove='y')}
)
-class TestCommandTests(TestCase):
+class TestCommandTests(unittest.TestCase):
def testTestIsCommand(self):
test_cmd = makeSetup().get_command_obj('test')
@@ -363,8 +339,3 @@ class TestCommandTests(TestCase):
ts5 = makeSetup().get_command_obj('test')
ts5.ensure_finalized()
self.assertEqual(ts5.test_suite, None)
-
-
-
-
-
diff --git a/setuptools/tests/server.py b/setuptools/tests/server.py
index f4aaaa1c..8a149d36 100644
--- a/setuptools/tests/server.py
+++ b/setuptools/tests/server.py
@@ -2,7 +2,8 @@
"""
import urllib2
import sys
-from threading import Thread
+import threading
+import BaseHTTPServer
from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
@@ -17,32 +18,65 @@ class IndexServer(HTTPServer):
# The index files should be located in setuptools/tests/indexes
s.stop()
"""
- def __init__(self):
- HTTPServer.__init__(self, ('', 0), SimpleHTTPRequestHandler)
+ def __init__(self, server_address=('', 0),
+ RequestHandlerClass=SimpleHTTPRequestHandler,
+ bind_and_activate=True):
+ HTTPServer.__init__(self, server_address, RequestHandlerClass,
+ bind_and_activate)
self._run = True
def serve(self):
- while True:
+ while self._run:
self.handle_request()
- if not self._run: break
def start(self):
- self.thread = Thread(target=self.serve)
+ self.thread = threading.Thread(target=self.serve)
self.thread.start()
def stop(self):
- """self.shutdown is not supported on python < 2.6"""
+ "Stop the server"
+
+ # self.shutdown is not supported on python < 2.6, so just
+ # set _run to false, and make a request, causing it to
+ # terminate.
self._run = False
+ url = 'http://127.0.0.1:%(server_port)s/' % vars(self)
try:
- if sys.version > '2.6':
- urllib2.urlopen('http://127.0.0.1:%s/' % self.server_port,
- None, 5)
+ if sys.version_info >= (2, 6):
+ urllib2.urlopen(url, timeout=5)
else:
- urllib2.urlopen('http://127.0.0.1:%s/' % self.server_port)
+ urllib2.urlopen(url)
except urllib2.URLError:
+ # ignore any errors; all that's important is the request
pass
self.thread.join()
def base_url(self):
port = self.server_port
return 'http://127.0.0.1:%s/setuptools/tests/indexes/' % port
+
+class RequestRecorder(BaseHTTPServer.BaseHTTPRequestHandler):
+ def do_GET(self):
+ requests = vars(self.server).setdefault('requests', [])
+ requests.append(self)
+ self.send_response(200, 'OK')
+
+class MockServer(HTTPServer, threading.Thread):
+ """
+ A simple HTTP Server that records the requests made to it.
+ """
+ def __init__(self, server_address=('', 0),
+ RequestHandlerClass=RequestRecorder,
+ bind_and_activate=True):
+ HTTPServer.__init__(self, server_address, RequestHandlerClass,
+ bind_and_activate)
+ threading.Thread.__init__(self)
+ self.daemon = True
+ self.requests = []
+
+ def run(self):
+ self.serve_forever()
+
+ def url(self):
+ return 'http://localhost:%(server_port)s/' % vars(self)
+ url = property(url)
diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py
index 4150ad10..d89c8ae3 100644
--- a/setuptools/tests/test_easy_install.py
+++ b/setuptools/tests/test_easy_install.py
@@ -1,17 +1,28 @@
"""Easy install Tests
"""
import sys
-import os, shutil, tempfile, unittest
+import os
+import shutil
+import tempfile
+import unittest
import site
-from StringIO import StringIO
+import contextlib
+import textwrap
+import tarfile
+import urlparse
+import StringIO
+import distutils.core
+
from setuptools.command.easy_install import easy_install, get_script_args, main
from setuptools.command.easy_install import PthDistributions
from setuptools.command import easy_install as easy_install_pkg
from setuptools.dist import Distribution
from pkg_resources import Distribution as PRDistribution
+import setuptools.tests.server
try:
- import multiprocessing
+ # import multiprocessing solely for the purpose of testing its existence
+ __import__('multiprocessing')
import logging
_LOG = logging.getLogger('test_easy_install')
logging.basicConfig(level=logging.INFO, stream=sys.stderr)
@@ -92,7 +103,7 @@ class TestEasyInstallTest(unittest.TestCase):
opts = self.command_options
if 'easy_install' in opts:
assert 'find_links' not in opts['easy_install'], msg
- return self._old_parse_command_line
+ return self._old_parse_command_line()
Distribution._old_parse_command_line = Distribution.parse_command_line
Distribution.parse_command_line = _parse_command_line
@@ -104,13 +115,14 @@ class TestEasyInstallTest(unittest.TestCase):
finally:
os.chdir(old_wd)
shutil.rmtree(dir)
+ Distribution.parse_command_line = Distribution._old_parse_command_line
def test_no_find_links(self):
# new option '--no-find-links', that blocks find-links added at
# the project level
dist = Distribution()
cmd = easy_install(dist)
- cmd.check_pth_processing = lambda : True
+ cmd.check_pth_processing = lambda: True
cmd.no_find_links = True
cmd.find_links = ['link1', 'link2']
cmd.install_dir = os.path.join(tempfile.mkdtemp(), 'ok')
@@ -120,7 +132,7 @@ class TestEasyInstallTest(unittest.TestCase):
# let's try without it (default behavior)
cmd = easy_install(dist)
- cmd.check_pth_processing = lambda : True
+ cmd.check_pth_processing = lambda: True
cmd.find_links = ['link1', 'link2']
cmd.install_dir = os.path.join(tempfile.mkdtemp(), 'ok')
cmd.args = ['ok']
@@ -173,7 +185,7 @@ class TestUserInstallTest(unittest.TestCase):
def tearDown(self):
os.chdir(self.old_cwd)
shutil.rmtree(self.dir)
- if sys.version >= "2.6":
+ if sys.version >= "2.6":
shutil.rmtree(site.USER_BASE)
shutil.rmtree(site.USER_SITE)
site.USER_BASE = self.old_base
@@ -250,3 +262,97 @@ class TestUserInstallTest(unittest.TestCase):
else:
del os.environ['PYTHONPATH']
+
+class TestSetupRequires(unittest.TestCase):
+
+ def test_setup_requires_honors_fetch_params(self):
+ """
+ When easy_install installs a source distribution which specifies
+ setup_requires, it should honor the fetch parameters (such as
+ allow-hosts, index-url, and find-links).
+ """
+ # set up a server which will simulate an alternate package index.
+ p_index = setuptools.tests.server.MockServer()
+ p_index.start()
+ p_index_loc = urlparse.urlparse(p_index.url).netloc
+ # create an sdist that has a build-time dependency.
+ with TestSetupRequires.create_sdist() as dist_file:
+ with tempdir_context() as temp_install_dir:
+ with environment_context(PYTHONPATH=temp_install_dir):
+ ei_params = ['--index-url', p_index.url,
+ '--allow-hosts', p_index_loc,
+ '--exclude-scripts', '--install-dir', temp_install_dir,
+ dist_file]
+ with reset_setup_stop_context():
+ with argv_context(['easy_install']):
+ # attempt to install the dist. It should fail because
+ # it doesn't exist.
+ self.assertRaises(SystemExit,
+ easy_install_pkg.main, ei_params)
+ self.assertEqual(len(p_index.requests), 2)
+ self.assertEqual(p_index.requests[0].path, '/does-not-exist/')
+
+ @staticmethod
+ @contextlib.contextmanager
+ def create_sdist():
+ """
+ Return an sdist with a setup_requires dependency (of something that
+ doesn't exist)
+ """
+ with tempdir_context() as d:
+ setup_py = tarfile.TarInfo(name="setup.py")
+ setup_py_bytes = StringIO.StringIO(textwrap.dedent("""
+ import setuptools
+ setuptools.setup(
+ name="distribute-test-fetcher",
+ version="1.0",
+ setup_requires = ['does-not-exist'],
+ )
+ """).lstrip())
+ setup_py.size = len(setup_py_bytes.buf)
+ dist_path = os.path.join(d, 'distribute-test-fetcher-1.0.tar.gz')
+ with tarfile.open(dist_path, 'w:gz') as dist:
+ dist.addfile(setup_py, fileobj=setup_py_bytes)
+ yield dist_path
+
+@contextlib.contextmanager
+def tempdir_context(cd=lambda dir:None):
+ temp_dir = tempfile.mkdtemp()
+ orig_dir = os.getcwd()
+ try:
+ cd(temp_dir)
+ yield temp_dir
+ finally:
+ cd(orig_dir)
+ shutil.rmtree(temp_dir)
+
+@contextlib.contextmanager
+def environment_context(**updates):
+ old_env = os.environ.copy()
+ os.environ.update(updates)
+ try:
+ yield
+ finally:
+ for key in updates:
+ del os.environ[key]
+ os.environ.update(old_env)
+
+@contextlib.contextmanager
+def argv_context(repl):
+ old_argv = sys.argv[:]
+ sys.argv[:] = repl
+ yield
+ sys.argv[:] = old_argv
+
+@contextlib.contextmanager
+def reset_setup_stop_context():
+ """
+ When the distribute tests are run using setup.py test, and then
+ one wants to invoke another setup() command (such as easy_install)
+ within those tests, it's necessary to reset the global variable
+ in distutils.core so that the setup() command will run naturally.
+ """
+ setup_stop_after = distutils.core._setup_stop_after
+ distutils.core._setup_stop_after = None
+ yield
+ distutils.core._setup_stop_after = setup_stop_after