Skip to content

Enforce latests syntax on CI #351

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

Merged
merged 3 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
14 changes: 14 additions & 0 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:

jobs:
test:
name: "Tests"
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -31,3 +32,16 @@ jobs:
run: python setup.py test
- name: Upload coverage
uses: codecov/codecov-action@v1

static-checks:
name: "Static checks"
runs-on: ubuntu-latest
steps:
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
uses: actions/checkout@v2
- name: "Setup Python"
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: "Run static checks"
uses: pre-commit/[email protected]
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
default_stages: [commit, push]
default_language_version:
# force all unspecified python hooks to run python3
python: python3
minimum_pre_commit_version: "1.20.0"
repos:
- repo: meta
hooks:
- id: check-hooks-apply
- repo: https://github.com/asottile/pyupgrade
rev: v2.19.0
hooks:
- id: pyupgrade
args: ["--py36-plus"]
exclude: ^airflow/_vendor/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line to remove

- repo: local
hooks:
- id: flynt
name: Convert to f-strings with flynt
entry: flynt
language: python
additional_dependencies: ['flynt==0.64']
28 changes: 28 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Contributor Guide
=================

# Static checks

The project uses static checks using fantastic [pre-commit](https://pre-commit.com/). Every change is checked on CI and if it does not pass the tests it cannot be accepted. If you want to check locally then run following command to install pre-commit:

```bash
pip install -r requiremenets_dev.txt
```

To turn on pre-commit checks for commit operations in git, enter:
```bash
pre-commit install
```

To run all checks on your staged files, enter:
```bash
pre-commit run
```

To run all checks on all files, enter:
```bash
pre-commit run --all-files
```

Pre-commit check results are also attached to your PR through integration with Github Action.
1 change: 0 additions & 1 deletion openapi_core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""OpenAPI core module"""
from openapi_core.shortcuts import (
create_spec, validate_request, validate_response,
Expand Down
3 changes: 1 addition & 2 deletions openapi_core/casting/schemas/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ class CastError(OpenAPIError):
type: str

def __str__(self):
return "Failed to cast value to {type} type: {value}".format(
type=self.type, value=self.value)
return f"Failed to cast value to {self.type} type: {self.value}"
2 changes: 1 addition & 1 deletion openapi_core/contrib/django/backports.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def parse_header_name(cls, header):


def request_current_scheme_host(req):
return '{}://{}'.format(req.scheme, req.get_host())
return f'{req.scheme}://{req.get_host()}'
10 changes: 4 additions & 6 deletions openapi_core/deserializing/media_types/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ def data_form_loads(value):
value = value.decode('ASCII', errors='surrogateescape')
parser = Parser()
parts = parser.parsestr(value, headersonly=False)
return dict(
(
part.get_param('name', header='content-disposition'),
part.get_payload(decode=True),
)
return {
part.get_param('name', header='content-disposition'):
part.get_payload(decode=True)
for part in parts.get_payload()
)
}
11 changes: 6 additions & 5 deletions openapi_core/deserializing/parameters/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class ParameterDeserializeError(BaseParameterDeserializeError):

def __str__(self):
return (
"Failed to deserialize value "
"of {location} parameter with style {style}: {value}"
).format(location=self.location, style=self.style, value=self.value)
"Failed to deserialize value of "
f"{self.location} parameter with style {self.style}: {self.value}"
)


@dataclass(init=False)
Expand All @@ -31,5 +31,6 @@ def __init__(self, name):
self.name = name

def __str__(self):
return "Value of {name} {location} parameter cannot be empty".format(
name=self.name, location=self.location)
return (
f"Value of {self.name} {self.location} parameter cannot be empty"
)
10 changes: 4 additions & 6 deletions openapi_core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ class MissingHeader(MissingHeaderError):
name: str

def __str__(self):
return "Missing header (without default value): {0}".format(
self.name)
return f"Missing header (without default value): {self.name}"


@dataclass
class MissingRequiredHeader(MissingHeaderError):
name: str

def __str__(self):
return "Missing required header: {0}".format(self.name)
return f"Missing required header: {self.name}"


class OpenAPIParameterError(OpenAPIError):
Expand All @@ -49,16 +48,15 @@ class MissingParameter(MissingParameterError):
name: str

def __str__(self):
return "Missing parameter (without default value): {0}".format(
self.name)
return f"Missing parameter (without default value): {self.name}"


@dataclass
class MissingRequiredParameter(MissingParameterError):
name: str

def __str__(self):
return "Missing required parameter: {0}".format(self.name)
return f"Missing required parameter: {self.name}"


class OpenAPIRequestBodyError(OpenAPIError):
Expand Down
2 changes: 1 addition & 1 deletion openapi_core/security/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ def __call__(self, request):
scheme = self.scheme['scheme']
if auth_type.lower() != scheme:
raise SecurityError(
'Unknown authorization method %s' % auth_type)
f'Unknown authorization method {auth_type}')

return encoded_credentials
6 changes: 3 additions & 3 deletions openapi_core/templating/media_types/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ class MediaTypeNotFound(MediaTypeFinderError):

def __str__(self):
return (
"Content for the following mimetype not found: {0}. "
"Valid mimetypes: {1}"
).format(self.mimetype, self.availableMimetypes)
f"Content for the following mimetype not found: {self.mimetype}. "
f"Valid mimetypes: {self.availableMimetypes}"
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add newline at the end of file

7 changes: 3 additions & 4 deletions openapi_core/templating/paths/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PathNotFound(PathError):
url: str

def __str__(self):
return "Path not found for {0}".format(self.url)
return f"Path not found for {self.url}"


@dataclass
Expand All @@ -23,8 +23,7 @@ class OperationNotFound(PathError):
method: str

def __str__(self):
return "Operation {0} not found for {1}".format(
self.method, self.url)
return f"Operation {self.method} not found for {self.url}"


@dataclass
Expand All @@ -33,4 +32,4 @@ class ServerNotFound(PathError):
url: str

def __str__(self):
return "Server not found for {0}".format(self.url)
return f"Server not found for {self.url}"
2 changes: 1 addition & 1 deletion openapi_core/templating/responses/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ class ResponseNotFound(ResponseFinderError):
availableresponses: List[str]

def __str__(self):
return "Unknown response http status: {0}".format(
return "Unknown response http status: {}".format(
str(self.http_status))
2 changes: 1 addition & 1 deletion openapi_core/templating/responses/finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def find(self, http_status='default'):
return self.responses / http_status

# try range
http_status_range = '{0}XX'.format(http_status[0])
http_status_range = f'{http_status[0]}XX'
if http_status_range in self.responses:
return self.responses / http_status_range

Expand Down
3 changes: 1 addition & 2 deletions openapi_core/unmarshalling/schemas/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,4 @@ class FormatterNotFoundError(UnmarshallerError):
type_format: str

def __str__(self):
return "Formatter not found for {format} format".format(
format=self.type_format)
return f"Formatter not found for {self.type_format} format"
2 changes: 1 addition & 1 deletion openapi_core/validation/request/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _get_parameter(self, param, request):
deprecated = param.getkey('deprecated', False)
if deprecated:
warnings.warn(
"{0} parameter is deprecated".format(name),
f"{name} parameter is deprecated",
DeprecationWarning,
)

Expand Down
2 changes: 1 addition & 1 deletion openapi_core/validation/response/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _get_header(self, name, header, response):
deprecated = header.getkey('deprecated', False)
if deprecated:
warnings.warn(
"{0} header is deprecated".format(name),
f"{name} header is deprecated",
DeprecationWarning,
)

Expand Down
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ webob
strict-rfc3339==0.7
sphinx==4.0.2
sphinx-rtd-theme==0.5.2
pre-commit
2 changes: 0 additions & 2 deletions tests/integration/schema/test_link_spec.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import division

from openapi_core.shortcuts import create_spec


Expand Down
2 changes: 0 additions & 2 deletions tests/integration/schema/test_path_params.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import division

import pytest

from openapi_core.shortcuts import create_spec
Expand Down
1 change: 0 additions & 1 deletion tests/integration/schema/test_spec.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import division
import pytest
from base64 import b64encode

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/validation/test_petstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ def test_get_pet(self, spec, response_validator):
}
auth = 'authuser'
headers = {
'Authorization': 'Basic {auth}'.format(auth=auth),
'Authorization': f'Basic {auth}',
}
request = MockRequest(
host_url, 'GET', '/pets/1',
Expand Down
9 changes: 4 additions & 5 deletions tests/unit/templating/test_paths_finders.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import division
import pytest

from openapi_core.spec.paths import SpecPath
Expand Down Expand Up @@ -226,7 +225,7 @@ class BaseTestVariableValid:

@pytest.mark.parametrize('version', ['v1', 'v2'])
def test_variable(self, finder, spec, version):
request_uri = '/{0}/resource'.format(version)
request_uri = f'/{version}/resource'
method = 'get'
request = MockRequest(
'http://petstore.swagger.io', method, request_uri)
Expand All @@ -247,7 +246,7 @@ class BaseTestPathVariableValid:

@pytest.mark.parametrize('res_id', ['111', '222'])
def test_path_variable(self, finder, spec, res_id):
request_uri = '/resource/{0}'.format(res_id)
request_uri = f'/resource/{res_id}'
method = 'get'
request = MockRequest(
'http://petstore.swagger.io', method, request_uri)
Expand Down Expand Up @@ -476,7 +475,7 @@ def paths(self, path, path_2):

def test_valid(self, finder, spec):
token_id = '123'
request_uri = '/keys/{0}/tokens'.format(token_id)
request_uri = f'/keys/{token_id}/tokens'
method = 'get'
request = MockRequest(
'http://petstore.swagger.io', method, request_uri)
Expand Down Expand Up @@ -578,7 +577,7 @@ def paths(self, path, path_2):

def test_valid(self, finder, spec):
token_id = '123'
request_uri = '/keys/{0}/tokens/master'.format(token_id)
request_uri = f'/keys/{token_id}/tokens/master'
method = 'get'
request = MockRequest(
'http://petstore.swagger.io', method, request_uri)
Expand Down
1 change: 0 additions & 1 deletion tests/unit/templating/test_responses_finders.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import division
from unittest import mock

import pytest
Expand Down