Skip to content

Commit 0e305b5

Browse files
Merge pull request #756 from timothycrosley/develop
Release 2.4.6
2 parents 9756917 + 4801e1d commit 0e305b5

File tree

9 files changed

+73
-15
lines changed

9 files changed

+73
-15
lines changed

Diff for: .bumpversion.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 2.4.5
2+
current_version = 2.4.6
33

44
[bumpversion:file:.env]
55

Diff for: .env

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fi
1111

1212
export PROJECT_NAME=$OPEN_PROJECT_NAME
1313
export PROJECT_DIR="$PWD"
14-
export PROJECT_VERSION="2.4.5"
14+
export PROJECT_VERSION="2.4.6"
1515

1616
if [ ! -d "venv" ]; then
1717
if ! hash pyvenv 2>/dev/null; then

Diff for: CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ Ideally, within a virtual environment.
1313
Changelog
1414
=========
1515

16+
### 2.4.6 - March 25, 2019
17+
- Fixed issue #753 - 404 not found does not respect default output format.
18+
- Documented the `--without-cython` option in `CONTRIBUTING.md`
19+
- Extended documentation for output formats
20+
1621
### 2.4.4 - March 21, 2019
1722
- Added the ability to change the default output format for CLI endpoints both at the API and global level.
1823
- Added the ablity to extend CLI APIs in addition to HTTP APIs issue #744.

Diff for: CONTRIBUTING.md

