Commits

Jurko Gospodnetić  committed d489a87

specify pytest package requirements using the 'requires' setup() argument

This allows the user to list all of pytest's package requirements using the
standard distutils '--requires' setup.py command-line argument.

Related to issue #516.

  • Participants
  • Parent commits 955e093
  • Branches setup cleanup

Comments (0)

Files changed (1)

 long_description = open('README.rst').read()
 
 
+def requirements():
+    """
+    Generates a list of package requirements for this project.
+
+    Each item is a (package_name, version_spec) tuple where version_spec is a
+    standard package version specifier string used by distutils & setuptools
+    (empty string stands for 'any version').
+
+    """
+    yield 'py', '>=1.4.20'
+    if sys.version_info < (2, 7) or (3,) <= sys.version_info < (3, 2):
+        yield 'argparse', ''
+    if sys.platform == 'win32':
+        yield 'colorama', ''
+
+
+def setup_requires(name, version_spec):
+    """Requirement formatted for the setup() requires parameter."""
+    if version_spec:
+        return '%s(%s)' % (name, version_spec)
+    return name
+
+
+def setup_install_requires(name, version_spec):
+    """Requirement formatted for the setup() install_requires parameter."""
+    return '%s%s' % (name, version_spec)
+
+
 def main():
-    install_requires = ['py>=1.4.20']
-    if sys.version_info < (2, 7) or (3,) <= sys.version_info < (3, 2):
-        install_requires.append('argparse')
-    if sys.platform == "win32":
-        install_requires.append("colorama")
-
     setup(
         name='pytest',
         description='pytest: simple powerful testing with Python',
         classifiers=classifiers,
         cmdclass={'test': PyTest},
         # the following should be enabled for release
-        install_requires=install_requires,
+        requires=[setup_requires(*x) for x in requirements()],
+        install_requires=[setup_install_requires(*x) for x in requirements()],
         packages=['_pytest', '_pytest.assertion'],
         py_modules=['pytest'],
         zip_safe=False,