Simply build requirements. Dependency management based on

social_app django project.
This commit is contained in:
Mike Terzo
2017-02-28 17:36:43 -05:00
parent fd4051b619
commit 10147b993e
8 changed files with 65 additions and 117 deletions

View File

@@ -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

View File

@@ -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

2
requirements-docker.txt Normal file
View File

@@ -0,0 +1,2 @@
-r requirements.txt
gunicorn==19.6.0

11
requirements-test.txt Normal file
View File

@@ -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

View File

@@ -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

View File

@@ -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

113
setup.py
View File

@@ -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<name>[^\s<=>]+)\s*(?P<pick>[^;]*)(?P<test>(|;.*))$'
def unpin(requirements):
for i, package in enumerate(requirements):
requirements[i] = re.sub(version_parse, r'\g<name> \g<test>', package)
def pin(requirements):
for i, package in enumerate(requirements):
match = re.match(version_parse, package)
version = re.sub(
r'^.*((>=|==)\s*(?P<lower>[^,]+)).*$', r'== \g<lower>',
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',

View File

@@ -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