Skip to content

Commit

Permalink
style: Apply isort pre-commit hook (#174)
Browse files Browse the repository at this point in the history
As well as update dev Python version to 3.9.5 and bump all other
pre-commit hooks.

Also fix CI workflow to ensure that pre-commit hooks and `py39-prev` tox
env run for dev Python version.
  • Loading branch information
playpauseandstop committed May 9, 2021
1 parent 8337c0c commit 979c4ce
Show file tree
Hide file tree
Showing 26 changed files with 70 additions and 52 deletions.
29 changes: 10 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ on:

env:
BADABUMP_VERSION: "21.1.0"
COMMITIZEN_VERSION: "2.16.0"
COMMITIZEN_VERSION: "2.17.6"
COVERALLS_VERSION: "3.0.1"
DEV_PYTHON_VERSION: "3.9.2"
POETRY_VERSION: "1.1.5"
TOX_GH_ACTIONS_VERSION: "2.4.0"
TOX_VERSION: "3.23.0"
TWINE_VERSION: "3.3.0"
DEV_PYTHON_VERSION: "3.9.5"
POETRY_VERSION: "1.1.6"
TOX_GH_ACTIONS_VERSION: "2.5.0"
TOX_VERSION: "3.23.1"
TWINE_VERSION: "3.4.1"

jobs:
dev:
Expand Down Expand Up @@ -97,11 +97,11 @@ jobs:
python3 -m pip install tox==${{ env.TOX_VERSION }} tox-gh-actions==${{ env.TOX_GH_ACTIONS_VERSION }}
- name: "Run pre-commit"
if: "matrix.python-version == env.DEV_PYTHON_VERSION"
if: "startsWith(env.DEV_PYTHON_VERSION, matrix.python-version)"
uses: "pre-commit/action@v2.0.3"

- name: "Validate OpenAPI schemas"
if: "matrix.python-version == env.DEV_PYTHON_VERSION"
if: "startsWith(env.DEV_PYTHON_VERSION, matrix.python-version)"
run: |
set -e
poetry run python3 -m openapi_spec_validator ./examples/hobotnica/src/hobotnica/openapi.yaml
Expand All @@ -117,22 +117,13 @@ jobs:
REDIS_URL: "redis://localhost:${{ job.services.redis.ports[6379] }}/0"
run: "python3 -m tox"

- name: "Run tests with attrs 19.3.0 & openapi-core 0.13.3"
if: "matrix.python-version == env.DEV_PYTHON_VERSION"
env:
TOXENV: "py39-prev"
PYTEST_ADDOPTS: "--no-cov"
PYTHONPATH: "./examples/hobotnica/src:./examples/petstore/src:./examples/simulations/src:./examples/todobackend/src"
REDIS_URL: "redis://localhost:${{ job.services.redis.ports[6379] }}/0"
run: "python3 -m tox"

- name: "Send report to coveralls"
if: "matrix.python-version == env.DEV_PYTHON_VERSION"
if: "startsWith(env.DEV_PYTHON_VERSION, matrix.python-version)"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
run: |
python3 -m pip install coveralls==${{ env.COVERALLS_VERSION }}
python3 -m coveralls
python3 -m coveralls --service=github
package:
needs: ["test"]
Expand Down
29 changes: 18 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ default_language_version:
minimum_pre_commit_version: "1.17.0"
repos:
- repo: "https://github.com/commitizen-tools/commitizen"
rev: "v2.16.0"
rev: "v2.17.6"
hooks:
- id: "commitizen"
# By default commitizen using `python3` instead `python` language, so
# needed to provide concrete version here as well
language_version: "python3.9"
stages: ["commit-msg"]

- repo: "https://github.com/PyCQA/isort"
rev: "5.8.0"
hooks:
- id: "isort"
name: "Format backend code (isort)"
exclude: ^docs/.*$

- repo: "https://github.com/psf/black"
rev: "20.8b1"
rev: "21.5b0"
hooks:
- id: "black"
# By default black using `python3` instead `python` language, so
Expand All @@ -28,7 +35,7 @@ repos:
name: "Format docs (blacken-docs)"
args: ["-l", "64"]
additional_dependencies:
- "black==20.8b1"
- "black==21.5b0"

- repo: "https://github.com/pre-commit/pre-commit-hooks"
rev: "v3.4.0"
Expand All @@ -39,21 +46,21 @@ repos:
- id: "check-toml"
- id: "check-yaml"

- repo: "https://gitlab.com/PyCQA/flake8"
rev: "3.8.4"
- repo: "https://github.com/PyCQA/flake8"
rev: "3.9.2"
hooks:
- id: "flake8"
name: "Lint code (flake8)"
additional_dependencies: &flake8_additional_dependencies
- "flake8==3.8.4"
- "flake8==3.9.2"
- "flake8-broken-line==0.3.0"
- "flake8-bugbear==21.3.2"
- "flake8-bugbear==21.4.3"
- "flake8-builtins==1.5.3"
- "flake8-comprehensions==3.3.1"
- "flake8-comprehensions==3.4.0"
- "flake8-eradicate==1.0.0"
- "flake8-import-order==0.18.1"
- "flake8-isort==4.0.0"
- "flake8-mutable==1.2.0"
- "flake8-pie==0.6.1"
- "flake8-pie==0.11.0"
- "flake8-quotes==3.2.0"
- "flake8-string-format==0.3.0"
- "flake8-tidy-imports==4.2.1"
Expand All @@ -62,7 +69,7 @@ repos:
exclude: ^docs/.*$

- repo: "https://github.com/asottile/yesqa"
rev: "v1.2.2"
rev: "v1.2.3"
hooks:
- id: yesqa
name: "Lint code (yesqa)"
Expand Down
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.9.2
3.9.5
1 change: 1 addition & 0 deletions examples/hobotnica/src/hobotnica/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
)

