Skip to content

Commit

Permalink
style: run pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gusghrlrl101 committed Apr 19, 2024
1 parent 010e12f commit 9f2847e
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 127 deletions.
18 changes: 9 additions & 9 deletions src/_bentoml_impl/server/serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import typing as t

import attrs
from simple_di import Provide, inject
from simple_di import Provide
from simple_di import inject

from _bentoml_sdk import Service
from bentoml._internal.container import BentoMLContainer
Expand Down Expand Up @@ -169,15 +170,14 @@ def serve_http(
from bentoml._internal.utils import reserve_free_port
from bentoml._internal.utils.analytics.usage_stats import track_serve
from bentoml._internal.utils.circus import create_standalone_arbiter
from bentoml.serve import (
construct_ssl_args,
construct_timeouts_args,
create_watcher,
ensure_prometheus_dir,
make_reload_plugin,
)
from bentoml.serve import construct_ssl_args
from bentoml.serve import construct_timeouts_args
from bentoml.serve import create_watcher
from bentoml.serve import ensure_prometheus_dir
from bentoml.serve import make_reload_plugin

from ..loader import import_service, normalize_identifier
from ..loader import import_service
from ..loader import normalize_identifier
from .allocator import ResourceAllocator

prometheus_dir = ensure_prometheus_dir()
Expand Down
19 changes: 14 additions & 5 deletions src/_bentoml_sdk/service/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
from __future__ import annotations

from typing import Any, Dict, List, Sequence, Union

from annotated_types import Ge, Gt, Le
from pydantic import IPvAnyAddress, TypeAdapter
from typing_extensions import Annotated, Literal, TypedDict
from typing import Any
from typing import Dict
from typing import List
from typing import Sequence
from typing import Union

from annotated_types import Ge
from annotated_types import Gt
from annotated_types import Le
from pydantic import IPvAnyAddress
from pydantic import TypeAdapter
from typing_extensions import Annotated
from typing_extensions import Literal
from typing_extensions import TypedDict

Posint = Annotated[int, Gt(0)]
Posfloat = Annotated[float, Gt(0.0)]
Expand Down
12 changes: 6 additions & 6 deletions src/_bentoml_sdk/service/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import pathlib
import sys
import typing as t
from functools import lru_cache, partial
from functools import lru_cache
from functools import partial

import attrs
from simple_di import Provide, inject
from simple_di import Provide
from simple_di import inject
from typing_extensions import Unpack

from bentoml import Runner
Expand Down Expand Up @@ -240,10 +242,8 @@ def openapi_spec(self) -> OpenAPISpecification:

def inject_config(self) -> None:
from bentoml._internal.configuration import load_config
from bentoml._internal.configuration.containers import (
BentoMLContainer,
config_merger,
)
from bentoml._internal.configuration.containers import BentoMLContainer
from bentoml._internal.configuration.containers import config_merger

# XXX: ensure at least one item to make `flatten_dict` work
override_defaults = {
Expand Down
41 changes: 21 additions & 20 deletions src/bentoml/_internal/configuration/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@
import schema as s
import yaml
from deepmerge.merger import Merger
from simple_di import Provide, providers
from simple_di import Provide
from simple_di import providers

from ...exceptions import BentoMLConfigException
from ..context import server_context, trace_context
from ..context import server_context
from ..context import trace_context
from ..resource import CpuResource
from ..utils import split_with_quotes, validate_or_create_dir
from ..utils import split_with_quotes
from ..utils import validate_or_create_dir
from ..utils.unflatten import unflatten
from . import expand_env_var
from .helpers import (
expand_env_var_in_values,
flatten_dict,
get_default_config,
import_configuration_spec,
load_config_file,
)
from .helpers import expand_env_var_in_values
from .helpers import flatten_dict
from .helpers import get_default_config
from .helpers import import_configuration_spec
from .helpers import load_config_file

if TYPE_CHECKING:
from fs.base import FS
Expand Down Expand Up @@ -336,14 +337,12 @@ def tracer_provider(
jaeger: dict[str, t.Any] = Provide[tracing.jaeger],
otlp: dict[str, t.Any] = Provide[tracing.otlp],
):
from opentelemetry.sdk.resources import (
SERVICE_INSTANCE_ID,
SERVICE_NAME,
SERVICE_NAMESPACE,
SERVICE_VERSION,
OTELResourceDetector,
Resource,
)
from opentelemetry.sdk.resources import SERVICE_INSTANCE_ID
from opentelemetry.sdk.resources import SERVICE_NAME
from opentelemetry.sdk.resources import SERVICE_NAMESPACE
from opentelemetry.sdk.resources import SERVICE_VERSION
from opentelemetry.sdk.resources import OTELResourceDetector
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor

Expand Down Expand Up @@ -440,7 +439,8 @@ def tracer_provider(
def tracing_excluded_urls(
excluded_urls: str | list[str] | None = Provide[tracing.excluded_urls],
):
from opentelemetry.util.http import ExcludeList, parse_excluded_urls
from opentelemetry.util.http import ExcludeList
from opentelemetry.util.http import parse_excluded_urls

if isinstance(excluded_urls, list):
return ExcludeList(excluded_urls)
Expand All @@ -463,7 +463,8 @@ def duration_buckets(
the Prometheus default is returned; otherwise, a set of exponential buckets
generated based on the configuration is returned.
"""
from ..utils.metrics import INF, exponential_buckets
from ..utils.metrics import INF
from ..utils.metrics import exponential_buckets

if "buckets" in duration:
return tuple(duration["buckets"]) + (INF,)
Expand Down
20 changes: 9 additions & 11 deletions src/bentoml/_internal/configuration/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@

from ...utils.metrics import DEFAULT_BUCKET
from ...utils.unflatten import unflatten
from ..helpers import (
depth,
ensure_iterable_type,
ensure_larger_than,
ensure_larger_than_zero,
ensure_range,
is_valid_ip_address,
rename_fields,
validate_otlp_protocol,
validate_tracing_type,
)
from ..helpers import depth
from ..helpers import ensure_iterable_type
from ..helpers import ensure_larger_than
from ..helpers import ensure_larger_than_zero
from ..helpers import ensure_range
from ..helpers import is_valid_ip_address
from ..helpers import rename_fields
from ..helpers import validate_otlp_protocol
from ..helpers import validate_tracing_type

TRACING_CFG = {
"exporter_type": s.Or(s.And(str, s.Use(str.lower), validate_tracing_type), None),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,7 @@ api_server:
namespace: bentoml_api_server
duration:
# https://github.com/prometheus/client_python/blob/f17a8361ad3ed5bc47f193ac03b00911120a8d81/prometheus_client/metrics.py#L544
buckets:
[
0.005,
0.01,
0.025,
0.05,
0.075,
0.1,
0.25,
0.5,
0.75,
1.0,
2.5,
5.0,
7.5,
10.0,
]
buckets: [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1.0, 2.5, 5.0, 7.5, 10.0]
min: ~
max: ~
factor: ~
Expand Down
18 changes: 8 additions & 10 deletions src/bentoml/_internal/configuration/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@

from ...utils.metrics import DEFAULT_BUCKET
from ...utils.unflatten import unflatten
from ..helpers import (
depth,
ensure_iterable_type,
ensure_larger_than,
ensure_larger_than_zero,
ensure_range,
is_valid_ip_address,
validate_otlp_protocol,
validate_tracing_type,
)
from ..helpers import depth
from ..helpers import ensure_iterable_type
from ..helpers import ensure_larger_than
from ..helpers import ensure_larger_than_zero
from ..helpers import ensure_range
from ..helpers import is_valid_ip_address
from ..helpers import validate_otlp_protocol
from ..helpers import validate_tracing_type

TRACING_CFG = {
"exporter_type": s.Or(s.And(str, s.Use(str.lower), validate_tracing_type), None),
Expand Down
20 changes: 2 additions & 18 deletions src/bentoml/_internal/configuration/v2/default_configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,7 @@ services:
namespace: bentoml_service
duration:
# https://github.com/prometheus/client_python/blob/f17a8361ad3ed5bc47f193ac03b00911120a8d81/prometheus_client/metrics.py#L544
buckets:
[
0.005,
0.01,
0.025,
0.05,
0.075,
0.1,
0.25,
0.5,
0.75,
1.0,
2.5,
5.0,
7.5,
10.0,
]
buckets: [0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1.0, 2.5, 5.0, 7.5, 10.0]
min: ~
max: ~
factor: ~
Expand All @@ -45,7 +29,7 @@ services:
request_content_type: true
response_content_length: true
response_content_type: true
skip_paths: ["/metrics", "/healthz", "/livez", "/readyz"]
skip_paths: ['/metrics', '/healthz', '/livez', '/readyz']
format:
trace_id: 032x
span_id: 016x
Expand Down
17 changes: 9 additions & 8 deletions src/bentoml/bentos.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@
import tempfile
import typing as t

from simple_di import Provide, inject
from simple_di import Provide
from simple_di import inject

from ._internal.bento import Bento
from ._internal.bento.build_config import BentoBuildConfig
from ._internal.configuration.containers import BentoMLContainer
from ._internal.tag import Tag
from ._internal.utils import resolve_user_filepath
from .exceptions import BadInput, BentoMLException, InvalidArgument
from .exceptions import BadInput
from .exceptions import BentoMLException
from .exceptions import InvalidArgument

if t.TYPE_CHECKING:
from ._internal.bento import BentoStore
from ._internal.bento.build_config import (
CondaOptions,
DockerOptions,
ModelSpec,
PythonOptions,
)
from ._internal.bento.build_config import CondaOptions
from ._internal.bento.build_config import DockerOptions
from ._internal.bento.build_config import ModelSpec
from ._internal.bento.build_config import PythonOptions
from ._internal.cloud import BentoCloudClient
from .server import Server

Expand Down
9 changes: 6 additions & 3 deletions src/bentoml/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
from pathlib import Path

import psutil
from simple_di import Provide, inject
from simple_di import Provide
from simple_di import inject

from bentoml._internal.log import SERVER_LOGGING_CONFIG

from ._internal.configuration.containers import BentoMLContainer
from ._internal.runner.runner import Runner
from ._internal.utils import is_async_callable
from .exceptions import BentoMLConfigException, BentoMLException
from .exceptions import BentoMLConfigException
from .exceptions import BentoMLException
from .grpc.utils import LATEST_PROTOCOL_VERSION

if t.TYPE_CHECKING:
Expand Down Expand Up @@ -327,7 +329,8 @@ def serve_http_production(
prometheus_dir = ensure_prometheus_dir()

import ipaddress
from socket import AF_INET, AF_INET6
from socket import AF_INET
from socket import AF_INET6

from circus.sockets import CircusSocket

Expand Down
13 changes: 9 additions & 4 deletions src/bentoml/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import sys
import textwrap
import typing as t
from abc import ABC, abstractmethod
from abc import ABC
from abc import abstractmethod
from typing import TYPE_CHECKING
from warnings import warn

from simple_di import Provide, inject
from simple_di import Provide
from simple_di import inject

from ._internal.bento import Bento
from ._internal.client import Client
Expand All @@ -21,7 +23,9 @@
from ._internal.service import Service
from ._internal.tag import Tag
from ._internal.utils.analytics.usage_stats import BENTOML_SERVE_FROM_SERVER_API
from .exceptions import InvalidArgument, ServerStateException, UnservableException
from .exceptions import InvalidArgument
from .exceptions import ServerStateException
from .exceptions import UnservableException

if TYPE_CHECKING:
from types import TracebackType
Expand Down Expand Up @@ -339,7 +343,8 @@ def __init__(
],
):
# hacky workaround to prevent bentoml.serve being overwritten immediately
from .serve import construct_ssl_args, construct_timeouts_args
from .serve import construct_ssl_args
from .serve import construct_timeouts_args

super().__init__(
bento,
Expand Down

0 comments on commit 9f2847e

Please sign in to comment.