From 10147b993e9d88456138fd1ca68c1340648604fb Mon Sep 17 00:00:00 2001 From: Mike Terzo Date: Tue, 28 Feb 2017 17:36:43 -0500 Subject: [PATCH] Simply build requirements. Dependency management based on social_app django project. --- .travis.yml | 25 +++------ Dockerfile | 11 ++-- requirements-docker.txt | 2 + requirements-test.txt | 11 ++++ requirements.txt | 10 +++- setup.cfg | 3 +- setup.py | 113 ++++++++++------------------------------ tox.ini | 7 +-- 8 files changed, 65 insertions(+), 117 deletions(-) create mode 100644 requirements-docker.txt create mode 100644 requirements-test.txt diff --git a/.travis.yml b/.travis.yml index 59ab47b..57cba26 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,28 +5,15 @@ python: - "2.7" - "3.5" - "3.6" -env: - global: - - TEST_DEPS="True" - matrix: - - DEPS_RESOLVE="" - - DEPS_RESOLVE="PINNED" - - DEPS_RESOLVE="UNPINNED" - -matrix: - allow_failures: - - env: DEPS_RESOLVE="UNPINNED" install: - # Travis already include pytest, need to upgrade it when unpinned - - if [[ "${DEPS_RESOLVE}" == "UNPINNED" ]]; then pip install -U pytest; fi - - pip install -r requirements.txt + - pip install -r requirements-test.txt - pip install -q coveralls --use-wheel - script: - - py.test --cov=puppetboard --pep8 -v - - if [ "${TRAVIS_PYTHON_VERSION}" != "2.6" ]; then bandit -r puppetboard; fi - - if [ "${TRAVIS_PYTHON_VERSION}" != "2.6" ]; then bandit -r tests; fi - + - pytest + - if [ "${TRAVIS_PYTHON_VERSION}" != "2.6" ]; then + pip install bandit; + bandit -r puppetboard; + fi after_success: - coveralls diff --git a/Dockerfile b/Dockerfile index 615e1af..bdc6641 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,11 +4,12 @@ ENV PUPPETBOARD_PORT 80 EXPOSE 80 ENV PUPPETBOARD_SETTINGS docker_settings.py -RUN mkdir -p /puppetboard -WORKDIR /puppetboard +RUN mkdir -p /usr/src/app/ +WORKDIR /usr/src/app/ -COPY . /puppetboard -RUN python setup.py install docker -RUN rm -rf /puppetboard +COPY requirements*.txt /usr/src/app/ +RUN pip install -r requirements-docker.txt + +COPY . /usr/src/app CMD gunicorn -b 0.0.0.0:${PUPPETBOARD_PORT} --access-logfile=/dev/stdout puppetboard.app:app diff --git a/requirements-docker.txt b/requirements-docker.txt new file mode 100644 index 0000000..22fc9ac --- /dev/null +++ b/requirements-docker.txt @@ -0,0 +1,2 @@ +-r requirements.txt +gunicorn==19.6.0 diff --git a/requirements-test.txt b/requirements-test.txt new file mode 100644 index 0000000..460e85c --- /dev/null +++ b/requirements-test.txt @@ -0,0 +1,11 @@ +-r requirements.txt +pep8==1.6.2 +coverage==4.0 +mock==1.3.0 +pytest==3.0.1 +pytest-pep8==1.0.5 +pytest-cov==2.2.1 +pytest-mock==1.5.0 +cov-core==1.15.0 +unittest2==1.1.0; python_version < '2.7' +beautifulsoup4==4.5.3 diff --git a/requirements.txt b/requirements.txt index d6e1198..a095b09 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,9 @@ --e . +Flask >=0.10.1 +Flask-WTF >=0.12,<=0.13 +Jinja2 >=2.7.2 +MarkupSafe >=0.19 +WTForms >=2.0,<3.0 +Werkzeug >=0.7,<= 0.11.5 +itsdangerous >=0.23 +pypuppetdb >=0.3.2 +requests >=2.6.0 diff --git a/setup.cfg b/setup.cfg index 7ca6f80..de98e4e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,5 +21,6 @@ exclude=venv [tool:pytest] addopts = --cov=puppetboard --cov-report=term-missing -norecursedirs = docs .tox venv +norecursedirs = docs .tox venv .eggs lib pep8ignore = E402 +python_files = test/*.py diff --git a/setup.py b/setup.py index cb55d46..d628696 100644 --- a/setup.py +++ b/setup.py @@ -2,63 +2,10 @@ import sys import os import codecs import re - +from setuptools.command.test import test as TestCommand from setuptools import setup, find_packages from puppetboard.version import __version__ -install_requires = [ - "Flask >= 0.10.1", - "Flask-WTF >= 0.12, <= 0.13", - "WTForms >= 2.0, < 3.0", - "pypuppetdb >= 0.3.2, < 0.4.0", -] - -install_pinned_requires = [ - "Jinja2 >= 2.7.2", - "MarkupSafe >= 0.19", - "Werkzeug >= 0.11.10", - "itsdangerous >= 0.23", - "requests == 2.6.0", -] - -tests_require = [ - "pytest >= 3.0.1", - "pytest-pep8 >= 1.0.5", - "pytest-cov >= 2.2.1", - "pytest-mock >= 1.5.0", - "mock >= 1.3.0", - "bandit", - "beautifulsoup4 >= 4.5.3", -] - -tests_pinned_requires = [ - "pep8 >= 1.6.2", - "coverage >= 4.0", - "cov-core >= 1.15.0", -] -if sys.version_info < (2, 7): - tests_pinned_requires.append("unittest2 >= 1.1.0") - -docker_requires = [ - "gunicorn == 19.6.0", -] - -version_parse = r'^(?P[^\s<=>]+)\s*(?P[^;]*)(?P(|;.*))$' - - -def unpin(requirements): - for i, package in enumerate(requirements): - requirements[i] = re.sub(version_parse, r'\g \g', package) - - -def pin(requirements): - for i, package in enumerate(requirements): - match = re.match(version_parse, package) - version = re.sub( - r'^.*((>=|==)\s*(?P[^,]+)).*$', r'== \g', - match.group('pick')) - requirements[i] = "%s %s%s" % ( - match.group('name'), version, match.group('test')) with codecs.open('README.rst', encoding='utf-8') as f: README = f.read() @@ -66,38 +13,32 @@ with codecs.open('README.rst', encoding='utf-8') as f: with codecs.open('CHANGELOG.rst', encoding='utf-8') as f: CHANGELOG = f.read() -test_deps = False -if os.environ.get('TEST_DEPS') in ('y', 'true', 'True', 't'): - test_deps = True -deps_resolve = os.environ.get('DEPS_RESOLVE') -for arg in sys.argv[:]: - if arg == 'publish': - sys.argv = [sys.argv[0], 'sdist', 'upload'] - break - elif arg == 'docker': - sys.argv.remove(arg) - install_requires.extend(docker_requires) - elif arg == 'unpinned': - sys.argv.remove(arg) - deps_resolve = 'UNPINNED' - elif arg == 'pinned': - sys.argv.remove(arg) - deps_resolve = 'PINNED' - elif arg == 'with_test': - sys.argv.remove(arg) - test_deps = True +requirements = None +with open('requirements.txt', 'r') as f: + requirements = [line.rstrip() + for line in f.readlines() if not line.startswith('-')] -if test_deps: - install_requires.extend(tests_require) +requirements_test = None +with open('requirements-test.txt', 'r') as f: + requirements_test = [line.rstrip() for line in f.readlines() + if not line.startswith('-')] + + +class PyTest(TestCommand): + + user_options = [('pytest-args=', 'a', "Arguments to pass to pytest")] + + def initialize_options(self): + TestCommand.initialize_options(self) + self.pytest_args = '--cov=puppetboard --cov-report=term-missing' + + def run_tests(self): + import shlex + import pytest + errno = pytest.main(shlex.split(self.pytest_args)) + sys.exit(errno) -if deps_resolve == 'UNPINNED': - unpin(install_requires) -elif deps_resolve == 'PINNED': - install_requires.extend(install_pinned_requires) - if test_deps: - install_requires.extend(tests_pinned_requires) - pin(install_requires) setup( name='puppetboard', @@ -111,9 +52,11 @@ setup( include_package_data=True, long_description='\n'.join((README, CHANGELOG)), zip_safe=False, - install_requires=install_requires, - test_requires=tests_require, + install_requires=requirements, + tests_require=requirements_test, + extras_require={'test': requirements_test}, keywords="puppet puppetdb puppetboard", + cmdclass={'test': PyTest}, classifiers=[ 'Development Status :: 3 - Alpha', 'Environment :: Web Environment', diff --git a/tox.ini b/tox.ini index 3bc9a67..1bbe8bf 100644 --- a/tox.ini +++ b/tox.ini @@ -1,12 +1,7 @@ [tox] -envlist = py{26,27,35,36}-{default,pinned,unpinned} +envlist = py{26,27,35,36} [testenv] -setenv = - TEST_DEPS=True - pinned: DEPS_RESOLVE=PINNED - unpinned: DEPS_RESOLVE=UNPINNED commands= py.test --cov=puppetboard --pep8 -v py{27,35,36}: bandit -r puppetboard - py{27,35,36}: bandit -r tests