From 7079d5054a3f0aa92bc09bb9d58437e03d92de7a Mon Sep 17 00:00:00 2001 From: Josh Dorothy Date: Tue, 27 Nov 2012 12:56:13 -0800 Subject: [PATCH] Complying with http://wiki.openstack.org/ProjectTestingInterface Fixes: bug 1083835 Change-Id: I31f525c62cdb3b4c7eb695b6a431e4df6443f673 --- setup.py | 45 ++++++++++++++++++++++++++++++++++++++------- tools/pip-requires | 4 ++++ tools/test-requires | 6 ++++++ tox.ini | 28 ++++++++++++++++++---------- 4 files changed, 66 insertions(+), 17 deletions(-) create mode 100644 tools/pip-requires create mode 100644 tools/test-requires diff --git a/setup.py b/setup.py index 037af388..cbe59c8a 100644 --- a/setup.py +++ b/setup.py @@ -17,15 +17,47 @@ # under the License. import os +import re import setuptools import sys -requirements = ["httplib2", "lxml", "prettytable"] -if sys.version_info < (2, 6): - requirements.append("simplejson") -if sys.version_info < (2, 7): - requirements.append("argparse") +# Get requirements from the first file that exists +def get_reqs_from_files(requirements_files): + for requirements_file in requirements_files: + if os.path.exists(requirements_file): + with open(requirements_file, 'r') as fil: + return fil.read().split('\n') + return [] + + +def parse_requirements(requirements_files=['requirements.txt', + 'tools/pip-requires']): + requirements = [] + for line in get_reqs_from_files(requirements_files): + # For the requirements list, we need to inject only the portion + # after egg= so that distutils knows the package it's looking for + # such as: + # -e git://github.com/openstack/nova/master#egg=nova + if re.match(r'\s*-e\s+', line): + requirements.append(re.sub(r'\s*-e\s+.*#egg=(.*)$', r'\1', + line)) + # such as: + # http://github.com/openstack/nova/zipball/master#egg=nova + elif re.match(r'\s*https?:', line): + requirements.append(re.sub(r'\s*https?:.*#egg=(.*)$', r'\1', + line)) + # -f lines are for index locations, and don't get used here + elif re.match(r'\s*-f\s+', line): + pass + # argparse is part of the standard library starting with 2.7 + # adding it to the requirements list screws distro installs + elif line == 'argparse' and sys.version_info >= (2, 7): + pass + else: + requirements.append(line) + + return requirements def read_file(file_name): @@ -41,8 +73,7 @@ setuptools.setup( license="Apache License, Version 2.0", url="https://github.com/openstack/python-reddwarfclient", packages=["reddwarfclient"], - install_requires=requirements, - tests_require=["nose", "mock"], + install_requires=parse_requirements(), test_suite="nose.collector", classifiers=[ "Development Status :: 5 - Production/Stable", diff --git a/tools/pip-requires b/tools/pip-requires new file mode 100644 index 00000000..27cd31fe --- /dev/null +++ b/tools/pip-requires @@ -0,0 +1,4 @@ +argparse>=1.2.1 +httplib2>=0.7.7 +lxml>=3.0.1 +prettytable>=0.6.1 \ No newline at end of file diff --git a/tools/test-requires b/tools/test-requires new file mode 100644 index 00000000..22a8cbf3 --- /dev/null +++ b/tools/test-requires @@ -0,0 +1,6 @@ +nose>=1.2.1 +nosexcover>=1.0.7 +openstack.nose_plugin>=0.11 +pep8==1.1 +sphinx>=1.1.2 +unittest2>=0.5.1 \ No newline at end of file diff --git a/tox.ini b/tox.ini index 976d57c0..2debadd8 100644 --- a/tox.ini +++ b/tox.ini @@ -1,16 +1,24 @@ # Python Reddwarf Client [tox] -envlist = py26, docs +envlist = py26,py27,pep8 -[testenv:docs] -deps = - coverage - httplib2 - sphinx -commands = - sphinx-build -b doctest {toxinidir}/docs/source {envtmpdir}/html - sphinx-build -b html {toxinidir}/docs/source {envtmpdir}/html +[testenv] +setenv = VIRTUAL_ENV={envdir} + NOSE_WITH_OPENSTACK=1 + NOSE_OPENSTACK_COLOR=1 + NOSE_OPENSTACK_RED=0.05 + NOSE_OPENSTACK_YELLOW=0.025 + NOSE_OPENSTACK_SHOW_ELAPSED=1 +deps = -r{toxinidir}/tools/pip-requires + -r{toxinidir}/tools/test-requires +commands = nosetests [testenv:pep8] -commands = pep8 --repeat --show-source --exclude=.venv,.tox,dist,doc reddwarfclient setup.py \ No newline at end of file +commands = pep8 --repeat --show-source --exclude=.venv,.tox,dist,doc reddwarfclient setup.py + +[testenv:venv] +commands = {posargs} + +[testenv:cover] +commands = nosetests --cover-erase --cover-package=reddwarfclient --with-xcoverage