Skip to content

Commit

Permalink
Merge pull request hugapi#836 from hugapi/develop
Browse files Browse the repository at this point in the history
2.6.1 Release
  • Loading branch information
timothycrosley authored Feb 6, 2020
2 parents 2e240cf + 16aa0a3 commit 9758507
Show file tree
Hide file tree
Showing 19 changed files with 67 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.6.0
current_version = 2.6.1

[bumpversion:file:.env]

Expand Down
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ACKNOWLEDGEMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Code Contributors
- Lordran (@xzycn)
- Stephan Fitzpatrick (@knowsuchagency)
- Edvard Majakari (@EdvardM)
- Sai Charan (@mrsaicharan1)

Documenters
===================
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 26 additions & 6 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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')
Expand All @@ -50,15 +50,15 @@ 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()`

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')
Expand 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.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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](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.

Expand Down
3 changes: 2 additions & 1 deletion examples/cli_multiple.py
Original file line number Diff line number Diff line change
@@ -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])


Expand Down
4 changes: 2 additions & 2 deletions examples/matplotlib/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion examples/pil_example/additional_requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Pillow==6.0.0
Pillow==6.2.0
2 changes: 1 addition & 1 deletion hug/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
"""
from __future__ import absolute_import

current = "2.6.0"
current = "2.6.1"
3 changes: 2 additions & 1 deletion hug/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tool.portray]
docs_dir = "documentation"
extra_dirs = ["examples", "artwork"]

[tool.portray.mkdocs.theme]
favicon = "artwork/koala.png"
logo = "artwork/koala.png"
name = "material"
palette = {primary = "blue grey", accent = "green"}
4 changes: 2 additions & 2 deletions scripts/before_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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`

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,)
Expand Down Expand Up @@ -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"])
1 change: 1 addition & 0 deletions tests/test_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -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=
Expand Down

0 comments on commit 9758507

Please sign in to comment.