Skip to content

Commit

Permalink
✨ add ruff linter
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu committed Aug 29, 2023
1 parent 87673c5 commit 453ccfd
Show file tree
Hide file tree
Showing 21 changed files with 227 additions and 82 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Ruff Lint

on:
push:
branches:
- master
pull_request:

jobs:
ruff:
name: Ruff Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Run Ruff Lint
uses: chartboost/ruff-action@v1
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ ci:
autoupdate_schedule: monthly
autoupdate_commit_msg: ":arrow_up: auto update by pre-commit hooks"
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.286
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
stages: [commit]

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
Expand Down
3 changes: 2 additions & 1 deletion codegen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ def build():
parsed_data = parse_openapi_spec(source, versioned_rest, config)
logger.info(
f"Successfully parsed OpenAPI spec {versioned_rest.version}: "
f"{len(parsed_data.schemas)} schemas, {len(parsed_data.endpoints)} endpoints"
f"{len(parsed_data.schemas)} schemas, "
f"{len(parsed_data.endpoints)} endpoints"
)

build_rest_api(parsed_data, versioned_rest)
Expand Down
1 change: 0 additions & 1 deletion codegen/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Any, Dict, List

import openapi_pydantic as oas
from pydantic import Field, BaseModel


Expand Down
2 changes: 0 additions & 2 deletions codegen/parser/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from functools import cached_property
from typing import Dict, List, Union, Optional

from pydantic import BaseModel

from .endpoints import EndpointData
from .schemas import SchemaData, ModelSchema

Expand Down
2 changes: 0 additions & 2 deletions codegen/parser/schemas/enum_schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import Union, Optional

import openapi_pydantic as oas

from ...source import Source
from ..utils import schema_from_source
from .schema import EnumSchema, NoneSchema, UnionSchema
Expand Down
2 changes: 0 additions & 2 deletions codegen/parser/schemas/float_schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import Optional

import openapi_pydantic as oas

from ...source import Source
from .schema import FloatSchema
from ..utils import schema_from_source
Expand Down
2 changes: 0 additions & 2 deletions codegen/parser/schemas/int_schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import Optional

import openapi_pydantic as oas

from ...source import Source
from .schema import IntSchema
from ..utils import schema_from_source
Expand Down
2 changes: 0 additions & 2 deletions codegen/parser/schemas/list_schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import Optional

import openapi_pydantic as oas

from . import parse_schema
from ...source import Source
from .schema import ListSchema
Expand Down
3 changes: 2 additions & 1 deletion codegen/parser/schemas/model_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ def _add_if_no_conflict(prop: Property):
model = model.schemas[assertion.index(True)]
if not isinstance(model, ModelSchema):
raise ValueError(
f"Invalid schema {model!r} in allOf: {prop_source.uri} from {source.uri}"
f"Invalid schema {model!r} in allOf: "
f"{prop_source.uri} from {source.uri}"
)
for prop in model.properties:
_add_if_no_conflict(prop)
Expand Down
3 changes: 2 additions & 1 deletion codegen/parser/schemas/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ def get_type_string(self) -> str:
def get_param_type_string(self) -> str:
if len(self.schemas) == 1:
return self.schemas[0].get_param_type_string()
return f"Union[{', '.join(schema.get_param_type_string() for schema in self.schemas)}]"
types = ", ".join(schema.get_param_type_string() for schema in self.schemas)
return f"Union[{types}]"

def get_model_imports(self) -> Set[str]:
imports = super().get_model_imports()
Expand Down
2 changes: 0 additions & 2 deletions codegen/parser/schemas/string_schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import Union, Optional

import openapi_pydantic as oas

from ...source import Source
from ..utils import schema_from_source
from .schema import DateSchema, FileSchema, StringSchema, DateTimeSchema
Expand Down
5 changes: 3 additions & 2 deletions codegen/parser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def split_words(value: str) -> List[str]:

def fix_reserved_words(value: str) -> str:
"""
Using reserved Python words as identifiers in generated code causes problems, so this function renames them.
Using reserved Python words as identifiers in generated code causes problems,
so this function renames them.
Args:
value: The identifier to-be that should be renamed if it's a reserved word.
Expand All @@ -56,7 +57,7 @@ def snake_case(value: str) -> str:
def pascal_case(value: str) -> str:
"""Converts to PascalCase"""
words = split_words(sanitize(value))
return "".join((word if word.isupper() else word.capitalize() for word in words))
return "".join(word if word.isupper() else word.capitalize() for word in words)


def kebab_case(value: str) -> str:
Expand Down
3 changes: 2 additions & 1 deletion githubkit/auth/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def auth_flow(
token = os.environ.get("GITHUB_TOKEN", os.environ.get("INPUT_GITHUB_TOKEN"))
if not token:
raise AuthCredentialError(
"`GITHUB_TOKEN` is not provided. Use `env:` or `with:` to input a token."
"`GITHUB_TOKEN` is not provided. "
"Use `env:` or `with:` to input a token."
)
request.headers["Authorization"] = f"token {token}"
yield request
Expand Down
5 changes: 4 additions & 1 deletion githubkit/auth/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ class AppAuth(httpx.Auth):
cache: "BaseCache" = DEFAULT_CACHE

JWT_CACHE_KEY = "githubkit:auth:app:jwt"
INSTALLATION_CACHE_KEY = "githubkit:auth:app:installation:{installation_id}:{permissions}:{repositories}:{repository_ids}"
INSTALLATION_CACHE_KEY = (
"githubkit:auth:app:installation:"
"{installation_id}:{permissions}:{repositories}:{repository_ids}"
)

def _create_jwt(self) -> str:
"""Create a JWT authenticating as GitHub APP.
Expand Down
4 changes: 2 additions & 2 deletions githubkit/cache/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import abc
from typing import Union, Optional
from datetime import datetime, timedelta
from typing import Optional
from datetime import timedelta


class BaseCache(abc.ABC):
Expand Down
4 changes: 3 additions & 1 deletion githubkit/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ def __init__(
timeout: Optional[Union[float, httpx.Timeout]] = None,
):
auth = auth or UnauthAuthStrategy() # type: ignore
self.auth: A = TokenAuthStrategy(auth) if isinstance(auth, str) else auth # type: ignore
self.auth: A = ( # type: ignore
TokenAuthStrategy(auth) if isinstance(auth, str) else auth
)

self.config = config or get_config(
base_url, accept_format, previews, user_agent, follow_redirects, timeout
Expand Down
4 changes: 3 additions & 1 deletion githubkit/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,6 @@ def paginate(
*args: CP.args,
**kwargs: CP.kwargs,
) -> Paginator[RT]:
return Paginator(request, page, per_page, map_func, *args, **kwargs) # type: ignore
return Paginator(
request, page, per_page, map_func, *args, **kwargs # type: ignore
)
1 change: 0 additions & 1 deletion githubkit/paginator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import inspect
from typing_extensions import Self, ParamSpec
from typing import (
List,
Expand Down
Loading

0 comments on commit 453ccfd

Please sign in to comment.