Skip to content

Commit

Permalink
Merge pull request #472 from HXLStandard/dev
Browse files Browse the repository at this point in the history
Release 2.0.1
  • Loading branch information
davidmegginson committed Jun 1, 2023
2 parents 5a65c84 + ea744c8 commit 3b7b531
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 86 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.pyc
/.eggs
/venv
/venv-test
build
dist
hxl-proxy.wsgi
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2023-06-01 Release 2.0.1:
- tweak dependency versions to avoid requests-cache conflicts
- move setup info from setup.py to setup.cfg
- add more dependency versions to about.html
- ensure that the HXL Proxy can read from itself

2023-05-18 Release 2.0
- from libhxl:
- /api/source-info now returns columns for headers and HXL hashtags
Expand Down
47 changes: 28 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,41 @@
# activation script for the Python virtual environment
VENV=venv/bin/activate

PYTEST_OPTS=-W ignore::DeprecationWarning
PIP3_OPTS=-q
PYTHON_OPTS=-W ignore:::pkg_resources # get rid of the deprecation warnings
SETUP_OPTS=-q

all: $(VENV)

# (re)build the virtual environment if it's missing, or whenever setup.cfg changes
$(VENV): setup.cfg requirements.txt
rm -rf venv
python3 -m venv venv
. $(VENV) && python3 ${PYTHON_OPTS} setup.py ${SETUP_OPTS} develop

# run unit tests
test: $(VENV)
. $(VENV) && pytest
. $(VENV) && pytest ${PYTEST_OPTS}

# run failed unit tests
test-failed: $(VENV)
. $(VENV) && pytest --lf
. $(VENV) && pytest ${PYTEST_OPTS} --lf

# alias to (re)build the Python virtual environment
build-venv: $(VENV)

# (re)build the virtual environment if it's missing, or whenever setup.py changes
$(VENV): setup.py requirements.txt
rm -rf venv
python3 -m venv venv
. $(VENV) && cd ../libhxl-python \
&& pip3 install -r requirements.txt \
&& python setup.py develop \
&& cd ../hxl-proxy \
&& python3 setup.py develop

# do a cold install in a temporary virtual environment and run unit tests
test-install:
pip3 cache remove '*'
pip3 ${PIP3_OPTS} cache remove '*'
echo "Testing setup.py ..."
rm -rf venv-test
python3 -m venv venv-test
. venv-test/bin/activate \
&& python setup.py install \
&& pytest
. venv-test/bin/activate && python3 ${PYTHON_OPTS} setup.py ${SETUP_OPTS} install && pytest ${PYTEST_OPTS}
echo "Testing requirements.txt ..."
rm -rf venv-test
python3 -m venv venv-test
. venv-test/bin/activate && pip3 ${PIP3_OPTS} install -r requirements.txt && pytest ${PYTEST_OPTS}
rm -rf venv-test # make sure we clean up

# Add target for docker build
Expand All @@ -56,7 +62,10 @@ test-docker:

# run local dev (needs config in local/config.py)
run-local: $(VENV)
. $(VENV) && HXL_PROXY_CONFIG=../local/config.py python run-server.py
. $(VENV) && HXL_PROXY_CONFIG=../local/config.py flask --app hxl_proxy run

debug-local: $(VENV)
. $(VENV) && HXL_PROXY_CONFIG=../local/config.py flask --debug --app hxl_proxy run