from rororo import BaseSettings, setup_openapi, setup_settings

from . import views


Expand Down
1 change: 1 addition & 0 deletions examples/hobotnica/src/hobotnica/auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from rororo.openapi.exceptions import InvalidCredentials

from .data import GITHUB_PERSONAL_TOKEN, GITHUB_USERNAME


Expand Down
1 change: 1 addition & 0 deletions examples/hobotnica/src/hobotnica/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from rororo import openapi_context
from rororo.annotations import Handler

from .auth import authenticate


Expand Down
1 change: 1 addition & 0 deletions examples/hobotnica/src/hobotnica/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from rororo import openapi_context, OperationTableDef
from rororo.openapi.exceptions import ObjectDoesNotExist

from .data import ENVIRONMENT_VARS, GITHUB_REPOSITORIES
from .decorators import login_required

Expand Down
1 change: 1 addition & 0 deletions examples/petstore/src/petstore/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from aiohttp import web

from rororo import setup_openapi, setup_settings

from . import views
from .settings import Settings

Expand Down
1 change: 1 addition & 0 deletions examples/petstore/src/petstore/shortcuts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import List

from rororo.openapi.exceptions import ObjectDoesNotExist

from .data import Pet


Expand Down
1 change: 1 addition & 0 deletions examples/petstore/src/petstore/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from rororo import openapi_context, OperationTableDef
from rororo.openapi import get_validated_data, get_validated_parameters

from .data import NewPet
from .shortcuts import get_pet_or_404

Expand Down
1 change: 1 addition & 0 deletions examples/simulations/src/simulations/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from rororo import get_validated_data, OperationTableDef, setup_openapi
from rororo.openapi.openapi import get_default_yaml_loader

from .storage import DEFAULT_STORAGE


Expand Down
1 change: 1 addition & 0 deletions examples/todobackend/src/todobackend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from rororo import setup_openapi, setup_settings
from rororo.settings import APP_SETTINGS_KEY

from . import views
from .constants import APP_REDIS_KEY, APP_STORAGE_KEY
from .settings import Settings
Expand Down
1 change: 1 addition & 0 deletions examples/todobackend/src/todobackend/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from rororo import openapi_context
from rororo.openapi.exceptions import ObjectDoesNotExist

from .constants import APP_STORAGE_KEY
from .data import Todo
from .storage import Storage
Expand Down
1 change: 1 addition & 0 deletions examples/todobackend/src/todobackend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from aiohttp import web

from rororo import openapi_context, OperationTableDef

from .constants import APP_STORAGE_KEY
from .data import Todo
from .storage import Storage
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ fail_under = 95
skip_covered = true
show_missing = true

[tool.isort]
profile = "attrs"
combine_as_imports = true
force_alphabetical_sort_within_sections = true
lines_between_types = 0
virtual_env = "./.venv/"

