1
0
Fork 0
mirror of https://github.com/shouptech/humulus.git synced 2026-02-03 16:09:44 +00:00

Add version number

This commit is contained in:
Emma 2019-07-22 15:30:27 -06:00
parent 9b1a739347
commit 02b2f321a4
8 changed files with 121 additions and 29 deletions

View file

@ -27,7 +27,7 @@ steps:
- pip install codecov - pip install codecov
- codecov - codecov
# Perform linting checks # Perform linting checks
- black --check src tests - black --check src tests setup.py
- flake8 - flake8
--- ---

View file

@ -17,36 +17,38 @@ from os import path
from setuptools import find_packages, setup from setuptools import find_packages, setup
this_directory = path.abspath(path.dirname(__file__)) 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() 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 = [ install_requires = [
'Flask==1.0.3', "Flask==1.0.3",
'Flask-WTF==0.14.2', "Flask-WTF==0.14.2",
'simplejson==3.16.0', "simplejson==3.16.0",
'python-slugify==3.0.2', "python-slugify==3.0.2",
'cloudant==2.12.0', "cloudant==2.12.0",
] ]
setup( setup(
name='humulus', name="humulus",
version='0.0.1', version=version["__version__"],
url='https://github.com/shouptech/humulus', url="https://github.com/shouptech/humulus",
author='Mike Shoup', author="Mike Shoup",
author_email='mike@shoup.io', author_email="mike@shoup.io",
description='Humulus is a beer recipe builder.', description="Humulus is a beer recipe builder.",
long_description=long_description, long_description=long_description,
long_description_content_type='text/x-rst', long_description_content_type="text/x-rst",
package_dir={'': 'src'}, package_dir={"": "src"},
packages=find_packages(where='src'), packages=find_packages(where="src"),
zip_safe=False, zip_safe=False,
include_package_data=True, include_package_data=True,
install_requires=install_requires, install_requires=install_requires,
setup_requires=install_requires + [ setup_requires=install_requires + ["pytest-runner"],
'pytest-runner', tests_require=["pytest"],
],
tests_require=[
'pytest',
],
classifiers=[], classifiers=[],
) )

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

@ -0,0 +1,20 @@
# 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.
import os
__version__ = "0.0.1"
if os.environ.get("DRONE_BUILD_NUMBER", default=None) is not None:
__version__ += "dev{}".format(os.environ["DRONE_BUILD_NUMBER"])

View file

@ -28,6 +28,11 @@ def create_app(test_config=None):
# Load config from configuration provided via ENV # Load config from configuration provided via ENV
app.config.from_envvar("HUMULUS_SETTINGS") app.config.from_envvar("HUMULUS_SETTINGS")
# Load current version of humulus
from . import _version
app.config["version"] = _version.__version__
from . import couch from . import couch
couch.init_app(app) couch.init_app(app)

View file

@ -14,7 +14,15 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # 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 from humulus.couch import get_db
@ -27,11 +35,20 @@ def index():
return redirect(url_for("recipes.index")) return redirect(url_for("recipes.index"))
@bp.route("/about")
def about():
"""Render the about page."""
return render_template("about.html")
@bp.route("/status") @bp.route("/status")
def status(): def status():
status = {"version": current_app.config["version"]}
if request.args.get("couch", default=False): if request.args.get("couch", default=False):
if get_db().exists(): if get_db().exists():
return jsonify({"ping": "ok", "couch": "ok"}), 200 status["couch"] = "ok"
return jsonify(status), 200
else: else:
return jsonify({"ping": "ok", "couch": "not_exist"}), 500 status["couch"] = "not_exist"
return jsonify({"ping": "ok"}), 200 return jsonify(status), 500
return jsonify(status), 200

View file

@ -47,6 +47,9 @@
{% endif %} {% endif %}
</ul> </ul>
<ul class="navbar-nav ml-auto"> <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"> <li class="nav-item active">
{% if session.logged_in %} {% if session.logged_in %}
<a class="nav-link" href="{{ url_for('auth.logout') }}">Logout</a> <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 # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from humulus import _version
def test_home(client): def test_home(client):
response = client.get("/") response = client.get("/")
assert response.status_code == 302 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): def test_status(client, monkeypatch):
class MockDBTrue: class MockDBTrue:
def exists(self): def exists(self):
@ -29,14 +37,20 @@ def test_status(client, monkeypatch):
response = client.get("/status") response = client.get("/status")
assert response.status_code == 200 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) monkeypatch.setattr("humulus.home.get_db", MockDBTrue)
response = client.get("/status?couch=y") response = client.get("/status?couch=y")
assert response.status_code == 200 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) monkeypatch.setattr("humulus.home.get_db", MockDBFalse)
response = client.get("/status?couch=y") response = client.get("/status?couch=y")
assert response.status_code == 500 assert response.status_code == 500
assert response.get_json() == {"ping": "ok", "couch": "not_exist"} assert response.get_json() == {
"version": _version.__version__,
"couch": "not_exist",
}