mirror of https://github.com/tiangolo/fastapi.git
🔧 Add Python formatting hooks to pre-commit (#4890)
This commit is contained in:
parent
f673e64eeb
commit
9cae3cdb09
|
|
@ -48,9 +48,7 @@ if __name__ == "__main__":
|
||||||
use_pr = pr
|
use_pr = pr
|
||||||
break
|
break
|
||||||
if not use_pr:
|
if not use_pr:
|
||||||
logging.error(
|
logging.error(f"No PR found for hash: {event.workflow_run.head_commit.id}")
|
||||||
f"No PR found for hash: {event.workflow_run.head_commit.id}"
|
|
||||||
)
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
github_headers = {
|
github_headers = {
|
||||||
"Authorization": f"token {settings.input_token.get_secret_value()}"
|
"Authorization": f"token {settings.input_token.get_secret_value()}"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
|
import random
|
||||||
import time
|
import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import random
|
|
||||||
from typing import Dict, Optional
|
from typing import Dict, Optional
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
@ -54,7 +54,7 @@ if __name__ == "__main__":
|
||||||
)
|
)
|
||||||
if pr.state == "open":
|
if pr.state == "open":
|
||||||
logging.debug(f"PR is open: {pr.number}")
|
logging.debug(f"PR is open: {pr.number}")
|
||||||
label_strs = set([label.name for label in pr.get_labels()])
|
label_strs = {label.name for label in pr.get_labels()}
|
||||||
if lang_all_label in label_strs and awaiting_label in label_strs:
|
if lang_all_label in label_strs and awaiting_label in label_strs:
|
||||||
logging.info(
|
logging.info(
|
||||||
f"This PR seems to be a language translation and awaiting reviews: {pr.number}"
|
f"This PR seems to be a language translation and awaiting reviews: {pr.number}"
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ from pydantic import BaseModel, BaseSettings, SecretStr
|
||||||
github_graphql_url = "https://api.github.com/graphql"
|
github_graphql_url = "https://api.github.com/graphql"
|
||||||
|
|
||||||
issues_query = """
|
issues_query = """
|
||||||
query Q($after: String) {
|
query Q($after: String) {
|
||||||
repository(name: "fastapi", owner: "tiangolo") {
|
repository(name: "fastapi", owner: "tiangolo") {
|
||||||
issues(first: 100, after: $after) {
|
issues(first: 100, after: $after) {
|
||||||
edges {
|
edges {
|
||||||
|
|
@ -47,7 +47,7 @@ query Q($after: String) {
|
||||||
"""
|
"""
|
||||||
|
|
||||||
prs_query = """
|
prs_query = """
|
||||||
query Q($after: String) {
|
query Q($after: String) {
|
||||||
repository(name: "fastapi", owner: "tiangolo") {
|
repository(name: "fastapi", owner: "tiangolo") {
|
||||||
pullRequests(first: 100, after: $after) {
|
pullRequests(first: 100, after: $after) {
|
||||||
edges {
|
edges {
|
||||||
|
|
|
||||||
|
|
@ -11,4 +11,38 @@ repos:
|
||||||
- --unsafe
|
- --unsafe
|
||||||
- id: end-of-file-fixer
|
- id: end-of-file-fixer
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
|
- repo: https://github.com/asottile/pyupgrade
|
||||||
|
rev: v2.32.1
|
||||||
|
hooks:
|
||||||
|
- id: pyupgrade
|
||||||
|
args:
|
||||||
|
- --py3-plus
|
||||||
|
- --keep-runtime-typing
|
||||||
|
- repo: https://github.com/myint/autoflake
|
||||||
|
rev: v1.4
|
||||||
|
hooks:
|
||||||
|
- id: autoflake
|
||||||
|
args:
|
||||||
|
- --recursive
|
||||||
|
- --in-place
|
||||||
|
- --remove-all-unused-imports
|
||||||
|
- --remove-unused-variables
|
||||||
|
- --expand-star-imports
|
||||||
|
- --exclude
|
||||||
|
- __init__.py
|
||||||
|
- --remove-duplicate-keys
|
||||||
|
- repo: https://github.com/pycqa/isort
|
||||||
|
rev: 5.10.1
|
||||||
|
hooks:
|
||||||
|
- id: isort
|
||||||
|
name: isort (python)
|
||||||
|
- id: isort
|
||||||
|
name: isort (cython)
|
||||||
|
types: [cython]
|
||||||
|
- id: isort
|
||||||
|
name: isort (pyi)
|
||||||
|
types: [pyi]
|
||||||
|
- repo: https://github.com/psf/black
|
||||||
|
rev: 22.3.0
|
||||||
|
hooks:
|
||||||
|
- id: black
|
||||||
|
|
|
||||||
|
|
@ -364,7 +364,7 @@ class APIRoute(routing.Route):
|
||||||
self.path_regex, self.path_format, self.param_convertors = compile_path(path)
|
self.path_regex, self.path_format, self.param_convertors = compile_path(path)
|
||||||
if methods is None:
|
if methods is None:
|
||||||
methods = ["GET"]
|
methods = ["GET"]
|
||||||
self.methods: Set[str] = set([method.upper() for method in methods])
|
self.methods: Set[str] = {method.upper() for method in methods}
|
||||||
if isinstance(generate_unique_id_function, DefaultPlaceholder):
|
if isinstance(generate_unique_id_function, DefaultPlaceholder):
|
||||||
current_generate_unique_id: Callable[
|
current_generate_unique_id: Callable[
|
||||||
["APIRoute"], str
|
["APIRoute"], str
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue