From 432837d9648cdc0f8f0c99ba885c229f15401c8f Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Thu, 5 Sep 2019 19:41:34 -0700 Subject: [PATCH 01/14] Add portray support --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..8a459db3 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[tool.portray] +docs_dir = "documentation" From 3bbb15b7a5d1d7fc75a63658626a4812285c7f30 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Thu, 5 Sep 2019 20:02:24 -0700 Subject: [PATCH 02/14] Add links for documentation site --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a54fc714..6b621e5d 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,10 @@ [![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://pypi.python.org/pypi/hug/) [![Join the chat at https://gitter.im/timothycrosley/hug](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/timothycrosley/hug?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -NOTE: For more in-depth documentation visit [hug's website](http://www.hug.rest) +_________________ + +[Read Latest Documentation](http://hugapi.github.io/hug/) - [Browse GitHub Code Repository](https://github.com/hugapi/hug) +_________________ hug aims to make developing Python driven APIs as simple as possible, but no simpler. As a result, it drastically simplifies Python API development. From 9aef8c8e8058158fe2962a6881c97e758da51d43 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Thu, 5 Sep 2019 20:10:37 -0700 Subject: [PATCH 03/14] Include hug icon / customize theme --- pyproject.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 8a459db3..e397fe1e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,8 @@ [tool.portray] docs_dir = "documentation" + +[tool.portray.mkdocs.theme] +favicon = "artwork/koala.png" +logo = "artwork/koala.png" +name = "material" +palette = {primary = "blue grey", accent = "green"} From 8aaafcca9ae13dc2544a555a6226d0a133b0c7f7 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Fri, 6 Sep 2019 08:44:30 -0700 Subject: [PATCH 04/14] Switch to HTTPs link for documentation website --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6b621e5d..408249a7 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ _________________ -[Read Latest Documentation](http://hugapi.github.io/hug/) - [Browse GitHub Code Repository](https://github.com/hugapi/hug) +[Read Latest Documentation](https://hugapi.github.io/hug/) - [Browse GitHub Code Repository](https://github.com/hugapi/hug) _________________ hug aims to make developing Python driven APIs as simple as possible, but no simpler. As a result, it drastically simplifies Python API development. From 7987c48feaafb5082ae03bd9b3a677774ccca160 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Wed, 11 Sep 2019 01:01:43 -0700 Subject: [PATCH 05/14] Add initial documentation around CORS usage --- FAQ.md | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/FAQ.md b/FAQ.md index 9d524869..1d9e85e2 100644 --- a/FAQ.md +++ b/FAQ.md @@ -6,13 +6,13 @@ For more examples, check out Hug's [documentation](https://github.com/timothycro Q: *Can I use Hug with a web framework -- Django for example?* -A: You can use Hug alongside Django or the web framework of your choice, but it does have drawbacks. You would need to run hug on a separate, hug-exclusive server. You can also [mount Hug as a WSGI app](https://pythonhosted.org/django-wsgi/embedded-apps.html), embedded within your normal Django app. +A: You can use Hug alongside Django or the web framework of your choice, but it does have drawbacks. You would need to run hug on a separate, hug-exclusive server. You can also [mount Hug as a WSGI app](https://pythonhosted.org/django-wsgi/embedded-apps.html), embedded within your normal Django app. Q: *Is Hug compatabile with Python 2?* -A: Python 2 is not supported by Hug. However, if you need to account for backwards compatability, there are workarounds. For example, you can wrap the decorators: +A: Python 2 is not supported by Hug. However, if you need to account for backwards compatability, there are workarounds. For example, you can wrap the decorators: -```Python +```Python def my_get_fn(func, *args, **kwargs): if 'hug' in globals(): return hug.get(func, *args, **kwargs) @@ -29,7 +29,7 @@ Q: *How can I serve static files from a directory using Hug?* A: For a static HTML page, you can just set the proper output format as: `output=hug.output_format.html`. To see other examples, check out the [html_serve](https://github.com/timothycrosley/hug/blob/develop/examples/html_serve.py) example, the [image_serve](https://github.com/timothycrosley/hug/blob/develop/examples/image_serve.py) example, and the more general [static_serve](https://github.com/timothycrosley/hug/blob/develop/examples/static_serve.py) example within `hug/examples`. -Most basic examples will use a format that looks something like this: +Most basic examples will use a format that looks something like this: ```Python @hug.static('/static') @@ -50,7 +50,7 @@ A: You can access a list of your routes by using the routes object on the HTTP A `__hug_wsgi__.http.routes` -It will return to you a structure of "base_url -> url -> HTTP method -> Version -> Python Handler". Therefore, for example, if you have no base_url set and you want to see the list of all URLS, you could run: +It will return to you a structure of "base_url -> url -> HTTP method -> Version -> Python Handler". Therefore, for example, if you have no base_url set and you want to see the list of all URLS, you could run: `__hug_wsgi__.http.routes[''].keys()` @@ -58,7 +58,7 @@ Q: *How can I configure a unique 404 route?* A: By default, Hug will call `documentation_404()` if no HTTP route is found. However, if you want to configure other options (such as routing to a directiory, or routing everything else to a landing page) you can use the `@hug.sink('/')` decorator to create a "catch-all" route: -```Python +```Python import hug @hug.sink('/all') @@ -67,3 +67,23 @@ def my_sink(request): ``` For more information, check out the ROUTING.md file within the `hug/documentation` directory. + +Q: *How can I enable CORS* + +A: There are many solutions depending on the specifics of your application. +For most applications, you can use the included cors middleware: + +``` +import hug + +api = hug.API(__name__) +api.http.add_middleware(hug.middleware.CORSMiddleware(api, max_age=10)) + + +@hug.get("/demo") +def get_demo(): + return {"result": "Hello World"} +``` +For cases that are more complex then the middleware handles + +[This comment]([https://github.com/hugapi/hug/issues/114#issuecomment-342493165]) (and the discussion around it) give a good starting off point. From 084dccd8230060218fc7d908e074dc8eb72ffdee Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Wed, 11 Sep 2019 20:58:41 -0700 Subject: [PATCH 06/14] Fix broken link in FAQ for CORs section --- FAQ.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FAQ.md b/FAQ.md index 1d9e85e2..e0c03ef7 100644 --- a/FAQ.md +++ b/FAQ.md @@ -86,4 +86,4 @@ def get_demo(): ``` For cases that are more complex then the middleware handles -[This comment]([https://github.com/hugapi/hug/issues/114#issuecomment-342493165]) (and the discussion around it) give a good starting off point. +[This comment](https://github.com/hugapi/hug/issues/114#issuecomment-342493165) (and the discussion around it) give a good starting off point. From 58358e81390cb6e7f725afa5188e04a9886f27d8 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Sun, 15 Sep 2019 20:55:33 -0700 Subject: [PATCH 07/14] Update to enable compatability with latest version of portray --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index e397fe1e..1eed2352 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,6 @@ [tool.portray] docs_dir = "documentation" +extra_dirs = ["examples", "artwork"] [tool.portray.mkdocs.theme] favicon = "artwork/koala.png" From 57d85ab2f781cef0180edcb680986b6241a3fac0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 22 Oct 2019 20:17:40 +0000 Subject: [PATCH 08/14] Bump pillow from 6.0.0 to 6.2.0 in /examples/pil_example Bumps [pillow](https://github.com/python-pillow/Pillow) from 6.0.0 to 6.2.0. - [Release notes](https://github.com/python-pillow/Pillow/releases) - [Changelog](https://github.com/python-pillow/Pillow/blob/master/CHANGES.rst) - [Commits](https://github.com/python-pillow/Pillow/compare/6.0.0...6.2.0) Signed-off-by: dependabot[bot] --- examples/pil_example/additional_requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/pil_example/additional_requirements.txt b/examples/pil_example/additional_requirements.txt index 4fb5ba9f..d31f72f6 100644 --- a/examples/pil_example/additional_requirements.txt +++ b/examples/pil_example/additional_requirements.txt @@ -1 +1 @@ -Pillow==6.0.0 +Pillow==6.2.0 From 038e2797f876b057d3dd18487b08f481f3f9cb48 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Sun, 24 Nov 2019 23:50:52 -0800 Subject: [PATCH 09/14] Add testing of 3.8 --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 454ae64b..a8c716dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,9 @@ matrix: - os: linux sudo: required python: 3.6 + - os: linux + sudo: required + python: 3.8 - os: linux sudo: required python: 3.7 From 9d68fff5c63e4428941fe864a42998ac02744676 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Tue, 26 Nov 2019 23:00:27 -0800 Subject: [PATCH 10/14] Fix before install to know about python 3.8 --- scripts/before_install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/before_install.sh b/scripts/before_install.sh index 32ab2dbc..ff7ca041 100755 --- a/scripts/before_install.sh +++ b/scripts/before_install.sh @@ -12,8 +12,6 @@ echo $TRAVIS_OS_NAME # Find the latest requested version of python case "$TOXENV" in - py34) - python_minor=4;; py35) python_minor=5;; py36) @@ -24,6 +22,8 @@ echo $TRAVIS_OS_NAME python_minor=6;; py37) python_minor=7;; + py38) + python_minor=8;; esac latest_version=`pyenv install --list | grep -e "^[ ]*3\.$python_minor" | tail -1` From 6d642df55539d842f4844866f7a7f1263da8816e Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Tue, 26 Nov 2019 23:14:21 -0800 Subject: [PATCH 11/14] Add 38 to tox --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 6d60eda4..62d638e2 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist=py{35,36,37,py3}-marshmallow{2,3}, cython-marshmallow{2,3} +envlist=py{35,36,37,38,py3}-marshmallow{2,3}, cython-marshmallow{2,3} [testenv] deps= From 0c07a7e4574aacd51ee8532d1668fa7b7bd3151f Mon Sep 17 00:00:00 2001 From: mrsaicharan1 Date: Sat, 1 Feb 2020 22:17:32 +0530 Subject: [PATCH 12/14] fix: Initialized OrderedDict to fix documentation function fix: black line length reformatting --- examples/cli_multiple.py | 3 ++- examples/matplotlib/plot.py | 4 ++-- hug/interface.py | 3 ++- tests/test_decorators.py | 3 ++- tests/test_documentation.py | 1 + tests/test_routing.py | 5 ++++- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/examples/cli_multiple.py b/examples/cli_multiple.py index b4bfcef1..d16bc0e9 100644 --- a/examples/cli_multiple.py +++ b/examples/cli_multiple.py @@ -1,7 +1,8 @@ import hug + @hug.cli() -def add(numbers: list=None): +def add(numbers: list = None): return sum([int(number) for number in numbers]) diff --git a/examples/matplotlib/plot.py b/examples/matplotlib/plot.py index 4f1906c3..066af861 100644 --- a/examples/matplotlib/plot.py +++ b/examples/matplotlib/plot.py @@ -7,9 +7,9 @@ @hug.get(output=hug.output_format.png_image) def plot(): pyplot.plot([1, 2, 3, 4]) - pyplot.ylabel('some numbers') + pyplot.ylabel("some numbers") image_output = io.BytesIO() - pyplot.savefig(image_output, format='png') + pyplot.savefig(image_output, format="png") image_output.seek(0) return image_output diff --git a/hug/interface.py b/hug/interface.py index 3463a062..fbd31619 100644 --- a/hug/interface.py +++ b/hug/interface.py @@ -305,7 +305,8 @@ def check_requirements(self, request=None, response=None, context=None): def documentation(self, add_to=None): """Produces general documentation for the interface""" - doc = OrderedDict if add_to is None else add_to + + doc = OrderedDict() if add_to is None else add_to usage = self.interface.spec.__doc__ if usage: diff --git a/tests/test_decorators.py b/tests/test_decorators.py index 8e70f134..4e180cd7 100644 --- a/tests/test_decorators.py +++ b/tests/test_decorators.py @@ -1044,6 +1044,7 @@ def extend_with(): # But not both with pytest.raises(ValueError): + @hug.extend_api(sub_command="sub_api", command_prefix="api_", http=False) def extend_with(): return (tests.module_fake_http_and_cli,) @@ -1940,7 +1941,7 @@ def pull_record(record_id: hug.types.number = 1): def test_multiple_cli(hug_api): @hug.cli(api=hug_api) - def multiple(items: list=None): + def multiple(items: list = None): return items hug_api.cli([None, "multiple", "-i", "one", "-i", "two"]) diff --git a/tests/test_documentation.py b/tests/test_documentation.py index b528dee6..1e0bbb71 100644 --- a/tests/test_documentation.py +++ b/tests/test_documentation.py @@ -186,6 +186,7 @@ def marshtest() -> Returns(): assert doc["handlers"]["/marshtest"]["POST"]["outputs"]["type"] == "Return docs" + def test_map_params_documentation_preserves_type(): @hug.get(map_params={"from": "from_mapped"}) def map_params_test(from_mapped: hug.types.number): diff --git a/tests/test_routing.py b/tests/test_routing.py index 1aadbc2e..c492909e 100644 --- a/tests/test_routing.py +++ b/tests/test_routing.py @@ -418,4 +418,7 @@ def test_allow_origins_request_handling(self, hug_api): def my_endpoint(): return "Success" - assert hug.test.get(hug_api, "/my_endpoint", headers={'ORIGIN': 'google.com'}).data == "Success" + assert ( + hug.test.get(hug_api, "/my_endpoint", headers={"ORIGIN": "google.com"}).data + == "Success" + ) From 7bb7cec3877fcee66d4c9d1c4252eebd77b27905 Mon Sep 17 00:00:00 2001 From: Timothy Edmund Crosley Date: Thu, 6 Feb 2020 08:57:50 -0800 Subject: [PATCH 13/14] Update ACKNOWLEDGEMENTS.md Add Sai Charan (@mrsaicharan1) to contributors list --- ACKNOWLEDGEMENTS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ACKNOWLEDGEMENTS.md b/ACKNOWLEDGEMENTS.md index dca0e0c9..3eb7c874 100644 --- a/ACKNOWLEDGEMENTS.md +++ b/ACKNOWLEDGEMENTS.md @@ -52,6 +52,7 @@ Code Contributors - Lordran (@xzycn) - Stephan Fitzpatrick (@knowsuchagency) - Edvard Majakari (@EdvardM) +- Sai Charan (@mrsaicharan1) Documenters =================== From 16aa0a3cb06f9be434eadac0737650770e661555 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Thu, 6 Feb 2020 09:17:49 -0800 Subject: [PATCH 14/14] Bump version to 2.6.1 --- .bumpversion.cfg | 2 +- .env | 2 +- CHANGELOG.md | 3 +++ hug/_version.py | 2 +- setup.py | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 59ce67d4..b1770e2f 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.6.0 +current_version = 2.6.1 [bumpversion:file:.env] diff --git a/.env b/.env index 7687a5af..281cd43d 100644 --- a/.env +++ b/.env @@ -11,7 +11,7 @@ fi export PROJECT_NAME=$OPEN_PROJECT_NAME export PROJECT_DIR="$PWD" -export PROJECT_VERSION="2.6.0" +export PROJECT_VERSION="2.6.1" if [ ! -d "venv" ]; then if ! hash pyvenv 2>/dev/null; then diff --git a/CHANGELOG.md b/CHANGELOG.md index 32bc327c..7dbbeb66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ Ideally, within a virtual environment. Changelog ========= +### 2.6.1 - February 6, 2019 +- Fixed issue #834: Bug in some cases when introspecting local documentation. + ### 2.6.0 - August 29, 2019 - Improved CLI multiple behaviour with empty defaults - Improved CLI type output for built-in types diff --git a/hug/_version.py b/hug/_version.py index a3c76249..c0c9a9df 100644 --- a/hug/_version.py +++ b/hug/_version.py @@ -21,4 +21,4 @@ """ from __future__ import absolute_import -current = "2.6.0" +current = "2.6.1" diff --git a/setup.py b/setup.py index 034cacf4..3d84b665 100755 --- a/setup.py +++ b/setup.py @@ -78,7 +78,7 @@ def list_modules(dirname): setup( name="hug", - version="2.6.0", + version="2.6.1", description="A Python framework that makes developing APIs " "as simple as possible, but no simpler.", long_description=long_description,