diff --git a/.github/workflows/tests-3.5.2.yaml b/.github/workflows/tests-3.5.2.yaml deleted file mode 100644 index fb7176e42..000000000 --- a/.github/workflows/tests-3.5.2.yaml +++ /dev/null @@ -1,40 +0,0 @@ -name: Run tests (CPython 3.5.2) - -on: - push: - branches: - - "*" - pull_request: - branches: - - master - -jobs: - run_tox: - name: tox -e py35 (3.5.2 on ubuntu-16.04) - runs-on: ubuntu-latest - - steps: - - name: Checkout repo - uses: actions/checkout@v2 - with: - fetch-depth: 2 - - - name: Run tox - uses: docker://ubuntu:16.04 - env: - DEBIAN_FRONTEND: noninteractive - with: - # NOTE(vytas): We upgrade pip in the venv in two steps, because 8.1.1 - # does not properly resolve python_requires. - args: | - /bin/bash -c " - apt-get update && - apt-get install -y build-essential python3.5 python3.5-dev python3-venv && - python3.5 -m venv venv && - source venv/bin/activate && - pip install -U 'pip < 20' && - pip install -U pip setuptools tox wheel && - python --version && - pip --version && - tox --version && - tox -e py35" diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 68dc6ce0b..9918d33a3 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -23,7 +23,7 @@ jobs: - "ubuntu-20.04" toxenv: - "pep8" - - "black" + - "blue" - "pep8-examples" - "pep8-docstrings" - "mypy" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fdab3127b..6a1ee439a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,13 +26,15 @@ Please note that all contributors and maintainers of this project are subject to ### Pull Requests -Before submitting a pull request, please ensure you have added or updated tests as appropriate, and that all existing tests still pass with your changes. Please also ensure that your coding style follows PEP 8 and the ``black`` formatting style. +Before submitting a pull request, please ensure you have added or updated tests as appropriate, +and that all existing tests still pass with your changes. +Please also ensure that your coding style follows PEP 8 and the ``blue`` formatting style. -In order to reformat your code with ``black``, simply issue: +In order to reformat your code with ``blue``, simply issue: ```bash -$ pip install -U black -$ black . +$ pip install -U blue +$ blue . ``` You can check all this by running ``tox`` from within the Falcon project directory. Your environment must be based on CPython 3.8 or 3.10: diff --git a/README.rst b/README.rst index 4a7f88153..1d1ab9e8d 100644 --- a/README.rst +++ b/README.rst @@ -8,7 +8,7 @@ > -|Build Status| |Docs| |codecov.io| +|Build Status| |Docs| |codecov.io| |Blue| The Falcon Web Framework ======================== @@ -1045,10 +1045,10 @@ limitations under the License. .. |Docs| image:: https://readthedocs.org/projects/falcon/badge/?version=stable :target: https://falcon.readthedocs.io/en/stable/?badge=stable :alt: Falcon web framework docs -.. |Runner| image:: https://a248.e.akamai.net/assets.github.com/images/icons/emoji/runner.png - :width: 20 - :height: 20 .. |Build Status| image:: https://github.com/falconry/falcon/workflows/Run%20tests/badge.svg :target: https://github.com/falconry/falcon/actions?query=workflow%3A%22Run+tests%22 .. |codecov.io| image:: https://codecov.io/gh/falconry/falcon/branch/master/graphs/badge.svg :target: http://codecov.io/gh/falconry/falcon +.. |Blue| image:: https://img.shields.io/badge/code%20style-blue-blue.svg + :target: https://blue.readthedocs.io/ + :alt: code style: blue diff --git a/docs/conf.py b/docs/conf.py index f78b4c1dc..d0f1afeb2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -84,7 +84,7 @@ # General information about the project. project = 'Falcon' -copyright = "{year} Falcon Contributors".format(year=datetime.utcnow().year) +copyright = '{year} Falcon Contributors'.format(year=datetime.utcnow().year) # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the diff --git a/docs/ext/rfc.py b/docs/ext/rfc.py index 9fa616852..5288c43a3 100644 --- a/docs/ext/rfc.py +++ b/docs/ext/rfc.py @@ -18,7 +18,6 @@ formatted like this:: RFC 7231; Section 6.5.3 - """ import re diff --git a/falcon/__init__.py b/falcon/__init__.py index b4c84a74d..ff300975c 100644 --- a/falcon/__init__.py +++ b/falcon/__init__.py @@ -21,7 +21,6 @@ import falcon app = falcon.App() - """ import logging as _logging diff --git a/falcon/errors.py b/falcon/errors.py index a26473e8d..d5502d7a1 100644 --- a/falcon/errors.py +++ b/falcon/errors.py @@ -32,7 +32,6 @@ def on_get(self, req, resp): ) # -- snip -- - """ from datetime import datetime diff --git a/falcon/response_helpers.py b/falcon/response_helpers.py index c148a5c22..2570a8ff4 100644 --- a/falcon/response_helpers.py +++ b/falcon/response_helpers.py @@ -115,8 +115,8 @@ def format_content_disposition(value, disposition_type='attachment'): def format_etag_header(value): """Format an ETag header, wrap it with " " in case of need.""" - if value[-1] != '\"': - value = '\"' + value + '\"' + if value[-1] != '"': + value = '"' + value + '"' return value diff --git a/falcon/testing/helpers.py b/falcon/testing/helpers.py index 15678e439..b11f7f6c7 100644 --- a/falcon/testing/helpers.py +++ b/falcon/testing/helpers.py @@ -20,7 +20,6 @@ from falcon import testing wsgi_environ = testing.create_environ() - """ import asyncio @@ -303,8 +302,8 @@ class ASGIResponseEventCollector: ] ) - _HEADER_NAME_RE = re.compile(br'^[a-zA-Z][a-zA-Z0-9\-_]*$') - _BAD_HEADER_VALUE_RE = re.compile(br'[\000-\037]') + _HEADER_NAME_RE = re.compile(rb'^[a-zA-Z][a-zA-Z0-9\-_]*$') + _BAD_HEADER_VALUE_RE = re.compile(rb'[\000-\037]') def __init__(self): self.events = [] @@ -802,7 +801,7 @@ def get_encoding_from_headers(headers): content_type, params = cgi.parse_header(content_type) if 'charset' in params: - return params['charset'].strip("'\"") + return params['charset'].strip('\'"') # NOTE(kgriffs): Added checks for text/event-stream and application/json if content_type in ('text/event-stream', 'application/json'): diff --git a/falcon/testing/resource.py b/falcon/testing/resource.py index b59d719e4..c20854a3e 100644 --- a/falcon/testing/resource.py +++ b/falcon/testing/resource.py @@ -21,7 +21,6 @@ from falcon import testing resource = testing.SimpleTestResource() - """ from json import dumps as json_dumps diff --git a/falcon/util/__init__.py b/falcon/util/__init__.py index 28f94075b..cd3eca388 100644 --- a/falcon/util/__init__.py +++ b/falcon/util/__init__.py @@ -17,7 +17,6 @@ some_uri = '...' decoded_uri = uri.decode(some_uri) - """ from http import cookies as http_cookies diff --git a/falcon/util/misc.py b/falcon/util/misc.py index 7835fc32b..4cdc7c5b2 100644 --- a/falcon/util/misc.py +++ b/falcon/util/misc.py @@ -21,7 +21,6 @@ import falcon now = falcon.http_now() - """ import datetime diff --git a/falcon/util/structures.py b/falcon/util/structures.py index cbef19b6d..13025cf4d 100644 --- a/falcon/util/structures.py +++ b/falcon/util/structures.py @@ -24,7 +24,6 @@ import falcon things = falcon.CaseInsensitiveDict() - """ from collections.abc import Mapping diff --git a/falcon/util/time.py b/falcon/util/time.py index 99f245539..b4286ff31 100644 --- a/falcon/util/time.py +++ b/falcon/util/time.py @@ -7,7 +7,6 @@ import falcon tz = falcon.TimezoneGMT() - """ import datetime diff --git a/falcon/util/uri.py b/falcon/util/uri.py index 049504637..601b5ee72 100644 --- a/falcon/util/uri.py +++ b/falcon/util/uri.py @@ -21,7 +21,6 @@ from falcon import uri name, port = uri.parse_host('example.org:8080') - """ from falcon.constants import PYPY diff --git a/pyproject.toml b/pyproject.toml index 54b3abd9b..c27d9f7f1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,14 @@ showcontent = true [tool.black] + # this is kept to avoid reformatting all the code if one were to + # inadvertently run black on the probject target-version = ["py35"] skip-string-normalization = true line-length = 88 extend-exclude = "falcon/vendor" + +[tool.blue] + target-version = ["py35"] + line-length = 88 + extend-exclude = "falcon/vendor" diff --git a/tests/test_headers.py b/tests/test_headers.py index dc1cb83f9..71cced44c 100644 --- a/tests/test_headers.py +++ b/tests/test_headers.py @@ -233,7 +233,7 @@ def __init__(self, with_double_quotes): def on_get(self, req, resp): etag = 'fa0d1a60ef6616bb28038515c8ea4cb2' if self.with_double_quotes: - etag = '\"' + etag + '\"' + etag = '"' + etag + '"' resp.etag = etag assert resp.etag == '"fa0d1a60ef6616bb28038515c8ea4cb2"' diff --git a/tests/test_request_access_route.py b/tests/test_request_access_route.py index ebed7aecb..202dac223 100644 --- a/tests/test_request_access_route.py +++ b/tests/test_request_access_route.py @@ -46,7 +46,7 @@ def test_rfc_forwarded(asgi): 'for="[2001:db8:cafe::17]:555",' 'for=x,' 'for="unknown", by=_hidden,for="\\"\\\\",' - 'for="_don\\\"t_\\try_this\\\\at_home_\\42",' + 'for="_don\\"t_\\try_this\\\\at_home_\\42",' 'for="198\\.51\\.100\\.17\\:1236";' 'proto=https;host=example.com' ) diff --git a/tests/test_response_body.py b/tests/test_response_body.py index 13b455ab2..0f3fadd3a 100644 --- a/tests/test_response_body.py +++ b/tests/test_response_body.py @@ -97,7 +97,7 @@ async def __anext__(self): class CodeResource: def on_get(self, req, resp): resp.content_type = 'text/x-malbolge' - resp.media = '\'&%$#"!76543210/43,P0).\'&%I6' + resp.media = "'&%$#\"!76543210/43,P0).'&%I6" resp.status = falcon.HTTP_725 diff --git a/tox.ini b/tox.ini index 02cb334be..7c4f40e76 100644 --- a/tox.ini +++ b/tox.ini @@ -13,7 +13,7 @@ # -------------------------------------------------------------------- envlist = cleanup, - black, + blue, pep8, mypy, mintest, @@ -264,9 +264,9 @@ deps = flake8>=3.7.0 flake8-import-order commands = flake8 [] -[testenv:black] -deps = black>=22.1.0 -commands = black --check . [] +[testenv:blue] +deps = blue>=0.9.0 +commands = blue --check . [] [testenv:pep8-docstrings] deps = flake8