From b212a46ab7ebf167625660899a67235b476caff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Tue, 6 Dec 2016 01:30:32 +0100 Subject: [PATCH] Added CI and tests --- .gitignore | 1 + Dockerfile-2.7 | 7 +++++ Dockerfile-3.4 | 7 +++++ Dockerfile.template | 7 +++++ MANIFEST.in | 4 ++- Makefile | 62 +++++++++++++++++++++++++++++++++++++++++++++ bitter/utils.py | 8 ++++-- setup.cfg | 4 +++ setup.py | 2 +- 9 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 Dockerfile-2.7 create mode 100644 Dockerfile-3.4 create mode 100644 Dockerfile.template create mode 100644 Makefile create mode 100644 setup.cfg diff --git a/.gitignore b/.gitignore index e294de9..de962e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +__pycache__ *.egg-info dist env diff --git a/Dockerfile-2.7 b/Dockerfile-2.7 new file mode 100644 index 0000000..f511194 --- /dev/null +++ b/Dockerfile-2.7 @@ -0,0 +1,7 @@ +# onbuild copies . to /usr/src/app/ +From python:2.7-onbuild +Maintainer J. Fernando Sánchez @balkian + +RUN pip install -e "/usr/src/app/[server]" + +ENTRYPOINT ["bitter"] diff --git a/Dockerfile-3.4 b/Dockerfile-3.4 new file mode 100644 index 0000000..b1410bc --- /dev/null +++ b/Dockerfile-3.4 @@ -0,0 +1,7 @@ +# onbuild copies . to /usr/src/app/ +From python:3.4-onbuild +Maintainer J. Fernando Sánchez @balkian + +RUN pip install -e "/usr/src/app/[server]" + +ENTRYPOINT ["bitter"] diff --git a/Dockerfile.template b/Dockerfile.template new file mode 100644 index 0000000..90b3611 --- /dev/null +++ b/Dockerfile.template @@ -0,0 +1,7 @@ +# onbuild copies . to /usr/src/app/ +From python:{{PYVERSION}}-onbuild +Maintainer J. Fernando Sánchez @balkian + +RUN pip install -e "/usr/src/app/[server]" + +ENTRYPOINT ["bitter"] diff --git a/MANIFEST.in b/MANIFEST.in index 2ebb089..f9ecf8b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,4 +5,6 @@ include README.md include bitter/VERSION graft bitter/templates graft bitter/static -graft test +include tests/test* +global-exclude *.pyc +global-exclude __pycache__ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f240584 --- /dev/null +++ b/Makefile @@ -0,0 +1,62 @@ +PYVERSIONS=3.4 2.7 +PYMAIN=$(firstword $(PYVERSIONS)) +NAME=bitter +REPO=balkian +VERSION=$(shell cat $(NAME)/VERSION) + + +all: build run + +dockerfiles: $(addprefix Dockerfile-,$(PYVERSIONS)) + +Dockerfile-%: Dockerfile.template + sed "s/{{PYVERSION}}/$*/" Dockerfile.template > Dockerfile-$* + +build: $(addprefix build-, $(PYMAIN)) + +buildall: $(addprefix build-, $(PYVERSIONS)) + +build-%: Dockerfile-% + docker build -t '$(REPO)/$(NAME):$(VERSION)-python$*' -f Dockerfile-$* .; + +test: $(addprefix test-,$(PYMAIN)) + +testall: $(addprefix test-,$(PYVERSIONS)) + +test-%: build-% + docker run --rm -w /usr/src/app/ -v $$PWD/tests/credentials.json:/usr/src/app/tests/credentials.json --entrypoint=/usr/local/bin/python -ti '$(REPO)/$(NAME):$(VERSION)-python$*' setup.py test --addopts "-vvv -s --pdb" ; + +pip_test-%: + docker run --rm -v $$PWD/dist:/dist/ -ti python:$* pip install /dist/$(NAME)-$(VERSION).tar.gz ; + +dist/$(NAME)-$(VERSION).tar.gz: + docker run --rm -ti -v $$PWD:/usr/src/app/ -w /usr/src/app/ python:$(PYMAIN) python setup.py sdist; + +sdist: dist/$(NAME)-$(VERSION).tar.gz + + +upload-%: test-% + docker push '$(REPO)/$(NAME):$(VERSION)-python$(PYMAIN)' + +upload: testall $(addprefix upload-,$(PYVERSIONS)) + docker tag '$(REPO)/$(NAME):$(VERSION)-python$(PYMAIN)' '$(REPO)/$(NAME):$(VERSION)' + docker tag '$(REPO)/$(NAME):$(VERSION)-python$(PYMAIN)' '$(REPO)/$(NAME)' + +clean: + @docker ps -a | awk '/$(REPO)\/$(NAME)/{ split($$2, vers, "-"); if(vers[1] != "${VERSION}"){ print $$1;}}' | xargs docker rm 2>/dev/null|| true + @docker images | awk '/$(REPO)\/$(NAME)/{ split($$2, vers, "-"); if(vers[1] != "${VERSION}"){ print $$1":"$$2;}}' | xargs docker rmi 2>/dev/null|| true + +upload_git: + git commit -a + git tag ${VERSION} + git push --tags origin master + +pip_upload: + python setup.py sdist upload ; + +pip_test: $(addprefix pip_test-,$(PYVERSIONS)) + +run: build + docker run --rm -p 5000:5000 -ti '$(REPO)/$(NAME):$(VERSION)-python$(PYMAIN)' + +.PHONY: test test-% build-% build test test_pip run diff --git a/bitter/utils.py b/bitter/utils.py index f621a29..44c24ff 100644 --- a/bitter/utils.py +++ b/bitter/utils.py @@ -14,9 +14,13 @@ from multiprocessing.pool import ThreadPool from tqdm import tqdm from itertools import islice, chain - from contextlib import contextmanager -from future.moves.itertools import zip_longest + +try: + from itertools import izip_longest +except ImportError: + from itertools import zip_longest + from collections import Counter from builtins import map, filter diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..0115b61 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,4 @@ +[metadata] +description-file = README.md +[aliases] +test=pytest \ No newline at end of file diff --git a/setup.py b/setup.py index 287da84..ebf267b 100644 --- a/setup.py +++ b/setup.py @@ -38,7 +38,7 @@ setup( extras_require = { 'server': ['flask', 'flask-oauthlib'] }, - test_suite="tests", + setup_requires=['pytest-runner',], include_package_data=True, entry_points=""" [console_scripts]