# browser tests for dev.proxy.hxlstandard.org
browser-tests-local:
Expand All @@ -78,8 +87,8 @@ browser-tests-prod:
publish-pypi: $(VENV)
rm -rf dist/*
. $(VENV) \
&& pip install twine \
&& python setup.py sdist \
&& pip3 ${PIP3_OPTS} -q install twine \
&& python3 ${PYTHON_OPTS} setup.py ${SETUP_OPTS} sdist \
&& twine upload dist/*

# (re)generate emacs TAGS file
Expand Down
6 changes: 1 addition & 5 deletions config.py.TEMPLATE
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import redis
from urllib.parse import urlparse
import distutils.util as util

#
# If True, will show detailed debugging information on errors
# Should be False for a production system
#
DEBUG = bool(util.strtobool(os.getenv('DEBUG', 'True')))
# use app.debug to detect debug mode

#
# Set the Python logging level for the app
Expand Down
2 changes: 1 addition & 1 deletion hxl_proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""

__version__="2.0"
__version__="2.0.1"
"""Module version number
See https://www.python.org/dev/peps/pep-0396/
Expand Down
15 changes: 9 additions & 6 deletions hxl_proxy/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from hxl_proxy import admin, app, auth, cache, caching, dao, exceptions, filters, pcodes, preview, recipes, util, validate

import datetime, flask, hxl, io, json, logging, requests, requests_cache, signal, werkzeug, csv, urllib
import datetime, flask, hxl, importlib, io, json, logging, requests, requests_cache, signal, werkzeug, csv, urllib

from hxl.util import logup

Expand Down Expand Up @@ -92,7 +92,8 @@ def handle_default_exception(e):
return flask.render_template('error.html', e=e, category=type(e)), status

# Register the general error handler UNLESS we're in debug mode
app.register_error_handler(Exception, handle_default_exception)
if not app.debug:
app.register_error_handler(Exception, handle_default_exception)


def handle_redirect_exception(e):
Expand Down Expand Up @@ -205,11 +206,13 @@ def about():
"""
# include version information for these packages
releases = {
'hxl-proxy': hxl_proxy.__version__,
'libhxl': hxl.__version__,
'flask': flask.__version__,
'requests': requests.__version__
'hxl_proxy': hxl_proxy.__version__,
}
for package in ['libhxl', 'flask', 'flask-caching', 'redis', 'requests', 'requests_cache', 'structlog', 'urllib3',]:
try:
releases[package] = importlib.metadata.version(package)
except Exception as e:
releases[package] = str(e)

# draw the web page
return flask.render_template('about.html', releases=releases)
Expand Down
1 change: 0 additions & 1 deletion hxl_proxy/default_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
DEBUG=True
DB_FILE='/tmp/hxl-proxy.db'

HID_CLIENT_ID = '<client id>'
Expand Down
15 changes: 8 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
urllib3>=1.21.1<1.27 # version required by requests
#git+https://github.com/HXLStandard/libhxl-python.git@dev#egg=libhxl # for development
libhxl==5.0 # for release
urllib3<1.27,>1.21.1 # avoid caching bug
requests_cache
ckanapi>=3.5
flask-caching
flask>=2.1.2
flask>=2.2.5<2.3 # 2.3 messes up pip dependencies
mysql-connector-python>=8.0.29
# git+https://github.com/HXLStandard/libhxl-python.git@dev#egg=libhxl # for development
libhxl==5.0.1 # for release
flask-caching
redis
requests>=2.27
requests_cache
requests
structlog
typing_extensions
4 changes: 3 additions & 1 deletion run-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
import sys
import os
from hxl_proxy import app
from hxl import datatypes
if __name__ == "__main__":
app.run(debug=True, host=os.getenv('FLASK_HOST', 'localhost'))
DEBUG = bool(datatypes.is_truthy(os.getenv('DEBUG', 'True')))
app.run(debug=DEBUG, host=os.getenv('FLASK_HOST', 'localhost'))
39 changes: 39 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[metadata]
name = hxl_proxy
version = attr: hxl_proxy.__version__
author = David Megginson
author_email = megginson@un.org
description = Flask-based web data proxy for the Humanitarian Exchange Language (HXL)
long_description = file: README.md
keywords = data, hxl
license = Public Domain
classifiers =
Framework :: Flask
Programming Language :: Python :: 3
project_urls =
Documentation = https://github.com/HXLStandard/hxl-proxy/wiki
GitHub = https://github.com/HXLStandard/hxl-proxy/
Changelog = https://github.com/HXLStandard/hxl-proxy/blob/prod/CHANGELOG

[options]
include_package_data = True
zip_safe = True
packages = hxl_proxy
python_requires = >=3.7
install_requires =
urllib3<1.27,>1.21.1 # avoid caching bug
requests_cache
ckanapi>=3.5
flask>=2.2.5<2.3 # 2.3 messes up pip dependencies
mysql-connector-python>=8.0.29
# libhxl @ git+https://github.com/HXLStandard/libhxl-python.git@dev # for development
libhxl==5.0.1 # for release
flask-caching
redis
structlog
typing_extensions # shouldn't be needed, but setuptools fails to pick it up
dependency_links =
git+https://github.com/HXLStandard/libhxl-python@dev#egg=libhxl
test_suite = tests
tests_require =
mock
48 changes: 3 additions & 45 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,4 @@
#!/usr/bin/python
"""Install, build, or test the HXL Proxy.
For details, try
python setup.py -h
"""
from setuptools import setup

import sys, setuptools

if sys.version_info.major != 3:
raise SystemExit("The HXL Proxy requires Python 3.x")

with open("README.md", "r") as fh:
long_description = fh.read()

setuptools.setup(
name = 'hxl-proxy',
packages = ['hxl_proxy'],
package_data={'hxl_proxy': ['*.sql']},
version = "2.0",
description = 'Flask-based web proxy for HXL',
long_description=long_description,
long_description_content_type="text/markdown",
author='David Megginson',
author_email='contact@megginson.com',
url='https://github.com/HXLStandard/hxl-proxy',
include_package_data = True,
zip_safe = False,
install_requires=[
'urllib3>=1.21.1,<1.27', # version required by requests
#'libhxl @ git+https://github.com/HXLStandard/libhxl-python.git@dev', # for development
'libhxl==5.0', # for release
'ckanapi>=3.5',
'flask-caching',
'flask>=2.1.2',
'mysql-connector-python>=8.0.29',
'redis',
'requests>=2.27',
'requests_cache',
'structlog',
],
dependency_links=[
"git+https://github.com/HXLStandard/libhxl-python@dev#egg=libhxl",
],
test_suite = "tests",
tests_require = ['mock']
)
if __name__ == "__main__":
setup()
1 change: 0 additions & 1 deletion tests/test_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class AbstractControllerTest(base.AbstractDBTest):
def setUp(self):
"""Configure a test app instance."""
super().setUp()
hxl_proxy.app.config['DEBUG'] = False
hxl_proxy.app.config['TIMEOUT'] = 30
hxl_proxy.app.config['SECRET_KEY'] = 'abcde'
hxl_proxy.app.config['HID_BASE_URL'] = 'https://hid.example.org'
Expand Down

0 comments on commit 3b7b531

Please sign in to comment.