+14
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ Once you have verified that you system matches the base requirements you can sta
3333
- If you don't have autoenv set-up, run `source .env` to set up the local environment. You will need to run this script every time you want to work on the project - though it will not cause the entire set up process to re-occur.
3434
4. Run `test` to verify your everything is set up correctly. If the tests all pass, you have successfully set up hug for local development! If not, you can ask for help diagnosing the error [here](https://gitter.im/timothycrosley/hug).
3535

36+
At step 3, you can skip using autoenv and the `.env` script,
37+
and create your development virtul environment manually instead
38+
using e.g. [`python3 -m venv`](https://docs.python.org/3/library/venv.html)
39+
or `mkvirtualenv` (from [virtualenvwrapper](https://virtualenvwrapper.readthedocs.io/en/latest/)).
40+
41+
Install dependencies by running `pip install -r requirements/release.txt`,
42+
and optional build or development dependencies
43+
by running `pip install -r requirements/build.txt`
44+
or `pip install -r requirements/build.txt`.
45+
46+
Install Hug itself with `pip install .` or `pip install -e .` (for editable mode).
47+
This will compile all modules with [Cython](https://cython.org/) if it's installed in the environment.
48+
You can skip Cython compilation using `pip install --without-cython .` (this works with `-e` as well).
49+
3650
Making a contribution
3751
=========
3852
Congrats! You're now ready to make a contribution! Use the following as a guide to help you reach a successful pull-request:

Diff for: documentation/OUTPUT_FORMATS.md

+32-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ hug output formats
33

44
Every endpoint that is exposed through an externally facing interface will need to return data in a standard, easily understandable format.
55

6-
The default output format for all hug APIs is JSON. However, you may explicitly specify a different default output_format:
6+
The default output format for all hug APIs is JSON. However, you may explicitly specify a different default output_format for a particular API:
77

88
hug.API(__name__).http.output_format = hug.output_format.html
99

@@ -13,7 +13,14 @@ or:
1313
def my_output_formatter(data, request, response):
1414
# Custom output formatting code
1515

16-
Or, to specify an output_format for a specific endpoint, simply specify the output format within its router:
16+
By default, this only applies to the output format of HTTP responses.
17+
To change the output format of the command line interface:
18+
19+
@hug.default_output_format(cli=True, http=False)
20+
def my_output_formatter(data, request, response):
21+
# Custom output formatting code
22+
23+
To specify an output_format for a specific endpoint, simply specify the output format within its router:
1724

1825
@hug.get(output=hug.output_format.html)
1926
def my_endpoint():
@@ -42,6 +49,29 @@ Finally, an output format may be a collection of different output formats that g
4249

4350
In this case, if the endpoint is accessed via my_endpoint.js, the output type will be JSON; however if it's accessed via my_endoint.html, the output type will be HTML.
4451

52+
You can also change the default output format globally for all APIs with either:
53+
54+
@hug.default_output_format(apply_globally=True, cli=True, http=True)
55+
def my_output_formatter(data, request, response):
56+
# Custom output formatting code
57+
58+
or:
59+
60+
hug.defaults.output_format = hug.output_format.html # for HTTP
61+
hug.defaults.cli_output_format = hug.output_format.html # for the CLI
62+
63+
Note that when extending APIs, changing the default output format globally must be done before importing the modules of any of the sub-APIs:
64+
65+
hug.defaults.cli_output_format = hug.output_format.html
66+
67+
from my_app import my_sub_api
68+
69+
@hug.extend_api()
70+
def extended():
71+
return [my_sub_api]
72+
73+
74+
4575
Built-in hug output formats
4676
===================
4777

Diff for: hug/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
"""
2222
from __future__ import absolute_import
2323

24-
current = "2.4.5"
24+
current = "2.4.6"

Diff for: hug/api.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -305,9 +305,16 @@ def handle_404(request, response, *args, **kwargs):
305305
"Here's a definition of the API to help you get going :)")
306306
to_return['documentation'] = self.documentation(base_url, self.determine_version(request, False),
307307
prefix=url_prefix)
308-
response.data = hug.output_format.json(to_return, indent=4, separators=(',', ': '))
308+
309+
if self.output_format == hug.output_format.json:
310+
response.data = hug.output_format.json(to_return, indent=4, separators=(',', ': '))
311+
response.content_type = 'application/json; charset=utf-8'
312+
else:
313+
response.data = self.output_format(to_return)
314+
response.content_type = self.output_format.content_type
315+
309316
response.status = falcon.HTTP_NOT_FOUND
310-
response.content_type = 'application/json; charset=utf-8'
317+
311318
handle_404.interface = True
312319
return handle_404
313320

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def list_modules(dirname):
7575

7676
setup(
7777
name='hug',
78-
version='2.4.5',
78+
version='2.4.6',
7979
description='A Python framework that makes developing APIs '
8080
'as simple as possible, but no simpler.',
8181
long_description=long_description,

Diff for: tests/test_decorators.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -307,30 +307,32 @@ def accepts_get_and_post():
307307
assert 'method not allowed' in hug.test.trace(api, 'accepts_get_and_post').status.lower()
308308

309309

310-
def test_not_found():
310+
def test_not_found(hug_api):
311311
"""Test to ensure the not_found decorator correctly routes 404s to the correct handler"""
312-
@hug.not_found()
312+
@hug.not_found(api=hug_api)
313313
def not_found_handler():
314314
return "Not Found"
315315

316-
result = hug.test.get(api, '/does_not_exist/yet')
316+
result = hug.test.get(hug_api, '/does_not_exist/yet')
317317
assert result.data == "Not Found"
318318
assert result.status == falcon.HTTP_NOT_FOUND
319319

320-
@hug.not_found(versions=10) # noqa
320+
@hug.not_found(versions=10, api=hug_api) # noqa
321321
def not_found_handler(response):
322322
response.status = falcon.HTTP_OK
323323
return {'look': 'elsewhere'}
324324

325-
result = hug.test.get(api, '/v10/does_not_exist/yet')
325+
result = hug.test.get(hug_api, '/v10/does_not_exist/yet')
326326
assert result.data == {'look': 'elsewhere'}
327327
assert result.status == falcon.HTTP_OK
328328

329-
result = hug.test.get(api, '/does_not_exist/yet')
329+
result = hug.test.get(hug_api, '/does_not_exist/yet')
330330
assert result.data == "Not Found"
331331
assert result.status == falcon.HTTP_NOT_FOUND
332332

333-
del api.http._not_found_handlers
333+
hug_api.http.output_format = hug.output_format.text
334+
result = hug.test.get(hug_api, '/v10/does_not_exist/yet')
335+
assert result.data == "{'look': 'elsewhere'}"
334336

335337

336338
def test_not_found_with_extended_api():

0 commit comments

Comments
 (0)