Skip to content

Commit

Permalink
fix: sort imports
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming committed Dec 15, 2023
1 parent 71e2c8a commit 8ee3483
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 45 deletions.
2 changes: 1 addition & 1 deletion examples/sentence-embedding/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import torch

import bentoml
from bentoml.types import Field
from bentoml.ui import Field


@bentoml.service(resources={"memory": "500MiB"}, traffic={"timeout": 1})
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ convention = "google"

[tool.ruff.isort]
force-single-line = true
known-first-party = ["bentoml"]
known-first-party = ["bentoml", "bentoml_cli", "_bentoml_sdk", "_bentoml_impl"]

[tool.pyright]
pythonVersion = "3.12"
Expand Down
3 changes: 2 additions & 1 deletion src/_bentoml_impl/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import typing as t

import pyarrow as pa
from _bentoml_sdk.types import arrow_serialization
from pydantic import BaseModel

from _bentoml_sdk.types import arrow_serialization

SchemaDict: t.TypeAlias = t.Dict[str, t.Any]

T = t.TypeVar("T", bound=BaseModel)
Expand Down
2 changes: 1 addition & 1 deletion src/_bentoml_impl/server/allocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from typing import Any

from _bentoml_sdk import Service
from simple_di import Provide
from simple_di import inject

from _bentoml_sdk import Service
from bentoml._internal.configuration.containers import BentoMLContainer
from bentoml._internal.resource import system_resources
from bentoml.exceptions import BentoMLConfigException
Expand Down
2 changes: 1 addition & 1 deletion src/_bentoml_impl/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import typing as t
from pathlib import Path

from _bentoml_sdk import Service
from simple_di import Provide
from simple_di import inject
from starlette.middleware import Middleware
from starlette.staticfiles import StaticFiles

from _bentoml_sdk import Service
from bentoml._internal.container import BentoMLContainer
from bentoml._internal.marshal.dispatcher import CorkDispatcher
from bentoml._internal.server.base_app import BaseAppFactory
Expand Down
2 changes: 1 addition & 1 deletion src/_bentoml_impl/server/serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import tempfile
import typing as t

from _bentoml_sdk import Service
from simple_di import Provide
from simple_di import inject

from _bentoml_sdk import Service
from bentoml._internal.container import BentoMLContainer
from bentoml.exceptions import BentoMLConfigException

Expand Down
6 changes: 4 additions & 2 deletions src/_bentoml_sdk/io_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
from .typing_utils import is_list_type

if t.TYPE_CHECKING:
from _bentoml_impl.serde import Serde
from starlette.requests import Request
from starlette.responses import Response

from _bentoml_impl.serde import Serde


DEFAULT_TEXT_MEDIA_TYPE = "text/plain"

Expand Down Expand Up @@ -116,12 +117,13 @@ async def from_http_request(cls, request: Request, serde: Serde) -> IODescriptor
@classmethod
async def to_http_response(cls, obj: t.Any, serde: Serde) -> Response:
"""Convert a output value to HTTP response"""
from _bentoml_impl.serde import JSONSerde
from pydantic import RootModel
from starlette.responses import FileResponse
from starlette.responses import Response
from starlette.responses import StreamingResponse

from _bentoml_impl.serde import JSONSerde

structured_media_type = cls.media_type or serde.media_type

if not issubclass(cls, RootModel):
Expand Down
1 change: 0 additions & 1 deletion src/_bentoml_sdk/service/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ def serve_http(
reload: bool = False,
) -> None:
from _bentoml_impl.server import serve_http

from bentoml._internal.log import configure_logging

configure_logging()
Expand Down
4 changes: 2 additions & 2 deletions src/bentoml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
from . import batch # Batch API
from . import exceptions # BentoML exceptions
from . import server # Server API
from . import types # BentoML types
from . import ui # BentoML UI
from . import monitoring # Monitoring API
from . import cloud # Cloud API

Expand Down Expand Up @@ -151,7 +151,7 @@
ray = _LazyLoader("bentoml.ray", globals(), "bentoml.ray")

io = _LazyLoader("bentoml.io", globals(), "bentoml.io")
types = _LazyLoader("bentoml.types", globals(), "bentoml.types")
ui = _LazyLoader("bentoml.ui", globals(), "bentoml.ui")
batch = _LazyLoader("bentoml.batch", globals(), "bentoml.batch")
models = _LazyLoader("bentoml.models", globals(), "bentoml.models")
metrics = _LazyLoader("bentoml.metrics", globals(), "bentoml.metrics")
Expand Down
3 changes: 2 additions & 1 deletion src/bentoml/_internal/bento/bento.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@
from .build_config import PythonOptions

if TYPE_CHECKING:
from fs.base import FS

from _bentoml_sdk import Service as NewService
from _bentoml_sdk.api import APIMethod
from _bentoml_sdk.service import ServiceConfig
from fs.base import FS

from ..models import Model
from ..service import Service
Expand Down
2 changes: 1 addition & 1 deletion src/bentoml/_internal/service/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

if t.TYPE_CHECKING:
import grpc
from _bentoml_sdk import Service as NewService

import bentoml
from _bentoml_sdk import Service as NewService
from bentoml.grpc.types import AddServicerFn
from bentoml.grpc.types import ServicerClass
from bentoml.triton import _TritonRunner
Expand Down
2 changes: 1 addition & 1 deletion src/bentoml/_internal/utils/analytics/usage_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
T = t.TypeVar("T")
AsyncFunc = t.Callable[P, t.Coroutine[t.Any, t.Any, t.Any]]

from _bentoml_sdk import Service as NewService
from prometheus_client.samples import Sample

from _bentoml_sdk import Service as NewService
from bentoml import Service

from ...server.metrics.prometheus import PrometheusClient
Expand Down
32 changes: 1 addition & 31 deletions src/bentoml/types.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from pydantic import Field

from ._internal.models.model import ModelSignature
from ._internal.types import ModelSignatureDict

if TYPE_CHECKING:
from _bentoml_sdk.types import Audio
from _bentoml_sdk.types import File
from _bentoml_sdk.types import Image
from _bentoml_sdk.types import Tensor
from _bentoml_sdk.types import Video
else:

def __getattr__(name: str) -> None:
if name not in ("File", "Image", "Audio", "Video", "Tensor"):
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

import _bentoml_sdk.types

return getattr(_bentoml_sdk.types, name)


__all__ = [
"ModelSignature",
"ModelSignatureDict",
"File",
"Image",
"Audio",
"Video",
"Tensor",
"Field",
]
__all__ = ["ModelSignature", "ModelSignatureDict"]
9 changes: 9 additions & 0 deletions src/bentoml/ui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from pydantic import Field

from _bentoml_sdk.types import Audio
from _bentoml_sdk.types import File
from _bentoml_sdk.types import Image
from _bentoml_sdk.types import Tensor
from _bentoml_sdk.types import Video

__all__ = ["Audio", "File", "Image", "Tensor", "Video", "Field"]
1 change: 1 addition & 0 deletions tests/unit/bentoml_cli/test_env_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import pytest

from bentoml_cli.env_manager import remove_env_arg

testdata = [
Expand Down
1 change: 1 addition & 0 deletions tests/unit/bentoml_io/test_allocator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest import mock

import pytest

from _bentoml_impl.server.allocator import BentoMLConfigException
from _bentoml_impl.server.allocator import ResourceAllocator
from _bentoml_impl.server.allocator import ResourceUnavailable
Expand Down

0 comments on commit 8ee3483

Please sign in to comment.