From 5fb8f5d3e70619417db17db8e9d7ef130f44c08a Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Mon, 6 May 2019 15:47:16 +0300 Subject: [PATCH 1/6] Add Awesome Sanic list button (#1563) --- README.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index f63d9707..d98e8736 100644 --- a/README.rst +++ b/README.rst @@ -16,7 +16,7 @@ Sanic | Build fast. Run fast. * - Package - | |PyPI| |PyPI version| |Wheel| |Supported implementations| |Code style black| * - Support - - | |Forums| |Join the chat at https://gitter.im/sanic-python/Lobby| + - | |Forums| |Join the chat at https://gitter.im/sanic-python/Lobby| |Awesome| * - Stats - | |Downloads| @@ -44,6 +44,9 @@ Sanic | Build fast. Run fast. .. |Supported implementations| image:: https://img.shields.io/pypi/implementation/sanic.svg :alt: Supported implementations :target: https://pypi.python.org/pypi/sanic +.. |Awesome| image:: https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg + :alt: Awesome Sanic List + :target: https://github.com/mekicha/awesome-sanic .. |Downloads| image:: https://pepy.tech/badge/sanic/month :alt: Downloads :target: https://pepy.tech/project/sanic From 8e2a1a61a5986a5ba0c10f272884f72ce08faa14 Mon Sep 17 00:00:00 2001 From: Yun Xu Date: Tue, 7 May 2019 16:51:24 -0700 Subject: [PATCH 2/6] minor: fix readthedoc build --- environment.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/environment.yml b/environment.yml index aeca7c38..e9b832b4 100644 --- a/environment.yml +++ b/environment.yml @@ -13,6 +13,7 @@ dependencies: - sphinx==1.8.3 - sphinx_rtd_theme==0.4.2 - recommonmark==0.5.0 + - requests-async==0.4.0 - sphinxcontrib-asyncio>=0.2.0 - docutils==0.14 - pygments==2.3.1 From ec428135ce6251e860da672f7fa9105e2fb89c44 Mon Sep 17 00:00:00 2001 From: Ketan Patel Date: Tue, 7 May 2019 22:38:29 -0700 Subject: [PATCH 3/6] 1564 - Moving `processes` variable intialization before `sig_handler`. --- sanic/server.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index 81b68cb5..a2038e3c 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -842,6 +842,8 @@ def serve_multiple(server_settings, workers): server_settings["host"] = None server_settings["port"] = None + processes = [] + def sig_handler(signal, frame): logger.info("Received signal %s. Shutting down.", Signals(signal).name) for process in processes: @@ -850,8 +852,6 @@ def serve_multiple(server_settings, workers): signal_func(SIGINT, lambda s, f: sig_handler(s, f)) signal_func(SIGTERM, lambda s, f: sig_handler(s, f)) - processes = [] - for _ in range(workers): process = Process(target=serve, kwargs=server_settings) process.daemon = True From 900020ddc9a3173416131ebb974c183d7ccd57d8 Mon Sep 17 00:00:00 2001 From: Ketan Patel Date: Wed, 8 May 2019 00:40:40 -0700 Subject: [PATCH 4/6] developer guide enhancements. --- CONTRIBUTING.md | 70 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 77e9e4c5..1db3cdd4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,28 +34,84 @@ the document that explains the way `sanic` manages dependencies inside the `setu | 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: +## Running all tests +To run the tests for Sanic it is recommended to use tox like so: ```bash tox ``` - See it's that simple! +`tox.ini` contains different environments. Running `tox` without any arguments will +run all unittests, perform lint and other checks. + +## Run unittests : +`tox` environment -> `[testenv]` + +To execute only unittests, run `tox` with environment like so: + +```bash +tox -e py36 -v -- tests/test_config.py +# or +tox -e py37 -v -- tests/test_config.py +``` + +## Run lint checks : +`tox` environment -> `[testenv:lint]` + +Permform `flake8`, `black` and `isort` checks. +```bash +tox -e lint +``` + +## Run other checks : +`tox` environment -> `[testenv:check]` + +Perform other checks. +```bash +tox -e check +``` + +# Code Style +To maintain the code consistency, Sanic uses following tools. + +1. [isort](https://github.com/timothycrosley/isort) +2. [black](https://github.com/python/black) +2. [flake8](https://github.com/PyCQA/flake8) + + +## isort +`isort` sorts Python imports. It divides imports into three +categories sorted each in alphabetical order. + 1. built-in + 2. third-party + 3. project-specific + +## black +`black` is a Python code formatter. + +## flake8 +`flake8` is a Python style guide that wraps following tools into one. +1. PyFlakes +2. pycodestyle +3. Ned Batchelder's McCabe script + +`isort`, `black` and `flake8` checks are performed during `tox` lint checks. + +Refer [tox](https://tox.readthedocs.io/en/latest/index.html) documentation for more details. + ## Pull requests! So the pull request approval rules are pretty simple: 1. All pull requests must pass unit tests. 2. All pull requests must be reviewed and approved by at least -one current collaborator on the project. + one current collaborator on the project. 3. All pull requests must pass flake8 checks. 4. All pull requests must be consistent with the existing code. 5. If you decide to remove/change anything from any common interface -a deprecation message should accompany it. + a deprecation message should accompany it. 6. If you implement a new feature you should have at least one unit -test to accompany it. + test to accompany it. 7. An example must be one of the following: * Example of how to use Sanic * Example of how to use Sanic extensions From d4ef151cc45e3a338f2e2ae56e29d75096231024 Mon Sep 17 00:00:00 2001 From: Yun Xu Date: Thu, 9 May 2019 20:52:24 -0700 Subject: [PATCH 5/6] deprecation: deprecate the use of remove_route --- sanic/app.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sanic/app.py b/sanic/app.py index be0d45bc..baf20e5c 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -555,12 +555,20 @@ class Sanic: This method provides the app user a mechanism by which an already existing route can be removed from the :class:`Sanic` object + .. warning:: + remove_route is deprecated in v19.06 and will be removed from future versions. + :param uri: URL Path to be removed from the app :param clean_cache: Instruct sanic if it needs to clean up the LRU route cache :param host: IP address or FQDN specific to the host :return: None """ + warnings.warn( + "remove_route is deprecated and will be removed from future versions.", + DeprecationWarning, + stacklevel=2, + ) self.router.remove(uri, clean_cache, host) # Decorator From bd89c7f2692f376ea27df7068630261c33183cd0 Mon Sep 17 00:00:00 2001 From: Yun Xu Date: Thu, 9 May 2019 21:14:27 -0700 Subject: [PATCH 6/6] fix lint issue --- sanic/app.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sanic/app.py b/sanic/app.py index baf20e5c..ce8770bd 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -556,7 +556,8 @@ class Sanic: existing route can be removed from the :class:`Sanic` object .. warning:: - remove_route is deprecated in v19.06 and will be removed from future versions. + remove_route is deprecated in v19.06 and will be removed + from future versions. :param uri: URL Path to be removed from the app :param clean_cache: Instruct sanic if it needs to clean up the LRU @@ -565,7 +566,8 @@ class Sanic: :return: None """ warnings.warn( - "remove_route is deprecated and will be removed from future versions.", + "remove_route is deprecated and will be removed " + "from future versions.", DeprecationWarning, stacklevel=2, )