Commit 016ae6c4 authored by PJ Eby's avatar PJ Eby

Added ``tests_require`` keyword to ``setup()``, so that e.g. packages

requiring ``nose`` to run unit tests can make this dependency optional
unless the ``test`` command is run.

--HG--
branch : setuptools
extra : convert_revision : svn%3A6015fed2-1504-0410-9fe1-9d1591cc4771/sandbox/trunk/setuptools%4041483
parent 1c5aaf13
......@@ -40,6 +40,7 @@ setup(
py_modules = ['pkg_resources', 'easy_install', 'site'],
zip_safe = False, # We want 'python -m easy_install' to work, for now :(
entry_points = {
"distutils.commands" : [
"%(cmd)s = setuptools.command.%(cmd)s:%(cmd)s" % locals()
......@@ -49,7 +50,8 @@ setup(
"eager_resources = setuptools.dist:assert_string_list",
"namespace_packages = setuptools.dist:check_nsp",
"extras_require = setuptools.dist:check_extras",
"install_requires = setuptools.dist:check_install_requires",
"install_requires = setuptools.dist:check_requirements",
"tests_require = setuptools.dist:check_requirements",
"entry_points = setuptools.dist:check_entry_points",
"test_suite = setuptools.dist:check_test_suite",
"zip_safe = setuptools.dist:assert_bool",
......@@ -67,6 +69,17 @@ setup(
"console_scripts":
["easy_install = setuptools.command.easy_install:main"],
},
classifiers = [f.strip() for f in """
Development Status :: 3 - Alpha
Intended Audience :: Developers
......@@ -101,19 +114,6 @@ setup(
......
[distutils.setup_keywords]
entry_points = setuptools.dist:check_entry_points
extras_require = setuptools.dist:check_extras
install_requires = setuptools.dist:check_install_requires
install_requires = setuptools.dist:check_requirements
include_package_data = setuptools.dist:assert_bool
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
tests_require = setuptools.dist:check_requirements
[egg_info.writers]
requires.txt = setuptools.command.egg_info:write_requirements
......
......@@ -355,6 +355,17 @@ unless you need the associated ``setuptools`` feature.
specified test suite, e.g. via ``setup.py test``. See the section on the
`test`_ command below for more details.
``tests_require``
If your project's tests need one or more additional packages besides those
needed to install it, you can use this option to specify them. It should
be a string or list of strings specifying what other distributions need to
be present for the package's tests to run. When you run the ``test``
command, ``setuptools`` will attempt to obtain these (even going
so far as to download them using ``EasyInstall``). Note that these
required projects will *not* be installed on the system where the tests
are run, but only downloaded to the project's setup directory if they're
not already installed locally.
``eager_resources``
A list of strings naming resources that should be extracted together, if
any of them is needed, or if any C extensions included in the project are
......@@ -1996,7 +2007,7 @@ Adding ``setup()`` Arguments
----------------------------
Sometimes, your commands may need additional arguments to the ``setup()``
script. You can enable this by defining entry points in the
call. You can enable this by defining entry points in the
``distutils.setup_keywords`` group. For example, if you wanted a ``setup()``
argument called ``bar_baz``, you might add something like this to your
distutils extension project's setup script::
......@@ -2041,8 +2052,9 @@ what values of that argument are valid.
Also note that as with commands, it is not necessary to subclass or monkeypatch
the distutils ``Distribution`` class in order to add your arguments; it is
sufficient to define the entry points in your extension, as long as the setup
script lists your extension in its ``setup_requires`` argument.
sufficient to define the entry points in your extension, as long as any setup
script using your extension lists your project in its ``setup_requires``
argument.
Adding new EGG-INFO Files
......@@ -2157,6 +2169,10 @@ Release Notes/Change History
* Added warning for namespace packages with missing ``declare_namespace()``
* Added ``tests_require`` keyword to ``setup()``, so that e.g. packages
requiring ``nose`` to run unit tests can make this dependency optional
unless the ``test`` command is run.
0.6a8
* Fixed some problems building extensions when Pyrex was installed, especially
with Python 2.4 and/or packages using SWIG.
......
......@@ -47,6 +47,9 @@ class test(Command):
self.reinitialize_command('build_ext', inplace=1)
self.run_command('build_ext')
if self.distribution.tests_require:
self.distribution.fetch_build_eggs(self.distribution.tests_require)
if self.test_suite:
cmd = ' '.join(self.test_args)
if self.dry_run:
......@@ -55,6 +58,7 @@ class test(Command):
self.announce('running "unittest %s"' % cmd)
self.run_tests()
def run_tests(self):
import unittest
old_path = sys.path[:]
......@@ -76,7 +80,3 @@ class test(Command):
......@@ -80,14 +80,14 @@ def assert_bool(dist, attr, value):
def check_install_requires(dist, attr, value):
def check_requirements(dist, attr, value):
"""Verify that install_requires is a valid requirements list"""
try:
list(pkg_resources.parse_requirements(value))
except (TypeError,ValueError):
raise DistutilsSetupError(
"'install_requires' must be a string or list of strings "
"containing valid project/version requirement specifiers"
"%r must be a string or list of strings "
"containing valid project/version requirement specifiers" % (attr,)
)
def check_entry_points(dist, attr, value):
......
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