Skip to content

Commit

Permalink
chore(internal): replace isort with ruff (#1042)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored Jan 3, 2024
1 parent 2e9ecee commit f1fbc9c
Show file tree
Hide file tree
Showing 56 changed files with 397 additions and 383 deletions.
16 changes: 9 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ dev-dependencies = [
"pytest",
"pytest-asyncio",
"ruff",
"isort",
"time-machine",
"nox",
"dirty-equals>=0.6.0",
Expand All @@ -69,7 +68,6 @@ format = { chain = [
"format:ruff",
"format:docs",
"fix:ruff",
"format:isort",
]}
"format:black" = "black ."
"format:docs" = "python bin/ruffen-docs.py README.md api.md"
Expand Down Expand Up @@ -130,16 +128,13 @@ reportImplicitOverride = true
reportImportCycles = false
reportPrivateUsage = false

[tool.isort]
profile = "black"
length_sort = true
extra_standard_library = ["typing_extensions"]

[tool.ruff]
line-length = 120
output-format = "grouped"
target-version = "py37"
select = [
# isort
"I",
# bugbear rules
"B",
# remove unused imports
Expand All @@ -166,6 +161,13 @@ ignore-init-module-imports = true
[tool.ruff.format]
docstring-code-format = true

[tool.ruff.lint.isort]
length-sort = true
length-sort-straight = true
combine-as-imports = true
extra-standard-library = ["typing_extensions"]
known-first-party = ["openai", "tests"]

[tool.ruff.per-file-ignores]
"bin/**.py" = ["T201", "T203"]
"tests/**.py" = ["T201", "T203"]
Expand Down
7 changes: 3 additions & 4 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@ httpx==0.25.2
idna==3.4
importlib-metadata==7.0.0
iniconfig==2.0.0
isort==5.10.1
msal==1.26.0
msal-extensions==1.1.0
mypy==1.7.1
mypy-extensions==1.0.0
nodeenv==1.8.0
nox==2023.4.22
numpy==1.26.2
numpy==1.26.3
packaging==23.2
pandas==2.1.4
pandas-stubs==2.1.4.231218
pandas-stubs==2.1.4.231227
platformdirs==3.11.0
pluggy==1.3.0
portalocker==2.8.2
Expand All @@ -64,7 +63,7 @@ tqdm==4.66.1
types-pytz==2023.3.1.1
types-tqdm==4.66.0.2
typing-extensions==4.8.0
tzdata==2023.3
tzdata==2023.4
urllib3==2.1.0
virtualenv==20.24.5
zipp==3.17.0
Expand Down
41 changes: 16 additions & 25 deletions src/openai/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,7 @@
from . import types
from ._types import NoneType, Transport, ProxiesTypes
from ._utils import file_from_path
from ._client import (
Client,
OpenAI,
Stream,
Timeout,
Transport,
AsyncClient,
AsyncOpenAI,
AsyncStream,
RequestOptions,
)
from ._client import Client, OpenAI, Stream, Timeout, Transport, AsyncClient, AsyncOpenAI, AsyncStream, RequestOptions
from ._version import __title__, __version__
from ._exceptions import (
APIError,
Expand Down Expand Up @@ -72,8 +62,7 @@

from .lib import azure as _azure
from .version import VERSION as VERSION
from .lib.azure import AzureOpenAI as AzureOpenAI
from .lib.azure import AsyncAzureOpenAI as AsyncAzureOpenAI
from .lib.azure import AzureOpenAI as AzureOpenAI, AsyncAzureOpenAI as AsyncAzureOpenAI
from .lib._old_api import *

_setup_logging()
Expand Down Expand Up @@ -323,15 +312,17 @@ def _reset_client() -> None: # type: ignore[reportUnusedFunction]
_client = None


from ._module_client import beta as beta
from ._module_client import chat as chat
from ._module_client import audio as audio
from ._module_client import edits as edits
from ._module_client import files as files
from ._module_client import images as images
from ._module_client import models as models
from ._module_client import embeddings as embeddings
from ._module_client import fine_tunes as fine_tunes
from ._module_client import completions as completions
from ._module_client import fine_tuning as fine_tuning
from ._module_client import moderations as moderations
from ._module_client import (
beta as beta,
chat as chat,
audio as audio,
edits as edits,
files as files,
images as images,
models as models,
embeddings as embeddings,
fine_tunes as fine_tunes,
completions as completions,
fine_tuning as fine_tuning,
moderations as moderations,
)
15 changes: 11 additions & 4 deletions src/openai/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@
ProxiesTypes,
RequestOptions,
)
from ._utils import is_given, is_mapping, get_async_library
from ._utils import (
is_given,
is_mapping,
get_async_library,
)
from ._version import __version__
from ._streaming import Stream as Stream
from ._streaming import AsyncStream as AsyncStream
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
from ._exceptions import OpenAIError, APIStatusError
from ._base_client import DEFAULT_MAX_RETRIES, SyncAPIClient, AsyncAPIClient
from ._base_client import (
DEFAULT_MAX_RETRIES,
SyncAPIClient,
AsyncAPIClient,
)

__all__ = [
"Timeout",
Expand Down
30 changes: 16 additions & 14 deletions src/openai/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,23 @@ def is_typeddict(type_: type[Any]) -> bool: # noqa: ARG001

else:
if PYDANTIC_V2:
from pydantic.v1.typing import get_args as get_args
from pydantic.v1.typing import is_union as is_union
from pydantic.v1.typing import get_origin as get_origin
from pydantic.v1.typing import is_typeddict as is_typeddict
from pydantic.v1.typing import is_literal_type as is_literal_type
from pydantic.v1.datetime_parse import parse_date as parse_date
from pydantic.v1.datetime_parse import parse_datetime as parse_datetime
from pydantic.v1.typing import (
get_args as get_args,
is_union as is_union,
get_origin as get_origin,
is_typeddict as is_typeddict,
is_literal_type as is_literal_type,
)
from pydantic.v1.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime
else:
from pydantic.typing import get_args as get_args
from pydantic.typing import is_union as is_union
from pydantic.typing import get_origin as get_origin
from pydantic.typing import is_typeddict as is_typeddict
from pydantic.typing import is_literal_type as is_literal_type
from pydantic.datetime_parse import parse_date as parse_date
from pydantic.datetime_parse import parse_datetime as parse_datetime
from pydantic.typing import (
get_args as get_args,
is_union as is_union,
get_origin as get_origin,
is_typeddict as is_typeddict,
is_literal_type as is_literal_type,
)
from pydantic.datetime_parse import parse_date as parse_date, parse_datetime as parse_datetime


# refactored config
Expand Down
3 changes: 1 addition & 2 deletions src/openai/_extras/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from .numpy_proxy import numpy as numpy
from .numpy_proxy import has_numpy as has_numpy
from .numpy_proxy import numpy as numpy, has_numpy as has_numpy
from .pandas_proxy import pandas as pandas
14 changes: 4 additions & 10 deletions src/openai/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,11 @@
AnyMapping,
HttpxRequestFiles,
)
from ._utils import (
is_list,
is_given,
is_mapping,
parse_date,
parse_datetime,
strip_not_given,
)
from ._compat import PYDANTIC_V2, ConfigDict
from ._compat import GenericModel as BaseGenericModel
from ._utils import is_list, is_given, is_mapping, parse_date, parse_datetime, strip_not_given
from ._compat import (
PYDANTIC_V2,
ConfigDict,
GenericModel as BaseGenericModel,
get_args,
is_union,
parse_obj,
Expand Down
9 changes: 1 addition & 8 deletions src/openai/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,7 @@
Sequence,
AsyncIterator,
)
from typing_extensions import (
Literal,
Protocol,
TypeAlias,
TypedDict,
override,
runtime_checkable,
)
from typing_extensions import Literal, Protocol, TypeAlias, TypedDict, override, runtime_checkable

import httpx
import pydantic
Expand Down
83 changes: 44 additions & 39 deletions src/openai/_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
from ._proxy import LazyProxy as LazyProxy
from ._utils import flatten as flatten
from ._utils import is_dict as is_dict
from ._utils import is_list as is_list
from ._utils import is_given as is_given
from ._utils import is_tuple as is_tuple
from ._utils import is_mapping as is_mapping
from ._utils import is_tuple_t as is_tuple_t
from ._utils import parse_date as parse_date
from ._utils import is_sequence as is_sequence
from ._utils import coerce_float as coerce_float
from ._utils import is_mapping_t as is_mapping_t
from ._utils import removeprefix as removeprefix
from ._utils import removesuffix as removesuffix
from ._utils import extract_files as extract_files
from ._utils import is_sequence_t as is_sequence_t
from ._utils import required_args as required_args
from ._utils import coerce_boolean as coerce_boolean
from ._utils import coerce_integer as coerce_integer
from ._utils import file_from_path as file_from_path
from ._utils import parse_datetime as parse_datetime
from ._utils import strip_not_given as strip_not_given
from ._utils import deepcopy_minimal as deepcopy_minimal
from ._utils import get_async_library as get_async_library
from ._utils import maybe_coerce_float as maybe_coerce_float
from ._utils import get_required_header as get_required_header
from ._utils import maybe_coerce_boolean as maybe_coerce_boolean
from ._utils import maybe_coerce_integer as maybe_coerce_integer
from ._typing import is_list_type as is_list_type
from ._typing import is_union_type as is_union_type
from ._typing import extract_type_arg as extract_type_arg
from ._typing import is_required_type as is_required_type
from ._typing import is_annotated_type as is_annotated_type
from ._typing import strip_annotated_type as strip_annotated_type
from ._typing import extract_type_var_from_base as extract_type_var_from_base
from ._streams import consume_sync_iterator as consume_sync_iterator
from ._streams import consume_async_iterator as consume_async_iterator
from ._transform import PropertyInfo as PropertyInfo
from ._transform import transform as transform
from ._transform import maybe_transform as maybe_transform
from ._utils import (
flatten as flatten,
is_dict as is_dict,
is_list as is_list,
is_given as is_given,
is_tuple as is_tuple,
is_mapping as is_mapping,
is_tuple_t as is_tuple_t,
parse_date as parse_date,
is_sequence as is_sequence,
coerce_float as coerce_float,
is_mapping_t as is_mapping_t,
removeprefix as removeprefix,
removesuffix as removesuffix,
extract_files as extract_files,
is_sequence_t as is_sequence_t,
required_args as required_args,
coerce_boolean as coerce_boolean,
coerce_integer as coerce_integer,
file_from_path as file_from_path,
parse_datetime as parse_datetime,
strip_not_given as strip_not_given,
deepcopy_minimal as deepcopy_minimal,
get_async_library as get_async_library,
maybe_coerce_float as maybe_coerce_float,
get_required_header as get_required_header,
maybe_coerce_boolean as maybe_coerce_boolean,
maybe_coerce_integer as maybe_coerce_integer,
)
from ._typing import (
is_list_type as is_list_type,
is_union_type as is_union_type,
extract_type_arg as extract_type_arg,
is_required_type as is_required_type,
is_annotated_type as is_annotated_type,
strip_annotated_type as strip_annotated_type,
extract_type_var_from_base as extract_type_var_from_base,
)
from ._streams import consume_sync_iterator as consume_sync_iterator, consume_async_iterator as consume_async_iterator
from ._transform import (
PropertyInfo as PropertyInfo,
transform as transform,
maybe_transform as maybe_transform,
)
5 changes: 4 additions & 1 deletion src/openai/_utils/_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

import pydantic

from ._utils import is_list, is_mapping
from ._utils import (
is_list,
is_mapping,
)
from ._typing import (
is_list_type,
is_union_type,
Expand Down
3 changes: 1 addition & 2 deletions src/openai/_utils/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import sniffio

from .._types import Headers, NotGiven, FileTypes, NotGivenOr, HeadersLike
from .._compat import parse_date as parse_date
from .._compat import parse_datetime as parse_datetime
from .._compat import parse_date as parse_date, parse_datetime as parse_datetime

_T = TypeVar("_T")
_TupleT = TypeVar("_TupleT", bound=Tuple[object, ...])
Expand Down
Loading

0 comments on commit f1fbc9c

Please sign in to comment.