Skip to content

Commit

Permalink
Adds circleci improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ravenoak committed Apr 3, 2019
1 parent 4b1f663 commit 82c8cac
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 39 deletions.
87 changes: 51 additions & 36 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,75 +1,93 @@
version: 2.1

workflows:
version: 2
build_and_deploy:
jobs:
- build:
- dependencies:
filters:
tags:
only: /.*/
- test-python-install:
- test:
version: "3.2"
requires:
- dependencies:
- version: "3.2"
- test:
version: "3.3"
requires:
- dependencies:
- version: "3.3"
- test:
version: "3.4"
requires:
- dependencies:
- version: "3.4"
- test:
version: "3.5"
requires:
- dependencies:
- version: "3.5"
- test:
version: "3.6"
requires:
- build
- test-python-install:
- dependencies:
- version: "3.6"
- test:
version: "3.7"
requires:
- build
- deploy:
- dependencies:
- version: "3.7"
- pypi:
requires:
- build
- dependencies
- test
filters:
tags:
only: /v[0-9]+(\.[0-9]+)*/
only: /^v[0-9]+(\.[0-9]+)*/
branches:
ignore: /.*/

jobs:

build:
dependencies:
parameters:
version:
type: string
default: "3.7"
docker:
- image: circleci/python:3.6
- image: circleci/python:<< parameters.version >>
steps:
- checkout
- restore_cache:
key: v1-dependency-cache-{{ .Branch }}-{{ checksum "setup.py" }}
key: v1-dependency-cache-{{ .Branch }}-{{ checksum "requirements.txt" }}-<< parameters.version >>
- run:
name: install python dependencies
command: |
python3 -m venv venv
. venv/bin/activate
python setup.py build
pip3 install -r requirements.txt
- save_cache:
key: v1-dependency-cache-{{ .Branch }}-{{ checksum "setup.py" }}
key: v1-dependency-cache-{{ .Branch }}-{{ checksum "requirements.txt" }}-<< parameters.version >>
paths:
- "venv"

test-python-install:
test:
parameters:
version:
type: string
default: latest
default: "3.7"
docker:
- image: circleci/python:<< parameters.version >>
steps:
- checkout
- restore_cache:
key: v1-dependency-cache-{{ .Branch }}-{{ checksum "setup.py" }}
- run:
name: install python dependencies
command: |
python3 -m venv venv
. venv/bin/activate
python setup.py build
- save_cache:
key: v1-dependency-cache-{{ .Branch }}-{{ checksum "setup.py" }}
paths:
- "venv"
key: v1-dependency-cache-{{ .Branch }}-{{ checksum "requirements.txt" }}-<< parameters.version >>
- run:
name: run tests
command: |
. venv/bin/activate
python setup.py test --junitxml=test-reports/junit.xml
python setup.py test
- store_test_results:
path: test-reports
- store_artifacts:
Expand All @@ -80,23 +98,19 @@ jobs:
python --version
python setup.py install
deploy:
pypi:
docker:
- image: circleci/python:3.6
- image: circleci/python:3.7
steps:
- checkout
- restore_cache:
key: v1-dependency-cache-{{ .Branch }}-{{ checksum "setup.py" }}
key: v1-dependency-cache-{{ .Branch }}-{{ checksum "requirements.txt" }}-3.7
- run:
name: install python dependencies
command: |
python3 -m venv venv
. venv/bin/activate
# make dev
- save_cache:
key: v1-dependency-cache-{{ .Branch }}-{{ checksum "setup.py" }}
paths:
- "venv"
python setup.py build
- run:
name: verify git tag vs. version
command: |
Expand All @@ -112,7 +126,8 @@ jobs:
- run:
name: create packages
command: |
make package
python setup.py sdist
python setup.py bdist_wheel
- run:
name: upload to pypi
command: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ venv.bak/
# mypy
.mypy_cache/

test-reports/
9 changes: 9 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Generated file, do not edit
arango-orm>=0.5.3
Flask>=1.0.0
setuptools
pytest-runner
Sphinx>=1.8.0
sphinx_rtd_theme
pytest>=4.3.0
mock;python_version<"3.3"
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ classifiers =
Framework :: Flask
Intended Audience :: Developers
License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
Programming Language :: Python :: 3.6
Operating System :: OS Independent
Programming Language :: Python :: 3 :: Only
Topic :: Database
Expand Down Expand Up @@ -59,7 +58,7 @@ values =
[tool:pytest]
testpaths = tests
addopts = --cov=flask_arango_orm --flake8
addopts = --cov=flask_arango_orm --flake8 --junitxml=test-reports/junit.xml
[coverage:run]
branch = True
Expand Down
38 changes: 37 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"""Setup for Flask-arango-orm
"""

import os
import sys

from setuptools import find_packages, setup
from setuptools.command.install import install

PROJECT_NAME = 'Flask-arango-orm'
PROJECT_RELEASE = '0.1.0'
Expand All @@ -25,6 +29,35 @@ def readme():
return fh.read()


# Taken from https://circleci.com/blog/continuously-deploying-python-\
# packages-to-pypi-with-circleci/
class VerifyVersionCommand(install):
"""Custom command to verify that the git tag matches our version"""
description = 'verify that the git tag matches our version'

def run(self):
tag = os.getenv('CIRCLE_TAG')

if tag != PROJECT_RELEASE:
info = "Git tag: {0} does not match the version of this app: {1}".format(
tag, PROJECT_RELEASE
)
sys.exit(info)


class WriteRequirementsCommand(install):
"""Writes all package requirements into requirements.txt"""
description = 'creates requirements.txt'

def run(self):
header = '# Generated file, do not edit\n'
all_requirements = INSTALL_REQUIRES + SETUP_REQUIRES + TESTS_REQUIRES
all_requirements = [I + '\n' for I in all_requirements]
all_requirements.insert(0, header)
with open('requirements.txt', 'w') as fh:
fh.writelines(all_requirements)


setup(name=PROJECT_NAME,
version=PROJECT_RELEASE,
description='Flask extension for arango-orm',
Expand All @@ -45,4 +78,7 @@ def readme():
'project': ('setup.py', PROJECT_NAME),
'version': ('setup.py', PROJECT_VERSION),
'release': ('setup.py', PROJECT_RELEASE),
'source_dir': ('setup.py', 'docs')}})
'source_dir': ('setup.py', 'docs'), }, },
cmdclass={
'mk_reqs': WriteRequirementsCommand,
'verify': VerifyVersionCommand, }, )

0 comments on commit 82c8cac

Please sign in to comment.