Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation Enhancements #1424

Merged
merged 20 commits into from
Dec 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
09678d6
add sanic app module documentations
harshanarayana Dec 7, 2018
1623d39
categorize the sanic extensions list
harshanarayana Dec 7, 2018
e6fba01
add documentation for cookies, exception, blueprint and handlers
harshanarayana Dec 8, 2018
939b5ea
update copyright date and add example section with category
harshanarayana Dec 8, 2018
e3dfce8
fix linter issues
harshanarayana Dec 8, 2018
f6355bd
add additional examples to documentation
harshanarayana Dec 8, 2018
efa77cf
add api documentation for router and server
harshanarayana Dec 8, 2018
e13053e
add automated calendar version manager
harshanarayana Dec 9, 2018
5189d8b
fix string formatting error in git commands for release script
harshanarayana Dec 9, 2018
9c6b835
add release note chnage log generation
harshanarayana Dec 9, 2018
b7702bc
add monitoring examples and documents
harshanarayana Dec 10, 2018
2d82b89
make release script black compliant and tweak documentation with inde…
harshanarayana Dec 15, 2018
c42c274
update manifest configuration
harshanarayana Dec 15, 2018
87ab0b3
fix current version in setup.cfg for relase script
harshanarayana Dec 15, 2018
4880761
add setuputil based test running and makefile support
harshanarayana Dec 18, 2018
82f7f84
cleanup requirements and move dependency inside setup.py
harshanarayana Dec 21, 2018
a80499c
update installation steps to be consistent across documentation and r…
harshanarayana Dec 22, 2018
de8c37a
fix pip install typo in contribution page
harshanarayana Dec 23, 2018
7005fab
add code beautification task to makefile
harshanarayana Dec 24, 2018
9bea23d
fix makefile phony targets
harshanarayana Dec 24, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ docs/_build/
docs/_api/
build/*
.DS_Store
dist/*
15 changes: 14 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,22 @@ So assume you have already cloned the repo and are in the working directory with
a virtual environment already set up, then run:

```bash
python setup.py develop && pip install -r requirements-dev.txt
pip3 install -e . "[.dev]"
```

# Dependency Changes

`Sanic` doesn't use `requirements*.txt` files to manage any kind of dependencies related to it in order to simplify the
effort required in managing the dependencies. Please make sure you have read and understood the following section of
the document that explains the way `sanic` manages dependencies inside the `setup.py` file.

| Dependency Type | Usage | Installation |
| ------------------------------------------| -------------------------------------------------------------------------- | --------------------------- |
| requirements | Bare minimum dependencies required for sanic to function | pip3 install -e . |
| tests_require / extras_require['test'] | Dependencies required to run the Unit Tests for `sanic` | pip3 install -e '[.test]' |
| extras_require['dev'] | Additional Development requirements to add contributing | pip3 install -e '[.dev]' |
| extras_require['docs'] | Dependencies required to enable building and enhancing sanic documentation | pip3 install -e '[.docs]' |

## Running tests

To run the tests for sanic it is recommended to use tox like so:
Expand Down
16 changes: 12 additions & 4 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
include README.rst
include MANIFEST.in
# Non Code related contents
include LICENSE
include README.rst
include pyproject.toml

# Setup
include setup.py
include Makefile

# Tests
include .coveragerc
graft tests

recursive-exclude * __pycache__
recursive-exclude * *.py[co]
global-exclude __pycache__
global-exclude *.py[co]
harshanarayana marked this conversation as resolved.
Show resolved Hide resolved
58 changes: 56 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,58 @@
test:
find . -name "*.pyc" -delete
.PHONY: help test test-coverage install docker-test black fix-import beautify

.DEFAULT: help

help:
@echo "Please use \`make <target>' where <target> is one of"
@echo "test"
@echo " Run Sanic Unit Tests"
@echo "test-coverage"
@echo " Run Sanic Unit Tests with Coverage"
@echo "install"
@echo " Install Sanic"
@echo "docker-test"
@echo " Run Sanic Unit Tests using Docker"
@echo "black"
@echo " Analyze and fix linting issues using Black"
@echo "fix-import"
@echo " Analyze and fix import order using isort"
@echo "beautify [sort_imports=1] [include_tests=1]"
@echo " Analyze and fix linting issue using black and optionally fix import sort using isort"
@echo ""

clean:
find . ! -path "./.eggs/*" -name "*.pyc" -exec rm {} \;
find . ! -path "./.eggs/*" -name "*.pyo" -exec rm {} \;
find . ! -path "./.eggs/*" -name ".coverage" -exec rm {} \;
rm -rf build/* > /dev/null 2>&1
rm -rf dist/* > /dev/null 2>&1

test: clean
python setup.py test

test-coverage: clean
python setup.py test --pytest-args="--cov sanic --cov-report term --cov-append "

install:
python setup.py install

docker-test: clean
docker build -t sanic/test-image -f docker/Dockerfile .
docker run -t sanic/test-image tox

beautify: black
ifdef sort_imports
ifdef include_tests
$(warning It is suggested that you do not run sort import on tests)
isort -rc sanic tests
else
$(info Sorting Imports)
isort -rc sanic
endif
endif

black:
black --config ./pyproject.toml sanic tests

fix-import: black
isort -rc sanic
23 changes: 12 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ Sanic is developed `on GitHub <https://github.com/huge-success/sanic/>`_. We als

If you have a project that utilizes Sanic make sure to comment on the `issue <https://github.com/huge-success/sanic/issues/396>`_ that we use to track those projects!

Installation
------------

- ``pip3 install sanic``

To install sanic without uvloop or ujson using bash, you can provide either or both of these environmental variables
using any truthy string like `'y', 'yes', 't', 'true', 'on', '1'` and setting the ``SANIC_NO_X`` (``X`` = ``UVLOOP``/``UJSON``)
to true will stop that features installation.

- ``SANIC_NO_UVLOOP=true SANIC_NO_UJSON=true pip install sanic``


Hello World Example
-------------------

Expand All @@ -65,17 +77,6 @@ Hello World Example
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000)

Installation
------------

- ``pip install sanic``

To install sanic without uvloop or ujson using bash, you can provide either or both of these environmental variables
using any truthy string like `'y', 'yes', 't', 'true', 'on', '1'` and setting the NO_X to true will stop that features
installation.

- ``SANIC_NO_UVLOOP=true SANIC_NO_UJSON=true pip install sanic``


Documentation
-------------
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

# General information about the project.
project = 'Sanic'
copyright = '2016, Sanic contributors'
copyright = '2018, Sanic contributors'
author = 'Sanic contributors'

# The version info for the project you're documenting, acts as replacement for
Expand Down
13 changes: 7 additions & 6 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,31 @@ Guides
:maxdepth: 2

sanic/getting_started
sanic/routing
sanic/config
sanic/logging
sanic/request_data
sanic/response
sanic/cookies
sanic/routing
sanic/blueprints
sanic/static_files
sanic/versioning
sanic/exceptions
sanic/middleware
sanic/blueprints
sanic/websocket
sanic/config
sanic/cookies
sanic/decorators
sanic/streaming
sanic/class_based_views
sanic/custom_protocol
sanic/sockets
sanic/ssl
sanic/logging
sanic/versioning
sanic/debug_mode
sanic/testing
sanic/deploying
sanic/extensions
sanic/contributing
sanic/api_reference
sanic/examples


Module Documentation
Expand Down
18 changes: 9 additions & 9 deletions docs/sanic/blueprints.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ app = Sanic(__name__)
app.blueprint(api)
```

## Using blueprints
## Using Blueprints

Blueprints have much the same functionality as an application instance.
Blueprints have almost the same functionality as an application instance.

### WebSocket routes

Expand Down Expand Up @@ -201,7 +201,7 @@ async def close_connection(app, loop):
Blueprints can be very useful for API versioning, where one blueprint may point
at `/v1/<routes>`, and another pointing at `/v2/<routes>`.

When a blueprint is initialised, it can take an optional `url_prefix` argument,
When a blueprint is initialised, it can take an optional `version` argument,
which will be prepended to all routes defined on the blueprint. This feature
can be used to implement our API versioning scheme.

Expand All @@ -210,8 +210,8 @@ can be used to implement our API versioning scheme.
from sanic.response import text
from sanic import Blueprint

blueprint_v1 = Blueprint('v1', url_prefix='/v1')
blueprint_v2 = Blueprint('v2', url_prefix='/v2')
blueprint_v1 = Blueprint('v1', url_prefix='/api', version="v1")
blueprint_v2 = Blueprint('v2', url_prefix='/api', version="v2")

@blueprint_v1.route('/')
async def api_v1_root(request):
Expand All @@ -222,7 +222,7 @@ async def api_v2_root(request):
return text('Welcome to version 2 of our documentation')
```

When we register our blueprints on the app, the routes `/v1` and `/v2` will now
When we register our blueprints on the app, the routes `/v1/api` and `/v2/api` will now
point to the individual blueprints, which allows the creation of *sub-sites*
for each API version.

Expand All @@ -232,8 +232,8 @@ from sanic import Sanic
from blueprints import blueprint_v1, blueprint_v2

app = Sanic(__name__)
app.blueprint(blueprint_v1, url_prefix='/v1')
app.blueprint(blueprint_v2, url_prefix='/v2')
app.blueprint(blueprint_v1)
app.blueprint(blueprint_v2)

app.run(host='0.0.0.0', port=8000, debug=True)
```
Expand All @@ -246,7 +246,7 @@ takes the format `<blueprint_name>.<handler_name>`. For example:
```python
@blueprint_v1.route('/')
async def root(request):
url = request.app.url_for('v1.post_handler', post_id=5) # --> '/v1/post/5'
url = request.app.url_for('v1.post_handler', post_id=5) # --> '/v1/api/post/5'
return redirect(url)


Expand Down
53 changes: 38 additions & 15 deletions docs/sanic/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,30 +85,53 @@ DB_USER = 'appuser'

Out of the box there are just a few predefined values which can be overwritten when creating the application.

| Variable | Default | Description |
| ------------------------- | --------- | ------------------------------------------------------ |
| REQUEST_MAX_SIZE | 100000000 | How big a request may be (bytes) |
| Variable | Default | Description |
| ------------------------- | --------- | --------------------------------------------------------- |
| REQUEST_MAX_SIZE | 100000000 | How big a request may be (bytes) |
| REQUEST_BUFFER_QUEUE_SIZE | 100 | Request streaming buffer queue size |
| REQUEST_TIMEOUT | 60 | How long a request can take to arrive (sec) |
| RESPONSE_TIMEOUT | 60 | How long a response can take to process (sec) |
| KEEP_ALIVE | True | Disables keep-alive when False |
| KEEP_ALIVE_TIMEOUT | 5 | How long to hold a TCP connection open (sec) |
| GRACEFUL_SHUTDOWN_TIMEOUT | 15.0 | How long take to force close non-idle connection (sec) |
| ACCESS_LOG | True | Disable or enable access log |
| REQUEST_TIMEOUT | 60 | How long a request can take to arrive (sec) |
| RESPONSE_TIMEOUT | 60 | How long a response can take to process (sec) |
| KEEP_ALIVE | True | Disables keep-alive when False |
| KEEP_ALIVE_TIMEOUT | 5 | How long to hold a TCP connection open (sec) |
| GRACEFUL_SHUTDOWN_TIMEOUT | 15.0 | How long to wait to force close non-idle connection (sec) |
| ACCESS_LOG | True | Disable or enable access log |

### The different Timeout variables:

A request timeout measures the duration of time between the instant when a new open TCP connection is passed to the Sanic backend server, and the instant when the whole HTTP request is received. If the time taken exceeds the `REQUEST_TIMEOUT` value (in seconds), this is considered a Client Error so Sanic generates a HTTP 408 response and sends that to the client. Adjust this value higher if your clients routinely pass very large request payloads or upload requests very slowly.
#### `REQUEST_TIMEOUT`

A response timeout measures the duration of time between the instant the Sanic server passes the HTTP request to the Sanic App, and the instant a HTTP response is sent to the client. If the time taken exceeds the `RESPONSE_TIMEOUT` value (in seconds), this is considered a Server Error so Sanic generates a HTTP 503 response and sets that to the client. Adjust this value higher if your application is likely to have long-running process that delay the generation of a response.
A request timeout measures the duration of time between the instant when a new open TCP connection is passed to the
Sanic backend server, and the instant when the whole HTTP request is received. If the time taken exceeds the
`REQUEST_TIMEOUT` value (in seconds), this is considered a Client Error so Sanic generates an `HTTP 408` response
and sends that to the client. Set this parameter's value higher if your clients routinely pass very large request payloads
or upload requests very slowly.

### What is Keep Alive? And what does the Keep Alive Timeout value do?
#### `RESPONSE_TIMEOUT`

Keep-Alive is a HTTP feature indroduced in HTTP 1.1. When sending a HTTP request, the client (usually a web browser application) can set a Keep-Alive header to indicate for the http server (Sanic) to not close the TCP connection after it has send the response. This allows the client to reuse the existing TCP connection to send subsequent HTTP requests, and ensures more efficient network traffic for both the client and the server.
A response timeout measures the duration of time between the instant the Sanic server passes the HTTP request to the
Sanic App, and the instant a HTTP response is sent to the client. If the time taken exceeds the `RESPONSE_TIMEOUT`
value (in seconds), this is considered a Server Error so Sanic generates an `HTTP 503` response and sends that to the
client. Set this parameter's value higher if your application is likely to have long-running process that delay the
generation of a response.

The `KEEP_ALIVE` config variable is set to `True` in Sanic by default. If you don't need this feature in your application, set it to `False` to cause all client connections to close immediately after a response is sent, regardless of the Keep-Alive header on the request.
#### `KEEP_ALIVE_TIMEOUT`

The amount of time the server holds the TCP connection open is decided by the server itself. In Sanic, that value is configured using the `KEEP_ALIVE_TIMEOUT` value. By default, it is set to 5 seconds, this is the same default setting as the Apache HTTP server and is a good balance between allowing enough time for the client to send a new request, and not holding open too many connections at once. Do not exceed 75 seconds unless you know your clients are using a browser which supports TCP connections held open for that long.
##### What is Keep Alive? And what does the Keep Alive Timeout value do?

`Keep-Alive` is a HTTP feature introduced in `HTTP 1.1`. When sending a HTTP request, the client (usually a web browser application)
can set a `Keep-Alive` header to indicate the http server (Sanic) to not close the TCP connection after it has send the response.
This allows the client to reuse the existing TCP connection to send subsequent HTTP requests, and ensures more efficient
network traffic for both the client and the server.

The `KEEP_ALIVE` config variable is set to `True` in Sanic by default. If you don't need this feature in your application,
set it to `False` to cause all client connections to close immediately after a response is sent, regardless of
the `Keep-Alive` header on the request.

The amount of time the server holds the TCP connection open is decided by the server itself.
In Sanic, that value is configured using the `KEEP_ALIVE_TIMEOUT` value. By default, it is set to 5 seconds.
This is the same default setting as the Apache HTTP server and is a good balance between allowing enough time for
the client to send a new request, and not holding open too many connections at once. Do not exceed 75 seconds unless
you know your clients are using a browser which supports TCP connections held open for that long.

For reference:
```
Expand Down
62 changes: 0 additions & 62 deletions docs/sanic/contributing.md

This file was deleted.

Loading