diff --git a/.travis.yml b/.travis.yml index a23697a..59ab47b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,28 +6,27 @@ python: - "3.5" - "3.6" env: - - PINNED=TRUE - - PINNED=FALSE + global: + - TEST_DEPS="True" + matrix: + - DEPS_RESOLVE="" + - DEPS_RESOLVE="PINNED" + - DEPS_RESOLVE="UNPINNED" matrix: allow_failures: - - python: 2.6 - env: PINNED=FALSE - - python: 2.7 - env: PINNED=FALSE - - python: 3.5 - env: PINNED=FALSE - - python: 3.6 - env: PINNED=FALSE + - env: DEPS_RESOLVE="UNPINNED" install: - - if [ "${PINNED}" == "FALSE" ]; then python scripts/unpin.py; fi + # 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 -U -r requirements-test.txt - - pip install -q coverage coveralls --use-wheel + - pip install -q coveralls --use-wheel + script: - - py.test --cov=puppetboard --pep8 -v - - ./bandit.sh + - 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 after_success: - coveralls diff --git a/Dockerfile b/Dockerfile index 87d9cab..615e1af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,14 @@ FROM python:2.7-alpine ENV PUPPETBOARD_PORT 80 -ENV PUPPETBOARD_SETTINGS docker_settings.py -RUN mkdir -p /usr/src/app -WORKDIR /usr/src/app +EXPOSE 80 -COPY requirements-docker.txt /usr/src/app/ -RUN pip install --no-cache-dir -r requirements-docker.txt -COPY . /usr/src/app +ENV PUPPETBOARD_SETTINGS docker_settings.py +RUN mkdir -p /puppetboard +WORKDIR /puppetboard + +COPY . /puppetboard +RUN python setup.py install docker +RUN rm -rf /puppetboard CMD gunicorn -b 0.0.0.0:${PUPPETBOARD_PORT} --access-logfile=/dev/stdout puppetboard.app:app diff --git a/bandit.sh b/bandit.sh deleted file mode 100755 index d54293c..0000000 --- a/bandit.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -xe -# Runs bandit tests - -pyver="$(python -V 2>&1)" - -if [[ $pyver =~ Python\ 2\.6 ]] -then - echo 'Bandit does not support python 2.6' -else - bandit -r puppetboard - bandit -r tests -fi diff --git a/puppetboard/__init__.py b/puppetboard/__init__.py index e69de29..5f04a96 100644 --- a/puppetboard/__init__.py +++ b/puppetboard/__init__.py @@ -0,0 +1,5 @@ +# +# Pupppetboard +# + +from .version import __version__ diff --git a/puppetboard/app.py b/puppetboard/app.py index bf03ee4..9dd062e 100644 --- a/puppetboard/app.py +++ b/puppetboard/app.py @@ -29,6 +29,8 @@ from puppetboard.dailychart import get_daily_reports_chart import werkzeug.exceptions as ex +from . import __version__ + REPORTS_COLUMNS = [ {'attr': 'end', 'filter': 'end_time', 'name': 'End time', 'type': 'datetime'}, @@ -66,6 +68,11 @@ logging.basicConfig(level=numeric_level) log = logging.getLogger(__name__) +@app.template_global() +def version(): + return __version__ + + def stream_template(template_name, **context): app.update_template_context(context) t = app.jinja_env.get_template(template_name) diff --git a/puppetboard/templates/layout.html b/puppetboard/templates/layout.html index 3a40a03..2c445ce 100644 --- a/puppetboard/templates/layout.html +++ b/puppetboard/templates/layout.html @@ -87,7 +87,7 @@ {% endfor %} -
v0.2.1
+
{{version()}}
diff --git a/puppetboard/version.py b/puppetboard/version.py new file mode 100644 index 0000000..5593202 --- /dev/null +++ b/puppetboard/version.py @@ -0,0 +1,5 @@ +# +# Puppetboard version module +# + +__version__ = '0.3.0.dev0' diff --git a/requirements-docker.txt b/requirements-docker.txt deleted file mode 100644 index 2d8f2bb..0000000 --- a/requirements-docker.txt +++ /dev/null @@ -1,10 +0,0 @@ -gunicorn==19.6.0 -Flask==0.10.1 -Flask-WTF==0.12 -Jinja2==2.7.2 -MarkupSafe==0.19 -WTForms==2.1 -Werkzeug==0.11.10 -itsdangerous==0.23 -pypuppetdb==0.3.2 -requests==2.6.0 diff --git a/requirements-test.txt b/requirements-test.txt deleted file mode 100644 index 021a97c..0000000 --- a/requirements-test.txt +++ /dev/null @@ -1,11 +0,0 @@ -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' -bandit -beautifulsoup4==4.5.3 diff --git a/requirements.txt b/requirements.txt index 899eb3b..d6e1198 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1 @@ -Flask==0.10.1 -Flask-WTF==0.12 -Jinja2==2.7.2 -MarkupSafe==0.19 -WTForms==2.1 -Werkzeug==0.11.10 -itsdangerous==0.23 -pypuppetdb==0.3.2 -requests==2.6.0 +-e . diff --git a/scripts/unpin.py b/scripts/unpin.py deleted file mode 100644 index 503b93a..0000000 --- a/scripts/unpin.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python - -import glob -import re -try: - import future.utils -except: - pass - - -for req_file in glob.glob('requirements*.txt'): - new_data = [] - with open(req_file, 'r') as fp: - data = fp.readlines() - for line in data: - new_data.append(re.sub(r'==\d+(\.\d+){0,3}\s+$', '\n', line)) - - with open(req_file, 'w') as fp: - fp.writelines(new_data) diff --git a/setup.py b/setup.py index 80e2051..cb55d46 100644 --- a/setup.py +++ b/setup.py @@ -1,15 +1,64 @@ import sys import os import codecs +import re 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(|;.*))$' -if sys.argv[-1] == 'publish': - os.system('python setup.py sdist upload') - sys.exit() +def unpin(requirements): + for i, package in enumerate(requirements): + requirements[i] = re.sub(version_parse, r'\g \g', package) -VERSION = "0.2.1" + +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() @@ -17,9 +66,42 @@ 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 + +if test_deps: + install_requires.extend(tests_require) + +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', - version=VERSION, + version=__version__, author='Corey Hammerton', author_email='corey.hammerton@gmail.com', packages=find_packages(), @@ -29,12 +111,8 @@ setup( include_package_data=True, long_description='\n'.join((README, CHANGELOG)), zip_safe=False, - install_requires=[ - "Flask >= 0.10.1", - "Flask-WTF >= 0.12, <= 0.13", - "WTForms >= 2.0, < 3.0", - "pypuppetdb >= 0.3.0, < 0.4.0", - ], + install_requires=install_requires, + test_requires=tests_require, keywords="puppet puppetdb puppetboard", classifiers=[ 'Development Status :: 3 - Alpha', diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..3bc9a67 --- /dev/null +++ b/tox.ini @@ -0,0 +1,12 @@ +[tox] +envlist = py{26,27,35,36}-{default,pinned,unpinned} + +[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