Skip to content

Commit

Permalink
🧑‍💻 Develop: migrate to ruff isort (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyongyu authored Nov 24, 2024
1 parent 470e370 commit 7cb51a0
Show file tree
Hide file tree
Showing 3,080 changed files with 35,721 additions and 35,744 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 0 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"vscode": {
"settings": {
"python.analysis.diagnosticMode": "workspace",
"python.analysis.typeCheckingMode": "basic",
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
Expand Down
8 changes: 1 addition & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ ci:
autoupdate_schedule: monthly
autoupdate_commit_msg: ":arrow_up: auto update by pre-commit hooks"
repos:
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
stages: [pre-commit]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.2
rev: v0.8.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
6 changes: 3 additions & 3 deletions codegen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import httpx
from jinja2 import Environment, PackageLoader

from .config import Config
from .source import get_source
from .log import logger as logger
from .parser.schemas import UnionSchema
from .config import Config
from .parser import (
ModelGroup,
WebhookData,
Expand All @@ -20,6 +18,8 @@
pascal_case,
parse_openapi_spec,
)
from .source import get_source
from .parser.schemas import UnionSchema

if sys.version_info >= (3, 11):
import tomllib
Expand Down
22 changes: 11 additions & 11 deletions codegen/parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from contextvars import ContextVar
from typing import TYPE_CHECKING, Optional
from contextvars import ContextVar

import httpx
from openapi_pydantic import OpenAPI

if TYPE_CHECKING:
from ..source import Source
from ..config import Override
from ..source import Source

# parser context
_override_config: ContextVar["Override"] = ContextVar("override_config")
Expand All @@ -31,20 +31,20 @@ def add_schema(ref: httpx.URL, schema: "SchemaData"):
_schemas.get()[ref] = schema


from .models import parse_models
from .utils import merge_inplace
from .webhooks import parse_webhook
from .endpoints import parse_endpoint
from .utils import sanitize as sanitize
from .data import ModelGroup as ModelGroup
from .utils import kebab_case as kebab_case
from .utils import snake_case as snake_case
from .data import OpenAPIData as OpenAPIData
from .data import WebhookData as WebhookData
from .utils import pascal_case as pascal_case
from .data import EndpointData as EndpointData
from .schemas import SchemaData, ModelSchema, parse_schema
from .utils import sanitize as sanitize
from .utils import kebab_case as kebab_case
from .utils import snake_case as snake_case
from .utils import pascal_case as pascal_case
from .utils import merge_inplace
from .utils import fix_reserved_words as fix_reserved_words
from .models import parse_models
from .schemas import SchemaData, ModelSchema, parse_schema
from .webhooks import parse_webhook
from .endpoints import parse_endpoint


def parse_openapi_spec(source: "Source", override: "Override") -> OpenAPIData:
Expand Down
2 changes: 1 addition & 1 deletion codegen/parser/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from collections import defaultdict
from dataclasses import field, dataclass

from .schemas import Property, SchemaData, ModelSchema, UnionSchema
from .utils import snake_case, concat_snake_name, fix_reserved_words
from .schemas import Property, SchemaData, ModelSchema, UnionSchema


@dataclass(eq=False)
Expand Down
6 changes: 3 additions & 3 deletions codegen/parser/endpoints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import openapi_pydantic as oas

from .parameter import build_param
from .response import build_response
from ..data import EndpointData as EndpointData
from ..utils import concat_snake_name
from .response import build_response
from .parameter import build_param
from .request_body import build_request_body
from ..data import EndpointData as EndpointData

if TYPE_CHECKING:
from ...source import Source
Expand Down
2 changes: 1 addition & 1 deletion codegen/parser/endpoints/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import openapi_pydantic as oas

from ..data import Parameter
from ..schemas import parse_schema, build_any_schema
from ..utils import build_prop_name, concat_snake_name, type_ref_from_source
from ..schemas import parse_schema, build_any_schema

if TYPE_CHECKING:
from ...source import Source
Expand Down
2 changes: 1 addition & 1 deletion codegen/parser/endpoints/request_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import openapi_pydantic as oas

from ..data import RequestBodyData
from ..schemas import parse_schema
from ..utils import concat_snake_name, type_ref_from_source
from ..schemas import parse_schema

if TYPE_CHECKING:
from ...source import Source
Expand Down
2 changes: 1 addition & 1 deletion codegen/parser/endpoints/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import openapi_pydantic as oas

from ..data import ResponseData
from ..schemas import parse_schema
from ..utils import type_ref_from_source
from ..schemas import parse_schema

if TYPE_CHECKING:
from ...source import Source
Expand Down
4 changes: 2 additions & 2 deletions codegen/parser/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import openapi_pydantic as oas

from .. import add_schema, get_schema, get_schemas
from ..utils import schema_from_source, type_ref_from_source
from .schema import Property as Property
from .schema import AnySchema as AnySchema
from .schema import IntSchema as IntSchema
Expand All @@ -16,10 +18,8 @@
from .schema import ModelSchema as ModelSchema
from .schema import UnionSchema as UnionSchema
from .schema import StringSchema as StringSchema
from .. import add_schema, get_schema, get_schemas
from .schema import DateTimeSchema as DateTimeSchema
from .schema import UniqueListSchema as UniqueListSchema
from ..utils import schema_from_source, type_ref_from_source

if TYPE_CHECKING:
from ...source import Source
Expand Down
2 changes: 1 addition & 1 deletion codegen/parser/schemas/any_schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import TYPE_CHECKING

from .schema import AnySchema
from ..utils import schema_from_source
from .schema import AnySchema

if TYPE_CHECKING:
from ...source import Source
Expand Down
4 changes: 2 additions & 2 deletions codegen/parser/schemas/bool_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ...source import Source
from .schema import BoolSchema
from ..utils import build_boolean, schema_from_source
from .schema import BoolSchema
from ...source import Source


def build_bool_schema(source: Source) -> BoolSchema:
Expand Down
2 changes: 1 addition & 1 deletion codegen/parser/schemas/float_schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import TYPE_CHECKING

from .schema import FloatSchema
from ..utils import schema_from_source
from .schema import FloatSchema

if TYPE_CHECKING:
from ...source import Source
Expand Down
2 changes: 1 addition & 1 deletion codegen/parser/schemas/int_schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import TYPE_CHECKING

from .schema import IntSchema
from ..utils import schema_from_source
from .schema import IntSchema

if TYPE_CHECKING:
from ...source import Source
Expand Down
2 changes: 1 addition & 1 deletion codegen/parser/schemas/list_schema.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import TYPE_CHECKING

from . import parse_schema
from .schema import ListSchema, UniqueListSchema
from ..utils import concat_snake_name, schema_from_source
from .schema import ListSchema, UniqueListSchema

if TYPE_CHECKING:
from ...source import Source
Expand Down
2 changes: 1 addition & 1 deletion codegen/parser/schemas/model_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import openapi_pydantic as oas

from .. import add_schema
from . import parse_schema
from .. import add_schema
from ..utils import (
build_prop_name,
build_class_name,
Expand Down
2 changes: 1 addition & 1 deletion codegen/parser/schemas/none_schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import TYPE_CHECKING

from .schema import NoneSchema
from ..utils import schema_from_source
from .schema import NoneSchema

if TYPE_CHECKING:
from ...source import Source
Expand Down
2 changes: 1 addition & 1 deletion codegen/parser/schemas/schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, ClassVar
from typing_extensions import override
from dataclasses import field, dataclass
from typing_extensions import override


@dataclass(kw_only=True)
Expand Down
16 changes: 8 additions & 8 deletions codegen/parser/schemas/union_schema.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
from typing import TYPE_CHECKING

from .. import add_schema
from . import parse_schema
from .int_schema import build_int_schema
from .bool_schema import build_bool_schema
from .list_schema import build_list_schema
from .none_schema import build_none_schema
from .float_schema import build_float_schema
from .model_schema import build_model_schema
from .string_schema import build_string_schema
from .. import add_schema
from ..utils import concat_snake_name, schema_from_source
from .schema import (
AnySchema,
Expand All @@ -26,6 +19,13 @@
DateTimeSchema,
UniqueListSchema,
)
from .int_schema import build_int_schema
from .bool_schema import build_bool_schema
from .list_schema import build_list_schema
from .none_schema import build_none_schema
from .float_schema import build_float_schema
from .model_schema import build_model_schema
from .string_schema import build_string_schema

if TYPE_CHECKING:
from ...source import Source
Expand Down
6 changes: 3 additions & 3 deletions codegen/parser/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import re
import builtins
from keyword import iskeyword
from typing import TYPE_CHECKING, Any, TypeVar
from keyword import iskeyword
import builtins

import openapi_pydantic as oas
from pydantic import TypeAdapter
import openapi_pydantic as oas

from . import get_override_config

Expand Down
2 changes: 1 addition & 1 deletion codegen/parser/webhooks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import openapi_pydantic as oas

from ..data import WebhookData
from ..schemas import parse_schema
from ..utils import snake_case, concat_snake_name, type_ref_from_source
from ..schemas import parse_schema

if TYPE_CHECKING:
from ...source import Source
Expand Down
12 changes: 6 additions & 6 deletions githubkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

lazy_module.apply()

from .config import Config as Config
from .github import GitHub as GitHub
from .core import GitHubCore as GitHubCore
from .response import Response as Response
from .paginator import Paginator as Paginator
from .compat import GitHubModel as GitHubModel
from .auth import AppAuthStrategy as AppAuthStrategy
from .auth import BaseAuthStrategy as BaseAuthStrategy
from .auth import TokenAuthStrategy as TokenAuthStrategy
Expand All @@ -18,3 +12,9 @@
from .auth import OAuthTokenAuthStrategy as OAuthTokenAuthStrategy
from .auth import OAuthDeviceAuthStrategy as OAuthDeviceAuthStrategy
from .auth import AppInstallationAuthStrategy as AppInstallationAuthStrategy
from .core import GitHubCore as GitHubCore
from .compat import GitHubModel as GitHubModel
from .config import Config as Config
from .github import GitHub as GitHub
from .response import Response as Response
from .paginator import Paginator as Paginator
8 changes: 4 additions & 4 deletions githubkit/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from .app import AppAuthStrategy as AppAuthStrategy
from .app import AppInstallationAuthStrategy as AppInstallationAuthStrategy
from .base import BaseAuthStrategy as BaseAuthStrategy
from .token import TokenAuthStrategy as TokenAuthStrategy
from .action import ActionAuthStrategy as ActionAuthStrategy
from .unauth import UnauthAuthStrategy as UnauthAuthStrategy
from .oauth import OAuthAppAuthStrategy as OAuthAppAuthStrategy
from .oauth import OAuthWebAuthStrategy as OAuthWebAuthStrategy
from .oauth import OAuthTokenAuthStrategy as OAuthTokenAuthStrategy
from .oauth import OAuthDeviceAuthStrategy as OAuthDeviceAuthStrategy
from .app import AppInstallationAuthStrategy as AppInstallationAuthStrategy
from .token import TokenAuthStrategy as TokenAuthStrategy
from .action import ActionAuthStrategy as ActionAuthStrategy
from .unauth import UnauthAuthStrategy as UnauthAuthStrategy
12 changes: 6 additions & 6 deletions githubkit/auth/app.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from dataclasses import dataclass
from typing_extensions import LiteralString
from typing import TYPE_CHECKING, Union, ClassVar, Optional
from datetime import datetime, timezone, timedelta
from dataclasses import dataclass
from collections.abc import Generator, AsyncGenerator
from typing import TYPE_CHECKING, Union, ClassVar, Optional
from typing_extensions import LiteralString

import httpx

from githubkit.exception import AuthCredentialError
from githubkit.utils import UNSET, Unset, exclude_unset
from githubkit.compat import model_dump, type_validate_python
from githubkit.exception import AuthCredentialError

from ._url import require_bypass, require_app_auth, require_basic_auth
from .base import BaseAuthStrategy
from .oauth import OAuthAppAuthStrategy
from ._url import require_bypass, require_app_auth, require_basic_auth

try:
import jwt
Expand All @@ -21,8 +21,8 @@

if TYPE_CHECKING:
from githubkit import Response, GitHubCore
from githubkit.versions.latest.models import InstallationToken
from githubkit.versions.latest.types import AppPermissionsType
from githubkit.versions.latest.models import InstallationToken


@dataclass
Expand Down
10 changes: 5 additions & 5 deletions githubkit/auth/oauth.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
from time import sleep
from typing_extensions import Self
from dataclasses import field, dataclass
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Optional, TypedDict, cast
from datetime import datetime, timezone, timedelta
from dataclasses import field, dataclass
from collections.abc import Coroutine, Generator, AsyncGenerator
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Optional, TypedDict, cast
from typing_extensions import Self

import httpx

from githubkit.utils import is_async
from githubkit.exception import AuthExpiredError, AuthCredentialError

from .base import BaseAuthStrategy
from ._url import require_bypass, get_oauth_base_url, require_basic_auth
from .base import BaseAuthStrategy

try:
import anyio
from anyio.to_thread import run_sync
from anyio.from_thread import threadlocals
from anyio.from_thread import run as run_async
from anyio.from_thread import threadlocals
except ImportError:
anyio = None
run_sync = None
Expand Down
Loading

0 comments on commit 7cb51a0

Please sign in to comment.