1
0
Fork 0
mirror of https://github.com/shouptech/humulus.git synced 2026-02-03 12:39:42 +00:00

Add version number (#41)

Closes #35
This commit is contained in:
Emma 2019-07-24 12:31:29 -06:00 committed by GitHub
parent 9b1a739347
commit 4db11b91b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 137 additions and 31 deletions

View file

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

View file

@ -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=[],
)

17
src/humulus/_version.py Normal file
View file

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

View file

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

View file

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

View file

@ -47,6 +47,9 @@
{% endif %}
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item {% if request.url_rule.endpoint == 'home.about' %}active{% endif %}">
<a class="nav-link" href="{{ url_for('home.about') }}">About</a>
</li>
<li class="nav-item active">
{% if session.logged_in %}
<a class="nav-link" href="{{ url_for('auth.logout') }}">Logout</a>

View file

@ -0,0 +1,31 @@
{#-
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.
-#}
{% extends '_base.html' %}
{% block title %}About Humulus{% endblock %}
{% block body %}
<div><h1>About Humulus</h1></div>
<div class="row"><div class="col">
Humulus version: {{ config.version }}
</div></div>
<div class="row"><div class="col">
<a href="https://github.com/shouptech/humulus/">Humulus</a> is an open source application for building beer recipes.
</div></div>
<div class="row"><div class="col">
Humulus is licensed under the
<a href="https://github.com/shouptech/humulus/blob/master/LICENSE">Apache v2.0 License</a>.
</div></div>
{% endblock %}

View file

@ -12,12 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from humulus import _version
def test_home(client):
response = client.get("/")
assert response.status_code == 302
def test_about(client):
response = client.get("/about")
assert response.status_code == 200
assert _version.__version__ in str(response.data)
def test_status(client, monkeypatch):
class MockDBTrue:
def exists(self):
@ -29,14 +37,20 @@ def test_status(client, monkeypatch):
response = client.get("/status")
assert response.status_code == 200
assert response.get_json() == {"ping": "ok"}
assert response.get_json() == {"version": _version.__version__}
monkeypatch.setattr("humulus.home.get_db", MockDBTrue)
response = client.get("/status?couch=y")
assert response.status_code == 200
assert response.get_json() == {"ping": "ok", "couch": "ok"}
assert response.get_json() == {
"version": _version.__version__,
"couch": "ok",
}
monkeypatch.setattr("humulus.home.get_db", MockDBFalse)
response = client.get("/status?couch=y")
assert response.status_code == 500
assert response.get_json() == {"ping": "ok", "couch": "not_exist"}
assert response.get_json() == {
"version": _version.__version__,
"couch": "not_exist",
}