[tool.poetry]
name = "rororo"
version = "2.2.0"
Expand Down Expand Up @@ -54,7 +61,7 @@ classifiers = [
python = "^3.6"
aiohttp = "^3.5"
aiohttp-middlewares = "^1.1.0"
attrs = ">=19.1,<21"
attrs = ">=19.2.0,<21"
contextvars = {python = "<3.7", version = "^2.4"}
email-validator = "^1.0.5"
environ-config = ">=20.1,<22.0"
Expand All @@ -77,7 +84,7 @@ pytest-env = "^0.6.2"
"Bug Tracker" = "https://github.com/playpauseandstop/rororo/issues"

[tool.pytest.ini_options]
minversion = "6.1.2"
minversion = "6.2.3"
testpaths = ["tests/"]
addopts = "--cov --no-cov-on-fail"
env = """
Expand Down Expand Up @@ -115,7 +122,7 @@ commands =
[testenv:py39-prev]
commands_pre =
poetry install
poetry run python -m pip install attrs==19.3.0 openapi-core==0.13.3
poetry run python -m pip install attrs==19.2.0 environ-config==20.1.0 openapi-core==0.13.3 pyrsistent==0.16
"""

[build-system]
Expand Down
1 change: 1 addition & 0 deletions src/rororo/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import types
from typing import Any, Callable, Dict, Mapping, Type, TypeVar, Union


try:
from typing_extensions import Literal, Protocol, TypedDict
except ImportError:
Expand Down
2 changes: 1 addition & 1 deletion src/rororo/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .annotations import DictStrAny


class IgnoreErrorsFilter(object):
class IgnoreErrorsFilter:
"""Ignore all warnings and errors from stdout handler."""

def filter(self, record: logging.LogRecord) -> bool: # noqa: A003
Expand Down
2 changes: 1 addition & 1 deletion src/rororo/openapi/core_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from openapi_core.validation.response.datatypes import OpenAPIResponse
from yarl import URL

from ..annotations import Handler
from .constants import HANDLER_OPENAPI_MAPPING_KEY
from .exceptions import OperationError
from .utils import get_openapi_spec
from ..annotations import Handler


def find_core_operation(
Expand Down
2 changes: 1 addition & 1 deletion src/rororo/openapi/core_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
)
from openapi_schema_validator._format import oas30_format_checker

from ..annotations import MappingStrAny
from .annotations import ValidateEmailKwargsDict
from .data import OpenAPIParameters, to_openapi_parameters
from .exceptions import CastError, ValidationError
from .security import validate_security
from .utils import get_base_url
from ..annotations import MappingStrAny


DATE_TIME_FORMATTER = Formatter.from_callables(
Expand Down
2 changes: 1 addition & 1 deletion src/rororo/openapi/middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from aiohttp_middlewares import error_middleware, get_error_response
from aiohttp_middlewares.annotations import Middleware

from ..annotations import DictStrAny, Handler
from .constants import REQUEST_CORE_OPERATION_KEY
from .core_data import find_core_operation
from .validators import validate_request, validate_response
from ..annotations import DictStrAny, Handler


def get_actual_handler(handler: Handler) -> Handler:
Expand Down
20 changes: 10 additions & 10 deletions src/rororo/openapi/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@
from pyrsistent import pmap
from yarl import URL

from ..annotations import (
DictStrAny,
DictStrStr,
F,
Handler,
Protocol,
TypedDict,
ViewType,
)
from ..settings import APP_SETTINGS_KEY, BaseSettings
from . import views
from .annotations import SecurityDict, ValidateEmailKwargsDict
from .constants import (
Expand All @@ -43,16 +53,6 @@
from .exceptions import ConfigurationError
from .middlewares import openapi_middleware
from .utils import add_prefix
from ..annotations import (
DictStrAny,
DictStrStr,
F,
Handler,
Protocol,
TypedDict,
ViewType,
)
from ..settings import APP_SETTINGS_KEY, BaseSettings


SchemaLoader = Callable[[bytes], DictStrAny]
Expand Down
2 changes: 1 addition & 1 deletion src/rororo/openapi/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from openapi_core.validation.request.validators import RequestValidator
from pyrsistent import pmap

from ..annotations import MappingStrAny
from .annotations import SecurityDict
from .exceptions import BasicSecurityError, SecurityError
from ..annotations import MappingStrAny


AUTHORIZATION_HEADER = hdrs.AUTHORIZATION
Expand Down
2 changes: 1 addition & 1 deletion src/rororo/openapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from openapi_core.validation.request.datatypes import OpenAPIRequest
from yarl import URL

from ..annotations import DictStrAny
from .annotations import ValidateEmailKwargsDict
from .constants import (
APP_OPENAPI_SCHEMA_KEY,
Expand All @@ -15,7 +16,6 @@
)
from .data import OpenAPIContext, OpenAPIParameters
from .exceptions import ConfigurationError, ContextError
from ..annotations import DictStrAny


def add_prefix(path: str, prefix: Optional[str]) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/rororo/openapi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from aiohttp import web
from aiohttp_middlewares import error_context

from ..annotations import MappingStrStr
from .exceptions import ConfigurationError, OpenAPIError
from .utils import get_openapi_schema
from ..annotations import MappingStrStr


logger = logging.getLogger(__name__)
Expand Down

0 comments on commit 979c4ce

Please sign in to comment.