Skip to content

Commit 62b2f35

Browse files
committed
Enforce latests syntax on CI
1 parent 82738c3 commit 62b2f35

File tree

25 files changed

+95
-44
lines changed

25 files changed

+95
-44
lines changed

.github/workflows/python-test.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010

1111
jobs:
1212
test:
13+
name: "Tests"
1314
runs-on: ubuntu-latest
1415
strategy:
1516
matrix:
@@ -31,3 +32,16 @@ jobs:
3132
run: python setup.py test
3233
- name: Upload coverage
3334
uses: codecov/codecov-action@v1
35+
36+
static-checks:
37+
name: "Static checks"
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
41+
uses: actions/checkout@v2
42+
- name: "Setup Python"
43+
uses: actions/setup-python@v2
44+
with:
45+
python-version: 3.9
46+
- name: "Run static checks"
47+
uses: pre-commit/[email protected]

.pre-commit-config.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
default_stages: [commit, push]
3+
default_language_version:
4+
# force all unspecified python hooks to run python3
5+
python: python3
6+
minimum_pre_commit_version: "1.20.0"
7+
repos:
8+
- repo: meta
9+
hooks:
10+
- id: check-hooks-apply
11+
- repo: https://github.com/asottile/pyupgrade
12+
rev: v2.19.0
13+
hooks:
14+
- id: pyupgrade
15+
args: ["--py36-plus"]
16+
exclude: ^airflow/_vendor/
17+
- repo: local
18+
hooks:
19+
- id: flynt
20+
name: Convert to f-strings with flynt
21+
entry: flynt
22+
language: python
23+
additional_dependencies: ['flynt==0.64']

CONTRIBUTING.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Contributor Guide
3+
=================
4+
5+
# Static checks
6+
7+
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:
8+
9+
```bash
10+
pip install -r requiremenets_dev.txt
11+
```
12+
13+
To turn on pre-commit checks for commit operations in git, enter:
14+
```bash
15+
pre-commit install
16+
```
17+
18+
To run all checks on your staged files, enter:
19+
```bash
20+
pre-commit run
21+
```
22+
23+
To run all checks on all files, enter:
24+
```bash
25+
pre-commit run --all-files
26+
```
27+
28+
Pre-commit check results are also attached to your PR through integration with Github Action.

openapi_core/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""OpenAPI core module"""
32
from openapi_core.shortcuts import (
43
create_spec, validate_request, validate_response,

openapi_core/casting/schemas/exceptions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ class CastError(OpenAPIError):
1010
type: str
1111

1212
def __str__(self):
13-
return "Failed to cast value to {type} type: {value}".format(
14-
type=self.type, value=self.value)
13+
return f"Failed to cast value to {self.type} type: {self.value}"

openapi_core/contrib/django/backports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ def parse_header_name(cls, header):
2424

2525

2626
def request_current_scheme_host(req):
27-
return '{}://{}'.format(req.scheme, req.get_host())
27+
return f'{req.scheme}://{req.get_host()}'

openapi_core/deserializing/media_types/util.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ def data_form_loads(value):
1111
value = value.decode('ASCII', errors='surrogateescape')
1212
parser = Parser()
1313
parts = parser.parsestr(value, headersonly=False)
14-
return dict(
15-
(
16-
part.get_param('name', header='content-disposition'),
17-
part.get_payload(decode=True),
18-
)
14+
return {
15+
part.get_param('name', header='content-disposition'):
16+
part.get_payload(decode=True)
1917
for part in parts.get_payload()
20-
)
18+
}

openapi_core/deserializing/parameters/exceptions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,4 @@ def __init__(self, name):
3131
self.name = name
3232

3333
def __str__(self):
34-
return "Value of {name} {location} parameter cannot be empty".format(
35-
name=self.name, location=self.location)
34+
return f"Value of {self.name} {self.location} parameter cannot be empty"

openapi_core/exceptions.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@ class MissingHeader(MissingHeaderError):
2323
name: str
2424

2525
def __str__(self):
26-
return "Missing header (without default value): {0}".format(
27-
self.name)
28-
26+
return f"Missing header (without default value): {self.name}"
2927

3028
@dataclass
3129
class MissingRequiredHeader(MissingHeaderError):
3230
name: str
3331

3432
def __str__(self):
35-
return "Missing required header: {0}".format(self.name)
33+
return f"Missing required header: {self.name}"
3634

3735

3836
class OpenAPIParameterError(OpenAPIError):
@@ -49,16 +47,15 @@ class MissingParameter(MissingParameterError):
4947
name: str
5048

5149
def __str__(self):
52-
return "Missing parameter (without default value): {0}".format(
53-
self.name)
50+
return f"Missing parameter (without default value): {self.name}"
5451

5552

5653
@dataclass
5754
class MissingRequiredParameter(MissingParameterError):
5855
name: str
5956

6057
def __str__(self):
61-
return "Missing required parameter: {0}".format(self.name)
58+
return f"Missing required parameter: {self.name}"
6259

6360

6461
class OpenAPIRequestBodyError(OpenAPIError):

openapi_core/security/providers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ def __call__(self, request):
4040
scheme = self.scheme['scheme']
4141
if auth_type.lower() != scheme:
4242
raise SecurityError(
43-
'Unknown authorization method %s' % auth_type)
43+
f'Unknown authorization method {auth_type}')
4444

4545
return encoded_credentials

0 commit comments

Comments
 (0)