From 46ce42044a48273b4f37b60c40fdd54e1c5fc227 Mon Sep 17 00:00:00 2001 From: Erik Rose Date: Thu, 5 Mar 2015 00:07:46 -0500 Subject: Make setup.py simpler and more idiomatic. * Remove shebang line. setup.py isn't generally executable. * Remove custom `develop` command. It's weird for `develop` to dictate what kind of env you're using. It's weird to change the behavior of `develop` at all. Instead, move the installation of packages needed for testing to tests_require. * Change `test` command to simply run pytests. Tox generally runs setup.py test, not the other way around. * Remove "if __name__" clause. setup.py shouldn't ever be imported. * Add workaround to 2.6/2.7 bug that reports an atexit error at the end of setup.py test runs. To do: massage tox and travis configs to adapt to this. --- setup.py | 129 ++++++++++++++++++++++++++++----------------------------------- 1 file changed, 58 insertions(+), 71 deletions(-) diff --git a/setup.py b/setup.py index c473cda..77fd44c 100755 --- a/setup.py +++ b/setup.py @@ -1,79 +1,66 @@ -#!/usr/bin/env python -# std imports, -import subprocess -import sys -import os +# Prevent spurious errors during `python setup.py test` in 2.6 and 2.7, a la +# http://www.eby-sarna.com/pipermail/peak/2010-May/003357.html: +try: + import multiprocessing +except ImportError: + pass +from os.path import dirname, join +from sys import exit, version_info -# 3rd-party -import setuptools -import setuptools.command.develop -import setuptools.command.test +from setuptools.command.test import test as TestCommand +from setuptools import setup -here = os.path.dirname(__file__) +class PyTest(TestCommand): + def finalize_options(self): + TestCommand.finalize_options(self) + self.test_args = ['blessings/tests'] + self.test_suite = True -class SetupDevelop(setuptools.command.develop.develop): - def run(self): - # ensure a virtualenv is loaded, - assert os.getenv('VIRTUAL_ENV'), 'You should be in a virtualenv' - # ensure tox is installed - subprocess.check_call(('pip', 'install', 'tox', 'ipython')) - # install development egg-link - setuptools.command.develop.develop.run(self) + def run_tests(self): + import pytest + exit(pytest.main(self.test_args)) -class SetupTest(setuptools.command.test.test): - def run(self): - self.spawn(('tox',)) +conditional_requirements = (['ordereddict>=1.1'] + if version_info < (2, 7) else []) -def main(): - extra = { - 'install_requires': [ - 'wcwidth>=0.1.0', - ] - } - if sys.version_info < (2, 7,): - extra['install_requires'].extend(['ordereddict>=1.1']) - - setuptools.setup( - name='blessings', - version='1.9.5', - description="A feature-filled fork of Erik Rose's blessings project", - long_description=open(os.path.join(here, 'README.rst')).read(), - author='Jeff Quast', - author_email='contact@jeffquast.com', - license='MIT', - packages=['blessings', 'blessings.tests'], - url='https://github.com/erikrose/blessings', - include_package_data=True, - test_suite='blessings.tests', - classifiers=[ - 'Intended Audience :: Developers', - 'Natural Language :: English', - 'Development Status :: 5 - Production/Stable', - 'Environment :: Console', - 'Environment :: Console :: Curses', - 'License :: OSI Approved :: MIT License', - 'Operating System :: POSIX', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.6', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.2', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', - 'Topic :: Software Development :: Libraries', - 'Topic :: Software Development :: User Interfaces', - 'Topic :: Terminals' - ], - keywords=['terminal', 'sequences', 'tty', 'curses', 'ncurses', - 'formatting', 'style', 'color', 'console', 'keyboard', - 'ansi', 'xterm'], - cmdclass={'develop': SetupDevelop, - 'test': SetupTest}, - **extra - ) - -if __name__ == '__main__': - main() +setup( + name='blessings', + version='1.9.5', + description='A thin, practical wrapper around terminal coloring, ' + 'styling, positioning, and keyboard input.', + long_description=open(join(dirname(__file__), 'README.rst')).read(), + author='Erik Rose, Jeff Quast', + author_email='erikrose@grinchcentral.com', + license='MIT', + packages=['blessings', 'blessings.tests'], + url='https://github.com/erikrose/blessings', + include_package_data=True, + test_suite='blessings.tests', + classifiers=[ + 'Intended Audience :: Developers', + 'Natural Language :: English', + 'Development Status :: 5 - Production/Stable', + 'Environment :: Console', + 'Environment :: Console :: Curses', + 'License :: OSI Approved :: MIT License', + 'Operating System :: POSIX', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.6', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.2', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + 'Topic :: Software Development :: Libraries', + 'Topic :: Software Development :: User Interfaces', + 'Topic :: Terminals' + ], + keywords=['terminal', 'sequences', 'tty', 'curses', 'ncurses', 'xterm', + 'formatting', 'style', 'color', 'console', 'keyboard', 'ansi'], + cmdclass={'test': PyTest}, + install_requires=['wcwidth>=0.1.0'] + conditional_requirements, + tests_require=['mock', 'pytest'] +) -- cgit v1.2.1