diff --git a/.drone.yml b/.drone.yml index 47b2ccc..7f6f160 100644 --- a/.drone.yml +++ b/.drone.yml @@ -9,7 +9,7 @@ services: COUCHDB_PASSWORD: password steps: -- name: test +- name: tests image: python:3.6 environment: COUCH_URL: 'http://couchdb:5984' @@ -27,7 +27,7 @@ steps: - pip install codecov - codecov # Perform linting checks - - black --check src tests + - black --check src tests setup.py - flake8 --- @@ -35,6 +35,23 @@ kind: pipeline name: publish steps: +- name: version-dev + image: python:3.6 + commands: + - sed -i "s/.dev/.dev${DRONE_BUILD_NUMBER}/" src/humulus/_version.py + when: + event: + exclude: + - tag + +- name: version-release + image: python:3.6 + commands: + - sed -i "s/.dev//" src/humulus/_version.py + when: + event: + - tag + - name: docker-dev image: plugins/docker settings: @@ -44,7 +61,7 @@ steps: from_secret: DOCKER_PASSWORD repo: shouptech/humulus tags: - - ${DRONE_COMMIT_SHA} + - ${DRONE_BUILD_NUMBER} when: event: exclude: diff --git a/setup.py b/setup.py index 4c44506..fedec49 100644 --- a/setup.py +++ b/setup.py @@ -17,36 +17,38 @@ from os import path from setuptools import find_packages, setup this_directory = path.abspath(path.dirname(__file__)) -with open(path.join(this_directory, 'README.rst'), encoding='utf-8') as f: +# Get contents of README +with open(path.join(this_directory, "README.rst"), encoding="utf-8") as f: long_description = f.read() +# Get current version number +version = {} +with open(path.join(this_directory, "src/humulus/_version.py")) as f: + exec(f.read(), version) + install_requires = [ - 'Flask==1.0.3', - 'Flask-WTF==0.14.2', - 'simplejson==3.16.0', - 'python-slugify==3.0.2', - 'cloudant==2.12.0', + "Flask==1.0.3", + "Flask-WTF==0.14.2", + "simplejson==3.16.0", + "python-slugify==3.0.2", + "cloudant==2.12.0", ] setup( - name='humulus', - version='0.0.1', - url='https://github.com/shouptech/humulus', - author='Mike Shoup', - author_email='mike@shoup.io', - description='Humulus is a beer recipe builder.', + name="humulus", + version=version["__version__"], + url="https://github.com/shouptech/humulus", + author="Mike Shoup", + author_email="mike@shoup.io", + description="Humulus is a beer recipe builder.", long_description=long_description, - long_description_content_type='text/x-rst', - package_dir={'': 'src'}, - packages=find_packages(where='src'), + long_description_content_type="text/x-rst", + package_dir={"": "src"}, + packages=find_packages(where="src"), zip_safe=False, include_package_data=True, install_requires=install_requires, - setup_requires=install_requires + [ - 'pytest-runner', - ], - tests_require=[ - 'pytest', - ], + setup_requires=install_requires + ["pytest-runner"], + tests_require=["pytest"], classifiers=[], ) diff --git a/src/humulus/_version.py b/src/humulus/_version.py new file mode 100644 index 0000000..4f7a780 --- /dev/null +++ b/src/humulus/_version.py @@ -0,0 +1,17 @@ +# Copyright 2019 Mike Shoup +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# The 'dev' portion of this variable will get updated during Drone CI builds +# with a build number for all non-tagged builds. +__version__ = "0.0.1.dev" diff --git a/src/humulus/app.py b/src/humulus/app.py index 2e8aaac..00702d3 100644 --- a/src/humulus/app.py +++ b/src/humulus/app.py @@ -28,6 +28,11 @@ def create_app(test_config=None): # Load config from configuration provided via ENV app.config.from_envvar("HUMULUS_SETTINGS") + # Load current version of humulus + from . import _version + + app.config["version"] = _version.__version__ + from . import couch couch.init_app(app) diff --git a/src/humulus/home.py b/src/humulus/home.py index de07c28..0a8035c 100644 --- a/src/humulus/home.py +++ b/src/humulus/home.py @@ -14,7 +14,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -from flask import Blueprint, redirect, url_for, request, jsonify +from flask import ( + current_app, + Blueprint, + redirect, + url_for, + request, + jsonify, + render_template, +) from humulus.couch import get_db @@ -27,11 +35,20 @@ def index(): return redirect(url_for("recipes.index")) +@bp.route("/about") +def about(): + """Render the about page.""" + return render_template("about.html") + + @bp.route("/status") def status(): + status = {"version": current_app.config["version"]} if request.args.get("couch", default=False): if get_db().exists(): - return jsonify({"ping": "ok", "couch": "ok"}), 200 + status["couch"] = "ok" + return jsonify(status), 200 else: - return jsonify({"ping": "ok", "couch": "not_exist"}), 500 - return jsonify({"ping": "ok"}), 200 + status["couch"] = "not_exist" + return jsonify(status), 500 + return jsonify(status), 200 diff --git a/src/humulus/templates/_base.html b/src/humulus/templates/_base.html index 3b7c495..d2623ff 100644 --- a/src/humulus/templates/_base.html +++ b/src/humulus/templates/_base.html @@ -47,6 +47,9 @@ {% endif %}