diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8e613da347a..a6d6c52f217 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,8 +2,8 @@ ci: autoupdate_schedule: monthly exclude: '.*\.(css|js|svg)$' repos: - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: 'v0.0.274' + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: 'v0.0.277' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix, --show-fixes] diff --git a/docs/source/frameworks/diffusers.rst b/docs/source/frameworks/diffusers.rst index a949fe843d2..de5299ca4f6 100644 --- a/docs/source/frameworks/diffusers.rst +++ b/docs/source/frameworks/diffusers.rst @@ -18,7 +18,7 @@ You can import a pretrained diffusion model from huggingface hub or local direct "sd2.1", # model tag in BentoML model store "stabilityai/stable-diffusion-2-1", # huggingface model name ) - + If you plan to use the model with a custom pipeline that has method other than :code:`__call__` (e.g. a :code:`StableDiffusionMegaPipeline`), you need to explicitly list them like this: diff --git a/examples/custom_model_runner/locustfile.py b/examples/custom_model_runner/locustfile.py index e33e8eed12c..08a14b33c85 100644 --- a/examples/custom_model_runner/locustfile.py +++ b/examples/custom_model_runner/locustfile.py @@ -1,6 +1,6 @@ -from locust import task -from locust import between from locust import HttpUser +from locust import between +from locust import task class MnistTestUser(HttpUser): diff --git a/examples/custom_model_runner/train.py b/examples/custom_model_runner/train.py index 9c3729fb557..20d39aaf574 100644 --- a/examples/custom_model_runner/train.py +++ b/examples/custom_model_runner/train.py @@ -4,12 +4,12 @@ import net import torch -import torch.optim as optim import torch.nn.functional as F +import torch.optim as optim +from torch.optim.lr_scheduler import StepLR +from torch.utils.data import DataLoader from torchvision import datasets from torchvision import transforms -from torch.utils.data import DataLoader -from torch.optim.lr_scheduler import StepLR def train(args, model, device, train_loader, optimizer, epoch): diff --git a/examples/custom_runner/nltk_pretrained_model/service.py b/examples/custom_runner/nltk_pretrained_model/service.py index a3adb6a70e1..37dd17fd02f 100644 --- a/examples/custom_runner/nltk_pretrained_model/service.py +++ b/examples/custom_runner/nltk_pretrained_model/service.py @@ -2,8 +2,8 @@ import time import typing as t -from typing import TYPE_CHECKING from statistics import mean +from typing import TYPE_CHECKING import nltk from nltk.sentiment import SentimentIntensityAnalyzer diff --git a/examples/custom_web_serving/fastapi_example/train.py b/examples/custom_web_serving/fastapi_example/train.py index 6afeda9ebb2..5af911d0b70 100644 --- a/examples/custom_web_serving/fastapi_example/train.py +++ b/examples/custom_web_serving/fastapi_example/train.py @@ -1,8 +1,8 @@ import logging import pandas as pd -from sklearn import svm from sklearn import datasets +from sklearn import svm import bentoml diff --git a/examples/custom_web_serving/flask_example/train.py b/examples/custom_web_serving/flask_example/train.py index 2f1bc082392..122186740f4 100644 --- a/examples/custom_web_serving/flask_example/train.py +++ b/examples/custom_web_serving/flask_example/train.py @@ -1,7 +1,7 @@ import logging -from sklearn import svm from sklearn import datasets +from sklearn import svm import bentoml diff --git a/examples/flax/MNIST/tests/conftest.py b/examples/flax/MNIST/tests/conftest.py index 4001e182621..4123305a82e 100644 --- a/examples/flax/MNIST/tests/conftest.py +++ b/examples/flax/MNIST/tests/conftest.py @@ -1,26 +1,26 @@ from __future__ import annotations +import contextlib import os +import subprocess import sys import typing as t -import contextlib -import subprocess from typing import TYPE_CHECKING import psutil import pytest import bentoml -from bentoml.testing.server import host_bento from bentoml._internal.configuration.containers import BentoMLContainer +from bentoml.testing.server import host_bento if TYPE_CHECKING: from contextlib import ExitStack - from _pytest.main import Session - from _pytest.nodes import Item from _pytest.config import Config from _pytest.fixtures import FixtureRequest as _PytestFixtureRequest + from _pytest.main import Session + from _pytest.nodes import Item class FixtureRequest(_PytestFixtureRequest): param: str diff --git a/examples/flax/MNIST/tests/test_endpoints.py b/examples/flax/MNIST/tests/test_endpoints.py index 1c4f452b33f..9e9a8e42dc8 100644 --- a/examples/flax/MNIST/tests/test_endpoints.py +++ b/examples/flax/MNIST/tests/test_endpoints.py @@ -7,8 +7,8 @@ import pytest import bentoml -from bentoml.testing.grpc import create_channel from bentoml.testing.grpc import async_client_call +from bentoml.testing.grpc import create_channel if t.TYPE_CHECKING: import jax.numpy as jnp diff --git a/examples/flax/MNIST/train.py b/examples/flax/MNIST/train.py index 98095b93e21..67e7314b8c1 100644 --- a/examples/flax/MNIST/train.py +++ b/examples/flax/MNIST/train.py @@ -1,17 +1,17 @@ # modified from https://github.com/google/flax/blob/main/examples/mnist/README.md from __future__ import annotations +import argparse import os import typing as t -import argparse from typing import TYPE_CHECKING -import jax import attrs -import numpy as np -import optax import cattrs +import jax import jax.numpy as jnp +import numpy as np +import optax import tensorflow_datasets as tfds from flax import linen as nn from flax import serialization diff --git a/examples/fraud_detection/benchmark/fastapi_main_load_model.py b/examples/fraud_detection/benchmark/fastapi_main_load_model.py index ef89b9ae9d9..5bfe1312d47 100644 --- a/examples/fraud_detection/benchmark/fastapi_main_load_model.py +++ b/examples/fraud_detection/benchmark/fastapi_main_load_model.py @@ -2,9 +2,9 @@ import numpy as np import pandas as pd -from sample import sample_input from fastapi import FastAPI from fastapi import Request +from sample import sample_input import bentoml diff --git a/examples/fraud_detection/benchmark/fastapi_main_local_runner.py b/examples/fraud_detection/benchmark/fastapi_main_local_runner.py index 0358fa021cc..0f11113aa9f 100644 --- a/examples/fraud_detection/benchmark/fastapi_main_local_runner.py +++ b/examples/fraud_detection/benchmark/fastapi_main_local_runner.py @@ -2,9 +2,9 @@ import numpy as np import pandas as pd -from sample import sample_input from fastapi import FastAPI from fastapi import Request +from sample import sample_input import bentoml diff --git a/examples/fraud_detection/benchmark/locustfile.py b/examples/fraud_detection/benchmark/locustfile.py index fcd20c1fae4..b85efab8951 100644 --- a/examples/fraud_detection/benchmark/locustfile.py +++ b/examples/fraud_detection/benchmark/locustfile.py @@ -1,8 +1,8 @@ import numpy as np import pandas as pd -from locust import task -from locust import between from locust import HttpUser +from locust import between +from locust import task NUM_OF_ROWS = 500 test_transactions = pd.read_csv("../data/test_transaction.csv")[0:NUM_OF_ROWS] diff --git a/examples/kfserving/train.py b/examples/kfserving/train.py index 2f1bc082392..122186740f4 100644 --- a/examples/kfserving/train.py +++ b/examples/kfserving/train.py @@ -1,7 +1,7 @@ import logging -from sklearn import svm from sklearn import datasets +from sklearn import svm import bentoml diff --git a/examples/mlflow/keras/train.py b/examples/mlflow/keras/train.py index 6c448be6860..828d4390697 100644 --- a/examples/mlflow/keras/train.py +++ b/examples/mlflow/keras/train.py @@ -2,17 +2,16 @@ on the Reuters newswire topic classification task. """ # pylint: disable=no-name-in-module -import numpy as np - # The following import and function call are the only additions to code required # to automatically log metrics and parameters to MLflow. import mlflow.keras +import numpy as np from tensorflow import keras +from tensorflow.keras.datasets import reuters +from tensorflow.keras.layers import Activation from tensorflow.keras.layers import Dense from tensorflow.keras.layers import Dropout -from tensorflow.keras.layers import Activation from tensorflow.keras.models import Sequential -from tensorflow.keras.datasets import reuters from tensorflow.keras.preprocessing.text import Tokenizer import bentoml diff --git a/examples/mlflow/lightgbm/train.py b/examples/mlflow/lightgbm/train.py index f30eef23b96..4ccdbd8dd58 100644 --- a/examples/mlflow/lightgbm/train.py +++ b/examples/mlflow/lightgbm/train.py @@ -1,12 +1,12 @@ import argparse -import mlflow import lightgbm as lgb import matplotlib as mpl +import mlflow import mlflow.lightgbm from sklearn import datasets -from sklearn.metrics import log_loss from sklearn.metrics import accuracy_score +from sklearn.metrics import log_loss from sklearn.model_selection import train_test_split import bentoml diff --git a/examples/mlflow/pytorch/mnist.py b/examples/mlflow/pytorch/mnist.py index 356a7baa0f4..317bf085d21 100644 --- a/examples/mlflow/pytorch/mnist.py +++ b/examples/mlflow/pytorch/mnist.py @@ -11,15 +11,15 @@ # # BentoML example is based on https://github.com/mlflow/mlflow/blob/master/examples/pytorch/mnist_tensorboard_artifact.py # -import os import argparse +import os -import torch import mlflow -import torch.nn as nn -import torch.optim as optim import mlflow.pytorch +import torch +import torch.nn as nn import torch.nn.functional as F +import torch.optim as optim from torchvision import datasets from torchvision import transforms diff --git a/examples/mlflow/sklearn_autolog/grid_search_cv.py b/examples/mlflow/sklearn_autolog/grid_search_cv.py index f687901715c..10693792002 100644 --- a/examples/mlflow/sklearn_autolog/grid_search_cv.py +++ b/examples/mlflow/sklearn_autolog/grid_search_cv.py @@ -2,10 +2,10 @@ import mlflow import pandas as pd -from utils import fetch_logged_data -from sklearn import svm from sklearn import datasets +from sklearn import svm from sklearn.model_selection import GridSearchCV +from utils import fetch_logged_data import bentoml diff --git a/examples/mlflow/sklearn_autolog/linear_regression.py b/examples/mlflow/sklearn_autolog/linear_regression.py index 8e8eb2351c3..052680fc1fb 100644 --- a/examples/mlflow/sklearn_autolog/linear_regression.py +++ b/examples/mlflow/sklearn_autolog/linear_regression.py @@ -1,9 +1,9 @@ from pprint import pprint -import numpy as np import mlflow -from utils import fetch_logged_data +import numpy as np from sklearn.linear_model import LinearRegression +from utils import fetch_logged_data import bentoml diff --git a/examples/mlflow/sklearn_autolog/pipeline.py b/examples/mlflow/sklearn_autolog/pipeline.py index 8e90429c18f..d18c6e9f250 100644 --- a/examples/mlflow/sklearn_autolog/pipeline.py +++ b/examples/mlflow/sklearn_autolog/pipeline.py @@ -1,11 +1,11 @@ from pprint import pprint -import numpy as np import mlflow -from utils import fetch_logged_data -from sklearn.pipeline import Pipeline +import numpy as np from sklearn.linear_model import LinearRegression +from sklearn.pipeline import Pipeline from sklearn.preprocessing import StandardScaler +from utils import fetch_logged_data import bentoml diff --git a/examples/mlflow/sklearn_logistic_regression/train.py b/examples/mlflow/sklearn_logistic_regression/train.py index 19405f458b8..13df8ee6f30 100644 --- a/examples/mlflow/sklearn_logistic_regression/train.py +++ b/examples/mlflow/sklearn_logistic_regression/train.py @@ -1,6 +1,6 @@ -import numpy as np import mlflow import mlflow.sklearn +import numpy as np from sklearn.linear_model import LogisticRegression import bentoml diff --git a/examples/mlflow/torchscript/IrisClassification/iris_classification.py b/examples/mlflow/torchscript/IrisClassification/iris_classification.py index ffa716d131b..2ad22486009 100644 --- a/examples/mlflow/torchscript/IrisClassification/iris_classification.py +++ b/examples/mlflow/torchscript/IrisClassification/iris_classification.py @@ -1,13 +1,13 @@ # pylint: disable=abstract-method,redefined-outer-name import argparse +import mlflow.pytorch import numpy as np import torch import torch.nn as nn -import mlflow.pytorch import torch.nn.functional as F -from sklearn.metrics import accuracy_score from sklearn.datasets import load_iris +from sklearn.metrics import accuracy_score from sklearn.model_selection import train_test_split import bentoml diff --git a/examples/mlflow/torchscript/MNIST/mnist_torchscript.py b/examples/mlflow/torchscript/MNIST/mnist_torchscript.py index f16dd317553..e1f4a79a171 100644 --- a/examples/mlflow/torchscript/MNIST/mnist_torchscript.py +++ b/examples/mlflow/torchscript/MNIST/mnist_torchscript.py @@ -2,16 +2,16 @@ import argparse +import mlflow +import mlflow.pytorch import numpy as np import torch -import mlflow import torch.nn as nn -import torch.optim as optim -import mlflow.pytorch import torch.nn.functional as F +import torch.optim as optim +from torch.optim.lr_scheduler import StepLR from torchvision import datasets from torchvision import transforms -from torch.optim.lr_scheduler import StepLR import bentoml diff --git a/examples/monitoring/task_classification/locustfile.py b/examples/monitoring/task_classification/locustfile.py index c529d88c0d0..8021cf373c0 100644 --- a/examples/monitoring/task_classification/locustfile.py +++ b/examples/monitoring/task_classification/locustfile.py @@ -1,7 +1,7 @@ import numpy as np -from locust import task -from locust import between from locust import HttpUser +from locust import between +from locust import task from sklearn import datasets test_data = datasets.load_iris().data diff --git a/examples/monitoring/task_classification/service.py b/examples/monitoring/task_classification/service.py index c9602b02ca6..b368426992c 100644 --- a/examples/monitoring/task_classification/service.py +++ b/examples/monitoring/task_classification/service.py @@ -5,8 +5,8 @@ import numpy as np import bentoml -from bentoml.io import Text from bentoml.io import NumpyNdarray +from bentoml.io import Text CLASS_NAMES = ["setosa", "versicolor", "virginica"] diff --git a/examples/monitoring/task_classification/tests/conftest.py b/examples/monitoring/task_classification/tests/conftest.py index 023976663f4..6e6dde3cec0 100644 --- a/examples/monitoring/task_classification/tests/conftest.py +++ b/examples/monitoring/task_classification/tests/conftest.py @@ -1,10 +1,10 @@ from __future__ import annotations +import contextlib import os +import subprocess import sys import typing as t -import contextlib -import subprocess from pathlib import Path import numpy as np @@ -14,11 +14,11 @@ from bentoml._internal.configuration.containers import BentoMLContainer if t.TYPE_CHECKING: + from _pytest.config import Config + from _pytest.fixtures import FixtureRequest from _pytest.main import Session from _pytest.nodes import Item - from _pytest.config import Config from _pytest.tmpdir import TempPathFactory - from _pytest.fixtures import FixtureRequest PROJECT_DIR = Path(__file__).parent.parent diff --git a/examples/monitoring/task_classification/train.py b/examples/monitoring/task_classification/train.py index 2f1bc082392..122186740f4 100644 --- a/examples/monitoring/task_classification/train.py +++ b/examples/monitoring/task_classification/train.py @@ -1,7 +1,7 @@ import logging -from sklearn import svm from sklearn import datasets +from sklearn import svm import bentoml diff --git a/examples/pydantic_validation/train.py b/examples/pydantic_validation/train.py index 6afeda9ebb2..5af911d0b70 100644 --- a/examples/pydantic_validation/train.py +++ b/examples/pydantic_validation/train.py @@ -1,8 +1,8 @@ import logging import pandas as pd -from sklearn import svm from sklearn import datasets +from sklearn import svm import bentoml diff --git a/examples/pytorch_mnist/locustfile.py b/examples/pytorch_mnist/locustfile.py index b62fdd54733..c9bdd3de8ac 100644 --- a/examples/pytorch_mnist/locustfile.py +++ b/examples/pytorch_mnist/locustfile.py @@ -1,6 +1,6 @@ -from locust import task -from locust import between from locust import HttpUser +from locust import between +from locust import task with open("samples/1.png", "rb") as f: test_image_bytes = f.read() diff --git a/examples/pytorch_mnist/tests/conftest.py b/examples/pytorch_mnist/tests/conftest.py index dc35d5f4fe8..8043b60da4e 100644 --- a/examples/pytorch_mnist/tests/conftest.py +++ b/examples/pytorch_mnist/tests/conftest.py @@ -9,8 +9,8 @@ def pytest_configure(config): # pylint: disable=unused-argument import os - import sys import subprocess + import sys cmd = f"{sys.executable} {os.path.join(os.getcwd(), 'train.py')} --k-folds=0" subprocess.run(cmd, shell=True, check=True) diff --git a/examples/pytorch_mnist/train.py b/examples/pytorch_mnist/train.py index fadbbea6436..6cd630edf86 100644 --- a/examples/pytorch_mnist/train.py +++ b/examples/pytorch_mnist/train.py @@ -1,15 +1,15 @@ # pylint: disable=redefined-outer-name +import argparse import os import random -import argparse import model as models import numpy as np import torch +from sklearn.model_selection import KFold from torch import nn from torchvision import transforms from torchvision.datasets import MNIST -from sklearn.model_selection import KFold import bentoml diff --git a/examples/quickstart/locustfile.py b/examples/quickstart/locustfile.py index 5a30e0eabcf..52a223196e1 100644 --- a/examples/quickstart/locustfile.py +++ b/examples/quickstart/locustfile.py @@ -2,10 +2,10 @@ import grpc import numpy as np -from locust import task +from locust import HttpUser from locust import User from locust import between -from locust import HttpUser +from locust import task from sklearn import datasets from bentoml.grpc.v1 import service_pb2 as pb diff --git a/examples/quickstart/train.py b/examples/quickstart/train.py index 9cb15bb28ce..5680d60f9cf 100644 --- a/examples/quickstart/train.py +++ b/examples/quickstart/train.py @@ -1,7 +1,7 @@ import logging -from sklearn import svm from sklearn import datasets +from sklearn import svm import bentoml diff --git a/examples/sklearn/pipeline/train.py b/examples/sklearn/pipeline/train.py index 6e38e5d9fac..aa9ee1a5ee4 100644 --- a/examples/sklearn/pipeline/train.py +++ b/examples/sklearn/pipeline/train.py @@ -1,13 +1,13 @@ import logging -from time import time from pprint import pprint +from time import time from sklearn.datasets import fetch_20newsgroups -from sklearn.pipeline import Pipeline -from sklearn.linear_model import SGDClassifier -from sklearn.model_selection import GridSearchCV from sklearn.feature_extraction.text import CountVectorizer from sklearn.feature_extraction.text import TfidfTransformer +from sklearn.linear_model import SGDClassifier +from sklearn.model_selection import GridSearchCV +from sklearn.pipeline import Pipeline import bentoml diff --git a/examples/tensorflow2_keras/locustfile.py b/examples/tensorflow2_keras/locustfile.py index 490fe59bea0..c4c8103eec6 100644 --- a/examples/tensorflow2_keras/locustfile.py +++ b/examples/tensorflow2_keras/locustfile.py @@ -1,6 +1,6 @@ -from locust import task -from locust import between from locust import HttpUser +from locust import between +from locust import task with open("samples/0.png", "rb") as f: test_image_bytes = f.read() diff --git a/examples/tensorflow2_keras/tests/conftest.py b/examples/tensorflow2_keras/tests/conftest.py index a3993314ce8..f8ebb4b4151 100644 --- a/examples/tensorflow2_keras/tests/conftest.py +++ b/examples/tensorflow2_keras/tests/conftest.py @@ -1,8 +1,8 @@ # pylint: disable=redefined-outer-name -import typing as t import pathlib import subprocess +import typing as t import pytest diff --git a/examples/tensorflow2_keras/tests/test_prediction.py b/examples/tensorflow2_keras/tests/test_prediction.py index 126952fe724..46070dcd530 100644 --- a/examples/tensorflow2_keras/tests/test_prediction.py +++ b/examples/tensorflow2_keras/tests/test_prediction.py @@ -1,8 +1,8 @@ # pylint: disable=redefined-outer-name # type: ignore[no-untyped-def] -import json import asyncio +import json import numpy as np import pytest diff --git a/examples/tensorflow2_keras/train.py b/examples/tensorflow2_keras/train.py index aa962e9f470..f5ea85f1493 100644 --- a/examples/tensorflow2_keras/train.py +++ b/examples/tensorflow2_keras/train.py @@ -1,8 +1,8 @@ # pylint: disable=no-name-in-module,redefined-outer-name,abstract-method import tensorflow as tf from tensorflow.keras import Model -from tensorflow.keras.layers import Dense from tensorflow.keras.layers import Conv2D +from tensorflow.keras.layers import Dense from tensorflow.keras.layers import Flatten import bentoml diff --git a/examples/tensorflow2_native/locustfile.py b/examples/tensorflow2_native/locustfile.py index 490fe59bea0..c4c8103eec6 100644 --- a/examples/tensorflow2_native/locustfile.py +++ b/examples/tensorflow2_native/locustfile.py @@ -1,6 +1,6 @@ -from locust import task -from locust import between from locust import HttpUser +from locust import between +from locust import task with open("samples/0.png", "rb") as f: test_image_bytes = f.read() diff --git a/examples/tensorflow2_native/tests/conftest.py b/examples/tensorflow2_native/tests/conftest.py index a3993314ce8..f8ebb4b4151 100644 --- a/examples/tensorflow2_native/tests/conftest.py +++ b/examples/tensorflow2_native/tests/conftest.py @@ -1,8 +1,8 @@ # pylint: disable=redefined-outer-name -import typing as t import pathlib import subprocess +import typing as t import pytest diff --git a/examples/tensorflow2_native/tests/test_prediction.py b/examples/tensorflow2_native/tests/test_prediction.py index 126952fe724..46070dcd530 100644 --- a/examples/tensorflow2_native/tests/test_prediction.py +++ b/examples/tensorflow2_native/tests/test_prediction.py @@ -1,8 +1,8 @@ # pylint: disable=redefined-outer-name # type: ignore[no-untyped-def] -import json import asyncio +import json import numpy as np import pytest diff --git a/examples/tensorflow2_native/train.py b/examples/tensorflow2_native/train.py index 759edc59f53..20219b7f0d7 100644 --- a/examples/tensorflow2_native/train.py +++ b/examples/tensorflow2_native/train.py @@ -1,7 +1,7 @@ # pylint: disable=no-name-in-module,redefined-outer-name,abstract-method import tensorflow as tf -from tensorflow.keras.layers import Dense from tensorflow.keras.layers import Conv2D +from tensorflow.keras.layers import Dense from tensorflow.keras.layers import Flatten import bentoml diff --git a/examples/triton/onnx/build_bento.py b/examples/triton/onnx/build_bento.py index d4cce38390c..41499d56891 100644 --- a/examples/triton/onnx/build_bento.py +++ b/examples/triton/onnx/build_bento.py @@ -1,17 +1,17 @@ from __future__ import annotations +import argparse import os import typing as t -import argparse import attr import torch import bentoml from bentoml import Bento -from bentoml._internal.utils import resolve_user_filepath from bentoml._internal.bento.build_config import BentoBuildConfig from bentoml._internal.configuration.containers import BentoMLContainer +from bentoml._internal.utils import resolve_user_filepath if __name__ == "__main__": parser = argparse.ArgumentParser() diff --git a/examples/triton/onnx/helpers.py b/examples/triton/onnx/helpers.py index b8300c08e60..c1111ac72a1 100644 --- a/examples/triton/onnx/helpers.py +++ b/examples/triton/onnx/helpers.py @@ -1,13 +1,13 @@ from __future__ import annotations -import os import json +import os import time import typing as t from pathlib import Path -import cv2 import attr +import cv2 import numpy as np import torch import torchvision diff --git a/examples/triton/onnx/locustfile.py b/examples/triton/onnx/locustfile.py index 69acf77bbb3..ddcf9540c11 100644 --- a/examples/triton/onnx/locustfile.py +++ b/examples/triton/onnx/locustfile.py @@ -1,8 +1,8 @@ from __future__ import annotations -from locust import task -from locust import constant from locust import HttpUser +from locust import constant +from locust import task class TritonOnnxYolov5User(HttpUser): diff --git a/examples/triton/onnx/serve_bento.py b/examples/triton/onnx/serve_bento.py index 5df7adf8995..f47c094a5e3 100644 --- a/examples/triton/onnx/serve_bento.py +++ b/examples/triton/onnx/serve_bento.py @@ -1,8 +1,8 @@ from __future__ import annotations if __name__ == "__main__": - import time import argparse + import time import bentoml diff --git a/examples/triton/onnx/service.py b/examples/triton/onnx/service.py index f599197e2d6..cf6d778effe 100644 --- a/examples/triton/onnx/service.py +++ b/examples/triton/onnx/service.py @@ -2,8 +2,8 @@ import typing as t -import torch import helpers +import torch import bentoml diff --git a/examples/triton/pytorch/build_bento.py b/examples/triton/pytorch/build_bento.py index 503a38d8747..9d8ac9f7c4e 100644 --- a/examples/triton/pytorch/build_bento.py +++ b/examples/triton/pytorch/build_bento.py @@ -1,17 +1,17 @@ from __future__ import annotations +import argparse import os import typing as t -import argparse import attr import torch import bentoml from bentoml import Bento -from bentoml._internal.utils import resolve_user_filepath from bentoml._internal.bento.build_config import BentoBuildConfig from bentoml._internal.configuration.containers import BentoMLContainer +from bentoml._internal.utils import resolve_user_filepath if __name__ == "__main__": parser = argparse.ArgumentParser() diff --git a/examples/triton/pytorch/helpers.py b/examples/triton/pytorch/helpers.py index b8300c08e60..c1111ac72a1 100644 --- a/examples/triton/pytorch/helpers.py +++ b/examples/triton/pytorch/helpers.py @@ -1,13 +1,13 @@ from __future__ import annotations -import os import json +import os import time import typing as t from pathlib import Path -import cv2 import attr +import cv2 import numpy as np import torch import torchvision diff --git a/examples/triton/pytorch/locustfile.py b/examples/triton/pytorch/locustfile.py index 48607666928..fb368db5b19 100644 --- a/examples/triton/pytorch/locustfile.py +++ b/examples/triton/pytorch/locustfile.py @@ -1,8 +1,8 @@ from __future__ import annotations -from locust import task -from locust import constant from locust import HttpUser +from locust import constant +from locust import task class TritonTorchscriptYolov5User(HttpUser): diff --git a/examples/triton/pytorch/serve_bento.py b/examples/triton/pytorch/serve_bento.py index ab84bf1de8f..cc1026dca41 100644 --- a/examples/triton/pytorch/serve_bento.py +++ b/examples/triton/pytorch/serve_bento.py @@ -1,8 +1,8 @@ from __future__ import annotations if __name__ == "__main__": - import time import argparse + import time import bentoml diff --git a/examples/triton/pytorch/service.py b/examples/triton/pytorch/service.py index 17ee3961069..b28d57370b8 100644 --- a/examples/triton/pytorch/service.py +++ b/examples/triton/pytorch/service.py @@ -2,8 +2,8 @@ import typing as t -import torch import helpers +import torch import bentoml diff --git a/examples/triton/tensorflow/build_bento.py b/examples/triton/tensorflow/build_bento.py index 9215a91a725..b95195f5b00 100644 --- a/examples/triton/tensorflow/build_bento.py +++ b/examples/triton/tensorflow/build_bento.py @@ -1,17 +1,17 @@ from __future__ import annotations +import argparse import os import typing as t -import argparse import attr import torch import bentoml from bentoml import Bento -from bentoml._internal.utils import resolve_user_filepath from bentoml._internal.bento.build_config import BentoBuildConfig from bentoml._internal.configuration.containers import BentoMLContainer +from bentoml._internal.utils import resolve_user_filepath if __name__ == "__main__": parser = argparse.ArgumentParser() diff --git a/examples/triton/tensorflow/helpers.py b/examples/triton/tensorflow/helpers.py index b8300c08e60..c1111ac72a1 100644 --- a/examples/triton/tensorflow/helpers.py +++ b/examples/triton/tensorflow/helpers.py @@ -1,13 +1,13 @@ from __future__ import annotations -import os import json +import os import time import typing as t from pathlib import Path -import cv2 import attr +import cv2 import numpy as np import torch import torchvision diff --git a/examples/triton/tensorflow/locustfile.py b/examples/triton/tensorflow/locustfile.py index 799535e9a86..67e21c219ad 100644 --- a/examples/triton/tensorflow/locustfile.py +++ b/examples/triton/tensorflow/locustfile.py @@ -1,8 +1,8 @@ from __future__ import annotations -from locust import task -from locust import constant from locust import HttpUser +from locust import constant +from locust import task class TritonTensorflowYolov5User(HttpUser): diff --git a/examples/triton/tensorflow/serve_bento.py b/examples/triton/tensorflow/serve_bento.py index aa0e98a3812..d2538ef9b4f 100644 --- a/examples/triton/tensorflow/serve_bento.py +++ b/examples/triton/tensorflow/serve_bento.py @@ -1,8 +1,8 @@ from __future__ import annotations if __name__ == "__main__": - import time import argparse + import time import bentoml diff --git a/examples/triton/tensorflow/service.py b/examples/triton/tensorflow/service.py index 6b001fad477..f782c79a3b9 100644 --- a/examples/triton/tensorflow/service.py +++ b/examples/triton/tensorflow/service.py @@ -2,9 +2,9 @@ import typing as t +import helpers import numpy as np import torch -import helpers import bentoml diff --git a/examples/tutorial/init_model.py b/examples/tutorial/init_model.py index 9dfae4e6816..aa3fe9a9423 100644 --- a/examples/tutorial/init_model.py +++ b/examples/tutorial/init_model.py @@ -1,6 +1,7 @@ -import bentoml import transformers +import bentoml + pipe = transformers.pipeline("text-classification") bentoml.transformers.save_model( diff --git a/examples/xgboost/locustfile.py b/examples/xgboost/locustfile.py index dc63b35f99e..d7a83026681 100644 --- a/examples/xgboost/locustfile.py +++ b/examples/xgboost/locustfile.py @@ -1,7 +1,7 @@ import numpy as np -from locust import task -from locust import between from locust import HttpUser +from locust import between +from locust import task from sklearn.datasets import load_svmlight_file test_data = load_svmlight_file("data/agaricus.txt.train") diff --git a/pyproject.toml b/pyproject.toml index 4bb1f95f630..8f2ca9d1ab7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -240,6 +240,7 @@ testpaths = ["tests"] line-length = 88 # We ignore E501 (line too long) here because we keep user-visible strings on one line. ignore = ["E501"] +extend-select = ["I"] exclude = [ "bazel-*/", "venv", diff --git a/src/bentoml/__init__.py b/src/bentoml/__init__.py index 7dcba4e7a24..16f9d270bd1 100644 --- a/src/bentoml/__init__.py +++ b/src/bentoml/__init__.py @@ -17,71 +17,71 @@ from typing import TYPE_CHECKING +from ._internal.configuration import BENTOML_VERSION as __version__ from ._internal.configuration import load_config from ._internal.configuration import save_config -from ._internal.configuration import BENTOML_VERSION as __version__ from ._internal.configuration import set_serialization_strategy # Inject dependencies and configurations load_config() +# BentoML built-in types +from ._internal.bento import Bento +from ._internal.cloud import YataiClient +from ._internal.context import ServiceContext as Context +from ._internal.models import Model +from ._internal.monitoring import monitor +from ._internal.runner import Runnable +from ._internal.runner import Runner +from ._internal.service import Service +from ._internal.service.loader import load +from ._internal.tag import Tag +from ._internal.utils.http import Cookie + # Bento management APIs +from .bentos import delete +from .bentos import export_bento from .bentos import get +from .bentos import import_bento from .bentos import list # pylint: disable=W0622 from .bentos import pull from .bentos import push from .bentos import serve -from .bentos import delete -from .bentos import export_bento -from .bentos import import_bento # server API from .server import GrpcServer from .server import HTTPServer -# BentoML built-in types -from ._internal.tag import Tag -from ._internal.bento import Bento -from ._internal.models import Model -from ._internal.runner import Runner -from ._internal.runner import Runnable -from ._internal.context import ServiceContext as Context -from ._internal.service import Service -from ._internal.monitoring import monitor -from ._internal.utils.http import Cookie -from ._internal.cloud import YataiClient -from ._internal.service.loader import load - # Framework specific modules, model management and IO APIs are lazily loaded upon import. if TYPE_CHECKING: - from . import h2o - from . import ray + from . import catboost + from . import detectron + from . import diffusers + from . import easyocr + from . import fastai from . import flax - from . import onnx from . import gluon + from . import h2o from . import keras - from . import spacy - from . import fastai + from . import lightgbm from . import mlflow + from . import onnx + from . import onnxmlir from . import paddle - from . import triton - from . import easyocr + from . import picklable_model from . import pycaret from . import pytorch + from . import pytorch_lightning + from . import ray from . import sklearn - from . import xgboost - from . import catboost - from . import lightgbm - from . import onnxmlir - from . import detectron - from . import diffusers - from . import tensorflow + from . import spacy from . import statsmodels + from . import tensorflow + from . import tensorflow_v1 from . import torchscript from . import transformers - from . import tensorflow_v1 - from . import picklable_model - from . import pytorch_lightning + from . import triton + from . import xgboost # isort: off from . import io diff --git a/src/bentoml/_internal/batch/spark.py b/src/bentoml/_internal/batch/spark.py index 6f8c432aec4..09b02f950e6 100644 --- a/src/bentoml/_internal/batch/spark.py +++ b/src/bentoml/_internal/batch/spark.py @@ -1,22 +1,22 @@ from __future__ import annotations -import typing as t import logging import os.path import tempfile +import typing as t from typing import TYPE_CHECKING from bentoml._internal.utils import reserve_free_port -from ..tag import Tag -from ..bento import Bento -from ...bentos import serve from ...bentos import import_bento +from ...bentos import serve from ...client import Client from ...client import HTTPClient from ...exceptions import BentoMLException from ...exceptions import MissingDependencyException +from ..bento import Bento from ..service.loader import load_bento +from ..tag import Tag try: from pyspark.files import SparkFiles @@ -27,8 +27,8 @@ ) if TYPE_CHECKING: - import pyspark.sql.session import pyspark.sql.dataframe + import pyspark.sql.session RecordBatch: t.TypeAlias = t.Any # pyarrow doesn't have type annotations diff --git a/src/bentoml/_internal/bento/bento.py b/src/bentoml/_internal/bento/bento.py index cd2dbe00a15..ee71a906301 100644 --- a/src/bentoml/_internal/bento/bento.py +++ b/src/bentoml/_internal/bento/bento.py @@ -1,45 +1,46 @@ from __future__ import annotations +import logging import os import typing as t -import logging -from typing import TYPE_CHECKING from datetime import datetime from datetime import timezone +from typing import TYPE_CHECKING -import fs import attr -import yaml -import fs.osfs +import fs import fs.errors import fs.mirror +import fs.osfs import fs.walk -from fs.copy import copy_file -from cattr.gen import override +import yaml from cattr.gen import make_dict_structure_fn from cattr.gen import make_dict_unstructure_fn -from simple_di import inject +from cattr.gen import override +from fs.copy import copy_file from simple_di import Provide +from simple_di import inject -from ..tag import Tag +from ...exceptions import BentoMLException +from ...exceptions import InvalidArgument +from ..configuration import BENTOML_VERSION +from ..configuration.containers import BentoMLContainer +from ..models import ModelStore +from ..models import copy_model +from ..runner import Runner from ..store import Store from ..store import StoreItem +from ..tag import Tag from ..types import PathType from ..utils import bentoml_cattr -from ..utils import encode_path_for_uri from ..utils import copy_file_to_fs_folder +from ..utils import encode_path_for_uri from ..utils import normalize_labels_value -from ..models import ModelStore, copy_model -from ..runner import Runner -from ...exceptions import InvalidArgument -from ...exceptions import BentoMLException -from .build_config import CondaOptions +from .build_config import BentoBuildConfig from .build_config import BentoPathSpec +from .build_config import CondaOptions from .build_config import DockerOptions from .build_config import PythonOptions -from .build_config import BentoBuildConfig -from ..configuration import BENTOML_VERSION -from ..configuration.containers import BentoMLContainer if TYPE_CHECKING: from fs.base import FS diff --git a/src/bentoml/_internal/bento/build_config.py b/src/bentoml/_internal/bento/build_config.py index 6955c6effa0..a8554e48af7 100644 --- a/src/bentoml/_internal/bento/build_config.py +++ b/src/bentoml/_internal/bento/build_config.py @@ -1,37 +1,37 @@ from __future__ import annotations +import logging import os import re +import subprocess import sys import typing as t -import logging -import subprocess -from sys import version_info from shlex import quote +from sys import version_info -import fs import attr -import yaml -import psutil +import fs import fs.copy +import psutil +import yaml from pathspec import PathSpec -from ..utils import bentoml_cattr -from ..utils import resolve_user_filepath -from ..utils import copy_file_to_fs_folder -from ..container import generate_containerfile -from ...exceptions import InvalidArgument from ...exceptions import BentoMLException -from ..utils.dotenv import parse_dotenv +from ...exceptions import InvalidArgument from ..configuration import CLEAN_BENTOML_VERSION -from ..container.generate import BENTO_PATH -from .build_dev_bentoml_whl import build_bentoml_editable_wheel -from ..container.frontend.dockerfile import DistroSpec -from ..container.frontend.dockerfile import get_supported_spec -from ..container.frontend.dockerfile import SUPPORTED_CUDA_VERSIONS +from ..container import generate_containerfile from ..container.frontend.dockerfile import ALLOWED_CUDA_VERSION_ARGS -from ..container.frontend.dockerfile import SUPPORTED_PYTHON_VERSIONS from ..container.frontend.dockerfile import CONTAINER_SUPPORTED_DISTROS +from ..container.frontend.dockerfile import SUPPORTED_CUDA_VERSIONS +from ..container.frontend.dockerfile import SUPPORTED_PYTHON_VERSIONS +from ..container.frontend.dockerfile import DistroSpec +from ..container.frontend.dockerfile import get_supported_spec +from ..container.generate import BENTO_PATH +from ..utils import bentoml_cattr +from ..utils import copy_file_to_fs_folder +from ..utils import resolve_user_filepath +from ..utils.dotenv import parse_dotenv +from .build_dev_bentoml_whl import build_bentoml_editable_wheel if t.TYPE_CHECKING: from attr import Attribute diff --git a/src/bentoml/_internal/bento/build_dev_bentoml_whl.py b/src/bentoml/_internal/bento/build_dev_bentoml_whl.py index 0476dd081bf..bcd3eb7648b 100644 --- a/src/bentoml/_internal/bento/build_dev_bentoml_whl.py +++ b/src/bentoml/_internal/bento/build_dev_bentoml_whl.py @@ -1,14 +1,14 @@ from __future__ import annotations -import os import logging +import os from pathlib import Path -from ..utils.pkg import source_locations from ...exceptions import BentoMLException from ...exceptions import MissingDependencyException from ...grpc.utils import LATEST_PROTOCOL_VERSION from ..configuration import is_pypi_installed_bentoml +from ..utils.pkg import source_locations logger = logging.getLogger(__name__) @@ -35,9 +35,8 @@ def build_bentoml_editable_wheel( # different from build. However, isort sometimes # incorrectly re-order the imports order. # isort: off - from build.env import IsolatedEnvBuilder - from build import ProjectBuilder + from build.env import IsolatedEnvBuilder # isort: on except ModuleNotFoundError as e: diff --git a/src/bentoml/_internal/client/__init__.py b/src/bentoml/_internal/client/__init__.py index e67874075b3..f380a7b9d55 100644 --- a/src/bentoml/_internal/client/__init__.py +++ b/src/bentoml/_internal/client/__init__.py @@ -1,9 +1,9 @@ from __future__ import annotations -import typing as t import asyncio -import logging import functools +import logging +import typing as t from abc import ABC from abc import abstractmethod from http.client import BadStatusLine @@ -16,9 +16,9 @@ if t.TYPE_CHECKING: from types import TracebackType + from ..service import Service from .grpc import GrpcClient from .http import HTTPClient - from ..service import Service class Client(ABC): diff --git a/src/bentoml/_internal/client/grpc.py b/src/bentoml/_internal/client/grpc.py index 2156e155b16..a55e706d768 100644 --- a/src/bentoml/_internal/client/grpc.py +++ b/src/bentoml/_internal/client/grpc.py @@ -1,24 +1,24 @@ from __future__ import annotations +import functools +import logging import time import typing as t -import logging -import functools +from functools import cached_property from typing import TYPE_CHECKING from packaging.version import parse -from . import Client -from .. import io_descriptors -from ..utils import LazyLoader -from functools import cached_property -from ..service import Service from ...exceptions import BentoMLException +from ...grpc.utils import LATEST_PROTOCOL_VERSION +from ...grpc.utils import import_generated_stubs from ...grpc.utils import import_grpc from ...grpc.utils import load_from_file -from ...grpc.utils import import_generated_stubs -from ...grpc.utils import LATEST_PROTOCOL_VERSION +from .. import io_descriptors +from ..service import Service from ..service.inference_api import InferenceAPI +from ..utils import LazyLoader +from . import Client logger = logging.getLogger(__name__) @@ -27,14 +27,14 @@ if TYPE_CHECKING: import grpc + from google.protobuf import json_format as _json_format from grpc import aio from grpc._channel import Channel as GrpcSyncChannel from grpc_health.v1 import health_pb2 as pb_health - from google.protobuf import json_format as _json_format - from ..types import PathType from ...grpc.v1.service_pb2 import Response from ...grpc.v1.service_pb2 import ServiceMetadataResponse + from ..types import PathType class ClientCredentials(t.TypedDict): root_certificates: t.NotRequired[PathType | bytes] diff --git a/src/bentoml/_internal/client/http.py b/src/bentoml/_internal/client/http.py index f4e6cda77ae..f2eb1b31a48 100644 --- a/src/bentoml/_internal/client/http.py +++ b/src/bentoml/_internal/client/http.py @@ -1,27 +1,27 @@ from __future__ import annotations +import asyncio import json -import time +import logging import socket +import time import typing as t -import asyncio -import logging import urllib.error import urllib.request from http.client import HTTPConnection from urllib.parse import urlparse import aiohttp -import starlette.requests import starlette.datastructures +import starlette.requests -from . import Client -from .. import io_descriptors as io -from ..service import Service -from ...exceptions import RemoteException from ...exceptions import BentoMLException +from ...exceptions import RemoteException +from .. import io_descriptors as io from ..configuration import get_debug_mode +from ..service import Service from ..service.inference_api import InferenceAPI +from . import Client logger = logging.getLogger(__name__) diff --git a/src/bentoml/_internal/cloud/__init__.py b/src/bentoml/_internal/cloud/__init__.py index dc1a77ad468..97e73790b1e 100644 --- a/src/bentoml/_internal/cloud/__init__.py +++ b/src/bentoml/_internal/cloud/__init__.py @@ -1,4 +1,4 @@ from .base import CloudClient as CloudClient from .bentocloud import BentoCloudClient as BentoCloudClient -from .yatai import YataiClient as YataiClient from .deployment import Resource as Resource +from .yatai import YataiClient as YataiClient diff --git a/src/bentoml/_internal/cloud/base.py b/src/bentoml/_internal/cloud/base.py index 6c1c93d5d9b..19d7337c5d1 100644 --- a/src/bentoml/_internal/cloud/base.py +++ b/src/bentoml/_internal/cloud/base.py @@ -3,25 +3,25 @@ import typing as t from abc import ABC from abc import abstractmethod -from functools import wraps from contextlib import contextmanager +from functools import wraps -from rich.panel import Panel from rich.console import Group -from rich.progress import Progress +from rich.panel import Panel from rich.progress import BarColumn -from rich.progress import TextColumn -from rich.progress import SpinnerColumn from rich.progress import DownloadColumn +from rich.progress import Progress +from rich.progress import SpinnerColumn +from rich.progress import TextColumn from rich.progress import TimeElapsedColumn from rich.progress import TimeRemainingColumn from rich.progress import TransferSpeedColumn -from ..tag import Tag from ..bento import Bento from ..bento import BentoStore from ..models import Model from ..models import ModelStore +from ..tag import Tag FILE_CHUNK_SIZE = 100 * 1024 * 1024 # 100Mb diff --git a/src/bentoml/_internal/cloud/bentocloud.py b/src/bentoml/_internal/cloud/bentocloud.py index d1aff2c395e..6f4f79c38af 100644 --- a/src/bentoml/_internal/cloud/bentocloud.py +++ b/src/bentoml/_internal/cloud/bentocloud.py @@ -1,55 +1,55 @@ from __future__ import annotations import io -import typing as t import tarfile import tempfile -import warnings import threading +import typing as t +import warnings +from concurrent.futures import ThreadPoolExecutor from pathlib import Path from tempfile import NamedTemporaryFile -from concurrent.futures import ThreadPoolExecutor import fs import requests from rich.live import Live -from simple_di import inject from simple_di import Provide +from simple_di import inject -from ..tag import Tag +from ...exceptions import BentoMLException +from ...exceptions import NotFound from ..bento import Bento from ..bento import BentoStore -from ..utils import calc_dir_size -from .config import get_rest_api_client +from ..configuration.containers import BentoMLContainer from ..models import Model -from ..models import copy_model from ..models import ModelStore +from ..models import copy_model +from ..tag import Tag +from ..utils import calc_dir_size +from .base import FILE_CHUNK_SIZE +from .base import CallbackIOWrapper +from .base import CloudClient +from .config import get_rest_api_client +from .deployment import Deployment from .schemas import BentoApiSchema -from .schemas import LabelItemSchema +from .schemas import BentoManifestSchema +from .schemas import BentoRunnerResourceSchema from .schemas import BentoRunnerSchema from .schemas import BentoUploadStatus +from .schemas import CompleteMultipartUploadSchema +from .schemas import CompletePartSchema +from .schemas import CreateBentoRepositorySchema from .schemas import CreateBentoSchema +from .schemas import CreateModelRepositorySchema from .schemas import CreateModelSchema -from .schemas import ModelUploadStatus -from .schemas import UpdateBentoSchema -from .schemas import CompletePartSchema -from .schemas import BentoManifestSchema -from .schemas import ModelManifestSchema -from .schemas import TransmissionStrategy from .schemas import FinishUploadBentoSchema from .schemas import FinishUploadModelSchema -from .schemas import BentoRunnerResourceSchema -from .schemas import CreateBentoRepositorySchema -from .schemas import CreateModelRepositorySchema -from .schemas import CompleteMultipartUploadSchema +from .schemas import LabelItemSchema +from .schemas import ModelManifestSchema +from .schemas import ModelUploadStatus from .schemas import PreSignMultipartUploadUrlSchema -from .base import CloudClient -from .base import FILE_CHUNK_SIZE -from .base import CallbackIOWrapper -from .deployment import Deployment -from ...exceptions import NotFound -from ...exceptions import BentoMLException -from ..configuration.containers import BentoMLContainer +from .schemas import TransmissionStrategy +from .schemas import UpdateBentoSchema if t.TYPE_CHECKING: from concurrent.futures import Future diff --git a/src/bentoml/_internal/cloud/client.py b/src/bentoml/_internal/cloud/client.py index 8b7aa0a5949..91a9e8fdea4 100644 --- a/src/bentoml/_internal/cloud/client.py +++ b/src/bentoml/_internal/cloud/client.py @@ -6,33 +6,34 @@ import requests -from .schemas import UserSchema, schema_from_object +from ...exceptions import CloudRESTApiClientError +from ..configuration import BENTOML_VERSION +from .schemas import BentoRepositorySchema from .schemas import BentoSchema -from .schemas import ModelSchema -from .schemas import schema_to_json -from .schemas import DeploymentSchema -from .schemas import schema_from_json +from .schemas import BentoWithRepositoryListSchema +from .schemas import ClusterFullSchema +from .schemas import ClusterListSchema +from .schemas import CompleteMultipartUploadSchema +from .schemas import CreateBentoRepositorySchema from .schemas import CreateBentoSchema +from .schemas import CreateDeploymentSchema +from .schemas import CreateModelRepositorySchema from .schemas import CreateModelSchema -from .schemas import UpdateBentoSchema -from .schemas import OrganizationSchema from .schemas import DeploymentListSchema -from .schemas import BentoRepositorySchema -from .schemas import ModelRepositorySchema -from .schemas import CreateDeploymentSchema -from .schemas import UpdateDeploymentSchema +from .schemas import DeploymentSchema from .schemas import FinishUploadBentoSchema from .schemas import FinishUploadModelSchema -from .schemas import CreateBentoRepositorySchema -from .schemas import CreateModelRepositorySchema -from .schemas import BentoWithRepositoryListSchema -from .schemas import CompleteMultipartUploadSchema +from .schemas import ModelRepositorySchema +from .schemas import ModelSchema from .schemas import ModelWithRepositoryListSchema +from .schemas import OrganizationSchema from .schemas import PreSignMultipartUploadUrlSchema -from .schemas import ClusterListSchema -from .schemas import ClusterFullSchema -from ...exceptions import CloudRESTApiClientError -from ..configuration import BENTOML_VERSION +from .schemas import UpdateBentoSchema +from .schemas import UpdateDeploymentSchema +from .schemas import UserSchema +from .schemas import schema_from_json +from .schemas import schema_from_object +from .schemas import schema_to_json logger = logging.getLogger(__name__) diff --git a/src/bentoml/_internal/cloud/config.py b/src/bentoml/_internal/cloud/config.py index e05d0822650..768636dd4ea 100644 --- a/src/bentoml/_internal/cloud/config.py +++ b/src/bentoml/_internal/cloud/config.py @@ -1,17 +1,17 @@ from __future__ import annotations -import typing as t import logging +import typing as t import attr import yaml -from ..utils import bentoml_cattr -from simple_di import inject from simple_di import Provide +from simple_di import inject -from .client import RestApiClient from ...exceptions import CloudRESTApiClientError from ..configuration.containers import BentoMLContainer +from ..utils import bentoml_cattr +from .client import RestApiClient logger = logging.getLogger(__name__) diff --git a/src/bentoml/_internal/cloud/deployment.py b/src/bentoml/_internal/cloud/deployment.py index bf16f1d04b1..1850cbbc4c1 100644 --- a/src/bentoml/_internal/cloud/deployment.py +++ b/src/bentoml/_internal/cloud/deployment.py @@ -1,29 +1,29 @@ from __future__ import annotations import json -import typing as t import logging +import typing as t import attr +from deepmerge.merger import Merger +from ...exceptions import BentoMLException from ..tag import Tag from ..utils import bentoml_cattr +from ..utils import first_not_none from ..utils import resolve_user_filepath from .config import get_rest_api_client +from .schemas import CreateDeploymentSchema +from .schemas import DeploymentListSchema from .schemas import DeploymentMode from .schemas import DeploymentSchema -from .schemas import DeploymentListSchema -from .schemas import DeploymentTargetType -from .schemas import FullDeploymentSchema -from .schemas import CreateDeploymentSchema +from .schemas import DeploymentTargetCanaryRule from .schemas import DeploymentTargetConfig -from .schemas import UpdateDeploymentSchema from .schemas import DeploymentTargetHPAConf -from .schemas import DeploymentTargetCanaryRule from .schemas import DeploymentTargetRunnerConfig -from deepmerge.merger import Merger -from ..utils import first_not_none -from ...exceptions import BentoMLException +from .schemas import DeploymentTargetType +from .schemas import FullDeploymentSchema +from .schemas import UpdateDeploymentSchema logger = logging.getLogger(__name__) diff --git a/src/bentoml/_internal/cloud/schemas.py b/src/bentoml/_internal/cloud/schemas.py index 42f6469e8a6..a44384cd2b4 100644 --- a/src/bentoml/_internal/cloud/schemas.py +++ b/src/bentoml/_internal/cloud/schemas.py @@ -2,9 +2,10 @@ import json import typing as t +from datetime import datetime from enum import Enum from typing import TYPE_CHECKING -from datetime import datetime + import attr import cattr from dateutil.parser import parse diff --git a/src/bentoml/_internal/cloud/yatai.py b/src/bentoml/_internal/cloud/yatai.py index 67421f97265..6f6eb9ab711 100644 --- a/src/bentoml/_internal/cloud/yatai.py +++ b/src/bentoml/_internal/cloud/yatai.py @@ -1,54 +1,54 @@ from __future__ import annotations import io -import typing as t import tarfile import tempfile -import warnings import threading +import typing as t +import warnings +from concurrent.futures import ThreadPoolExecutor from pathlib import Path from tempfile import NamedTemporaryFile -from concurrent.futures import ThreadPoolExecutor import fs import requests from rich.live import Live -from simple_di import inject from simple_di import Provide +from simple_di import inject -from ..tag import Tag +from ...exceptions import BentoMLException +from ...exceptions import NotFound from ..bento import Bento from ..bento import BentoStore -from ..utils import calc_dir_size -from .config import get_rest_api_client +from ..configuration.containers import BentoMLContainer from ..models import Model -from ..models import copy_model from ..models import ModelStore +from ..models import copy_model +from ..tag import Tag +from ..utils import calc_dir_size +from .base import FILE_CHUNK_SIZE +from .base import CallbackIOWrapper +from .base import CloudClient +from .config import get_rest_api_client from .schemas import BentoApiSchema -from .schemas import LabelItemSchema +from .schemas import BentoManifestSchema +from .schemas import BentoRunnerResourceSchema from .schemas import BentoRunnerSchema from .schemas import BentoUploadStatus +from .schemas import CompleteMultipartUploadSchema +from .schemas import CompletePartSchema +from .schemas import CreateBentoRepositorySchema from .schemas import CreateBentoSchema +from .schemas import CreateModelRepositorySchema from .schemas import CreateModelSchema -from .schemas import ModelUploadStatus -from .schemas import UpdateBentoSchema -from .schemas import CompletePartSchema -from .schemas import BentoManifestSchema -from .schemas import ModelManifestSchema -from .schemas import TransmissionStrategy from .schemas import FinishUploadBentoSchema from .schemas import FinishUploadModelSchema -from .schemas import BentoRunnerResourceSchema -from .schemas import CreateBentoRepositorySchema -from .schemas import CreateModelRepositorySchema -from .schemas import CompleteMultipartUploadSchema +from .schemas import LabelItemSchema +from .schemas import ModelManifestSchema +from .schemas import ModelUploadStatus from .schemas import PreSignMultipartUploadUrlSchema -from .base import CloudClient -from .base import FILE_CHUNK_SIZE -from .base import CallbackIOWrapper -from ...exceptions import NotFound -from ...exceptions import BentoMLException -from ..configuration.containers import BentoMLContainer +from .schemas import TransmissionStrategy +from .schemas import UpdateBentoSchema if t.TYPE_CHECKING: from concurrent.futures import Future diff --git a/src/bentoml/_internal/configuration/__init__.py b/src/bentoml/_internal/configuration/__init__.py index 77cecd967ca..f67e56547cd 100644 --- a/src/bentoml/_internal/configuration/__init__.py +++ b/src/bentoml/_internal/configuration/__init__.py @@ -1,14 +1,14 @@ from __future__ import annotations +import logging import os import re import typing as t -import logging -from typing import TYPE_CHECKING from functools import lru_cache +from typing import TYPE_CHECKING -from ...exceptions import BentoMLException from ...exceptions import BentoMLConfigException +from ...exceptions import BentoMLException try: from ..._version import __version__ @@ -137,8 +137,8 @@ def get_quiet_mode() -> bool: def load_config(bentoml_config_file: str | None = None): """Load global configuration of BentoML""" - from .containers import BentoMLContainer from .containers import BentoMLConfiguration + from .containers import BentoMLContainer if not bentoml_config_file: bentoml_config_file = get_bentoml_config_file_from_env() diff --git a/src/bentoml/_internal/configuration/containers.py b/src/bentoml/_internal/configuration/containers.py index f7835935a49..068a783ca4e 100644 --- a/src/bentoml/_internal/configuration/containers.py +++ b/src/bentoml/_internal/configuration/containers.py @@ -1,34 +1,34 @@ from __future__ import annotations -import os +import logging import math -from pathlib import Path -import uuid +import os import typing as t -import logging +import uuid from copy import deepcopy -from typing import TYPE_CHECKING from dataclasses import dataclass +from pathlib import Path +from typing import TYPE_CHECKING -import yaml import schema as s +import yaml +from deepmerge.merger import Merger from simple_di import Provide from simple_di import providers -from deepmerge.merger import Merger -from . import expand_env_var +from ...exceptions import BentoMLConfigException +from ..context import component_context +from ..context import trace_context +from ..resource import CpuResource +from ..resource import system_resources 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 flatten_dict -from .helpers import load_config_file from .helpers import get_default_config from .helpers import import_configuration_spec -from ..context import trace_context -from ..context import component_context -from ..resource import CpuResource -from ..resource import system_resources -from ...exceptions import BentoMLConfigException -from ..utils.unflatten import unflatten +from .helpers import load_config_file if TYPE_CHECKING: from fs.base import FS @@ -36,8 +36,8 @@ from .. import external_typing as ext from ..bento import BentoStore from ..models import ModelStore - from ..utils.analytics import ServeInfo from ..server.metrics.prometheus import PrometheusClient + from ..utils.analytics import ServeInfo SerializationStrategy = t.Literal["EXPORT_BENTO", "LOCAL_BENTO", "REMOTE_BENTO"] @@ -358,13 +358,13 @@ def tracer_provider( jaeger: dict[str, t.Any] = Provide[tracing.jaeger], otlp: dict[str, t.Any] = Provide[tracing.otlp], ): - from opentelemetry.sdk.trace import TracerProvider - from opentelemetry.sdk.resources import Resource + from opentelemetry.sdk.resources import SERVICE_INSTANCE_ID from opentelemetry.sdk.resources import SERVICE_NAME - from opentelemetry.sdk.resources import SERVICE_VERSION from opentelemetry.sdk.resources import SERVICE_NAMESPACE - from opentelemetry.sdk.resources import SERVICE_INSTANCE_ID + 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 from ...exceptions import InvalidArgument diff --git a/src/bentoml/_internal/configuration/helpers.py b/src/bentoml/_internal/configuration/helpers.py index 24a1c6343fc..f57684c3aba 100644 --- a/src/bentoml/_internal/configuration/helpers.py +++ b/src/bentoml/_internal/configuration/helpers.py @@ -1,17 +1,17 @@ from __future__ import annotations +import logging import os import socket import typing as t -import logging -from typing import TYPE_CHECKING from functools import singledispatch +from typing import TYPE_CHECKING -import yaml import schema as s +import yaml -from ..utils import LazyLoader from ...exceptions import BentoMLConfigException +from ..utils import LazyLoader if TYPE_CHECKING: from types import ModuleType diff --git a/src/bentoml/_internal/configuration/v1/__init__.py b/src/bentoml/_internal/configuration/v1/__init__.py index 6e121e47099..55ecf41ce9a 100644 --- a/src/bentoml/_internal/configuration/v1/__init__.py +++ b/src/bentoml/_internal/configuration/v1/__init__.py @@ -5,17 +5,17 @@ import schema as s +from ...utils.metrics import DEFAULT_BUCKET +from ...utils.unflatten import unflatten from ..helpers import depth -from ..helpers import ensure_range -from ..helpers import rename_fields +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 ensure_iterable_type -from ..helpers import validate_tracing_type +from ..helpers import rename_fields from ..helpers import validate_otlp_protocol -from ..helpers import ensure_larger_than_zero -from ...utils.metrics import DEFAULT_BUCKET -from ...utils.unflatten import unflatten +from ..helpers import validate_tracing_type __all__ = ["SCHEMA", "migration"] diff --git a/src/bentoml/_internal/container/base.py b/src/bentoml/_internal/container/base.py index cec0ea0b171..033cce84a2f 100644 --- a/src/bentoml/_internal/container/base.py +++ b/src/bentoml/_internal/container/base.py @@ -1,22 +1,20 @@ from __future__ import annotations -import os -import typing as t import logging +import os import subprocess +import typing as t from abc import abstractmethod -from queue import Queue -from typing import TYPE_CHECKING +from functools import singledispatchmethod from itertools import chain +from queue import Queue from threading import Thread +from typing import TYPE_CHECKING import attr -from ..utils import resolve_user_filepath from ...exceptions import BentoMLException - -from functools import singledispatchmethod - +from ..utils import resolve_user_filepath if TYPE_CHECKING: from typing_extensions import Self diff --git a/src/bentoml/_internal/container/buildah.py b/src/bentoml/_internal/container/buildah.py index 3cf54336105..94443db96de 100644 --- a/src/bentoml/_internal/container/buildah.py +++ b/src/bentoml/_internal/container/buildah.py @@ -1,15 +1,15 @@ from __future__ import annotations +import logging import shutil import typing as t -import logging from typing import TYPE_CHECKING from .base import Arguments if TYPE_CHECKING: - from .base import ArgType from ..types import PathType + from .base import ArgType logger = logging.getLogger(__name__) diff --git a/src/bentoml/_internal/container/buildctl.py b/src/bentoml/_internal/container/buildctl.py index ab342d5a6ec..c4bf328258b 100644 --- a/src/bentoml/_internal/container/buildctl.py +++ b/src/bentoml/_internal/container/buildctl.py @@ -1,10 +1,10 @@ from __future__ import annotations +import logging import os import re import shutil import typing as t -import logging from typing import TYPE_CHECKING import psutil @@ -12,8 +12,8 @@ from .base import Arguments if TYPE_CHECKING: - from .base import ArgType from ..types import PathType + from .base import ArgType logger = logging.getLogger(__name__) diff --git a/src/bentoml/_internal/container/buildx.py b/src/bentoml/_internal/container/buildx.py index cc522d14878..a3acc1488db 100644 --- a/src/bentoml/_internal/container/buildx.py +++ b/src/bentoml/_internal/container/buildx.py @@ -1,18 +1,18 @@ from __future__ import annotations -import typing as t import logging import subprocess +import typing as t from typing import TYPE_CHECKING from .base import Arguments from .docker import ENV -from .docker import health as _docker_health from .docker import find_binary +from .docker import health as _docker_health if TYPE_CHECKING: - from .base import ArgType from ..types import PathType + from .base import ArgType logger = logging.getLogger(__name__) diff --git a/src/bentoml/_internal/container/docker.py b/src/bentoml/_internal/container/docker.py index 584b50fe0cb..856ef4d2203 100644 --- a/src/bentoml/_internal/container/docker.py +++ b/src/bentoml/_internal/container/docker.py @@ -1,11 +1,11 @@ from __future__ import annotations +import logging import os import re import shutil -import typing as t -import logging import subprocess +import typing as t from typing import TYPE_CHECKING import psutil @@ -14,8 +14,8 @@ from .base import Arguments if TYPE_CHECKING: - from .base import ArgType from ..types import PathType + from .base import ArgType logger = logging.getLogger(__name__) diff --git a/src/bentoml/_internal/container/frontend/dockerfile/__init__.py b/src/bentoml/_internal/container/frontend/dockerfile/__init__.py index 2a3bdba6b23..183018d3e3b 100644 --- a/src/bentoml/_internal/container/frontend/dockerfile/__init__.py +++ b/src/bentoml/_internal/container/frontend/dockerfile/__init__.py @@ -1,13 +1,13 @@ from __future__ import annotations -import typing as t import logging +import typing as t from typing import TYPE_CHECKING import attr -from .....exceptions import InvalidArgument from .....exceptions import BentoMLException +from .....exceptions import InvalidArgument if TYPE_CHECKING: P = t.ParamSpec("P") diff --git a/src/bentoml/_internal/container/generate.py b/src/bentoml/_internal/container/generate.py index fb5bce72b8b..716aeef074e 100644 --- a/src/bentoml/_internal/container/generate.py +++ b/src/bentoml/_internal/container/generate.py @@ -1,16 +1,16 @@ from __future__ import annotations +import logging import os import typing as t -import logging from typing import TYPE_CHECKING from jinja2 import Environment from jinja2.loaders import FileSystemLoader +from ..configuration.containers import BentoMLContainer from ..utils import resolve_user_filepath from .frontend.dockerfile import DistroSpec -from ..configuration.containers import BentoMLContainer logger = logging.getLogger(__name__) diff --git a/src/bentoml/_internal/container/nerdctl.py b/src/bentoml/_internal/container/nerdctl.py index 5918d723b1b..d50f44ec2af 100644 --- a/src/bentoml/_internal/container/nerdctl.py +++ b/src/bentoml/_internal/container/nerdctl.py @@ -1,9 +1,9 @@ from __future__ import annotations +import logging import os import shutil import typing as t -import logging from typing import TYPE_CHECKING import psutil @@ -11,8 +11,8 @@ from .base import Arguments if TYPE_CHECKING: - from .base import ArgType from ..types import PathType + from .base import ArgType logger = logging.getLogger(__name__) diff --git a/src/bentoml/_internal/container/podman.py b/src/bentoml/_internal/container/podman.py index 32030bfb620..bf6d076f5f7 100644 --- a/src/bentoml/_internal/container/podman.py +++ b/src/bentoml/_internal/container/podman.py @@ -1,9 +1,9 @@ from __future__ import annotations -import shutil -import typing as t import logging +import shutil import subprocess +import typing as t from typing import TYPE_CHECKING import psutil @@ -12,8 +12,8 @@ from .buildah import ENV if TYPE_CHECKING: - from .base import ArgType from ..types import PathType + from .base import ArgType logger = logging.getLogger(__name__) diff --git a/src/bentoml/_internal/env_manager/envs.py b/src/bentoml/_internal/env_manager/envs.py index a88246a7a6d..3be60be2a9d 100644 --- a/src/bentoml/_internal/env_manager/envs.py +++ b/src/bentoml/_internal/env_manager/envs.py @@ -1,9 +1,9 @@ from __future__ import annotations -import os -import typing as t import logging +import os import subprocess +import typing as t from abc import ABC from abc import abstractmethod from shutil import which diff --git a/src/bentoml/_internal/env_manager/manager.py b/src/bentoml/_internal/env_manager/manager.py index 70341e3715b..923b6c99a7b 100644 --- a/src/bentoml/_internal/env_manager/manager.py +++ b/src/bentoml/_internal/env_manager/manager.py @@ -1,16 +1,16 @@ from __future__ import annotations -import typing as t import logging +import typing as t import fs -from simple_di import inject from simple_di import Provide +from simple_di import inject -from .envs import Conda from ..bento.bento import Bento from ..bento.bento import BentoInfo from ..configuration.containers import BentoMLContainer +from .envs import Conda if t.TYPE_CHECKING: from fs.base import FS diff --git a/src/bentoml/_internal/exportable.py b/src/bentoml/_internal/exportable.py index 5d750c5e279..316579bf171 100644 --- a/src/bentoml/_internal/exportable.py +++ b/src/bentoml/_internal/exportable.py @@ -1,9 +1,9 @@ from __future__ import annotations +import logging import os import re import typing as t -import logging import urllib.parse from abc import ABC from abc import abstractmethod @@ -13,8 +13,8 @@ import fs.errors import fs.mirror import fs.opener -import fs.tempfs import fs.opener.errors +import fs.tempfs from fs import open_fs from fs.base import FS diff --git a/src/bentoml/_internal/frameworks/catboost.py b/src/bentoml/_internal/frameworks/catboost.py index 3d5dff0496f..e70004515a9 100644 --- a/src/bentoml/_internal/frameworks/catboost.py +++ b/src/bentoml/_internal/frameworks/catboost.py @@ -1,8 +1,8 @@ from __future__ import annotations +import logging import os import typing as t -import logging from types import ModuleType from typing import TYPE_CHECKING @@ -11,14 +11,14 @@ import bentoml from bentoml import Tag -from bentoml.models import ModelOptions -from bentoml.exceptions import NotFound -from bentoml.exceptions import InvalidArgument from bentoml.exceptions import BentoMLException +from bentoml.exceptions import InvalidArgument from bentoml.exceptions import MissingDependencyException +from bentoml.exceptions import NotFound +from bentoml.models import ModelOptions -from ..utils.pkg import get_pkg_version from ..models.model import ModelContext +from ..utils.pkg import get_pkg_version if TYPE_CHECKING: from bentoml.types import ModelSignature diff --git a/src/bentoml/_internal/frameworks/common/jax.py b/src/bentoml/_internal/frameworks/common/jax.py index 3b986b611ef..a59495d6535 100644 --- a/src/bentoml/_internal/frameworks/common/jax.py +++ b/src/bentoml/_internal/frameworks/common/jax.py @@ -1,18 +1,18 @@ from __future__ import annotations +import itertools import pickle import typing as t -import itertools from typing import TYPE_CHECKING from simple_di import inject -from ...types import LazyType -from ...utils import LazyLoader from ....exceptions import MissingDependencyException -from ...runner.container import Payload from ...runner.container import DataContainer from ...runner.container import DataContainerRegistry +from ...runner.container import Payload +from ...types import LazyType +from ...utils import LazyLoader try: import jaxlib as jaxlib diff --git a/src/bentoml/_internal/frameworks/common/pytorch.py b/src/bentoml/_internal/frameworks/common/pytorch.py index 6e0da1dd5d0..d684f1e68a6 100644 --- a/src/bentoml/_internal/frameworks/common/pytorch.py +++ b/src/bentoml/_internal/frameworks/common/pytorch.py @@ -1,25 +1,25 @@ from __future__ import annotations -import pickle -import typing as t -import logging import functools import itertools +import logging +import pickle +import typing as t from typing import TYPE_CHECKING -from simple_di import inject from simple_di import Provide +from simple_di import inject import bentoml -from ...types import LazyType from ....exceptions import MissingDependencyException +from ...configuration.containers import BentoMLContainer from ...models.model import Model -from ...runner.utils import Params -from ...runner.container import Payload from ...runner.container import DataContainer from ...runner.container import DataContainerRegistry -from ...configuration.containers import BentoMLContainer +from ...runner.container import Payload +from ...runner.utils import Params +from ...types import LazyType try: import torch diff --git a/src/bentoml/_internal/frameworks/detectron.py b/src/bentoml/_internal/frameworks/detectron.py index 3af874a7928..d2ea9c3a5cf 100644 --- a/src/bentoml/_internal/frameworks/detectron.py +++ b/src/bentoml/_internal/frameworks/detectron.py @@ -1,31 +1,31 @@ from __future__ import annotations -import typing as t import logging +import typing as t from types import ModuleType import bentoml -from ..tag import Tag -from ..types import LazyType -from ..utils import LazyLoader -from ..utils.pkg import get_pkg_version -from ...exceptions import NotFound from ...exceptions import MissingDependencyException +from ...exceptions import NotFound from ..models.model import Model from ..models.model import ModelContext from ..models.model import ModelSignature from ..models.model import PartialKwargsModelOptions as ModelOptions from ..runner.utils import Params -from .common.pytorch import torch -from .common.pytorch import inference_mode_ctx +from ..tag import Tag +from ..types import LazyType +from ..utils import LazyLoader +from ..utils.pkg import get_pkg_version from .common.pytorch import PyTorchTensorContainer # noqa # type: ignore +from .common.pytorch import inference_mode_ctx +from .common.pytorch import torch try: + import detectron2.checkpoint as Checkpoint import detectron2.config as Config import detectron2.engine as Engine import detectron2.modeling as Modeling - import detectron2.checkpoint as Checkpoint except ImportError: # pragma: no cover raise MissingDependencyException( "'detectron2' is required in order to use module 'bentoml.detectron'. Install detectron2 with 'pip install 'git+https://github.com/facebookresearch/detectron2.git''." diff --git a/src/bentoml/_internal/frameworks/diffusers.py b/src/bentoml/_internal/frameworks/diffusers.py index b1ace4b5588..f33892fba25 100644 --- a/src/bentoml/_internal/frameworks/diffusers.py +++ b/src/bentoml/_internal/frameworks/diffusers.py @@ -1,10 +1,10 @@ from __future__ import annotations -import re +import logging import os +import re import shutil import typing as t -import logging from pathlib import Path from typing import TYPE_CHECKING @@ -12,10 +12,10 @@ import bentoml from bentoml import Tag -from bentoml.models import ModelContext -from bentoml.exceptions import NotFound from bentoml.exceptions import BentoMLException from bentoml.exceptions import MissingDependencyException +from bentoml.exceptions import NotFound +from bentoml.models import ModelContext from ..models.model import PartialKwargsModelOptions @@ -27,11 +27,11 @@ try: - import torch import diffusers + import torch + from diffusers.utils.import_utils import is_accelerate_available from diffusers.utils.import_utils import is_torch_version from diffusers.utils.import_utils import is_xformers_available - from diffusers.utils.import_utils import is_accelerate_available except ImportError: # pragma: no cover raise MissingDependencyException( "'diffusers' and 'transformers' is required in order to use module 'bentoml.diffusers', install diffusers and its dependencies with 'pip install --upgrade diffusers transformers accelerate'. For more information, refer to https://github.com/huggingface/diffusers", diff --git a/src/bentoml/_internal/frameworks/easyocr.py b/src/bentoml/_internal/frameworks/easyocr.py index 0dfeaffd113..4a857516b7d 100644 --- a/src/bentoml/_internal/frameworks/easyocr.py +++ b/src/bentoml/_internal/frameworks/easyocr.py @@ -1,21 +1,21 @@ from __future__ import annotations -import typing as t import logging +import typing as t from types import ModuleType import cloudpickle import bentoml -from ..tag import Tag -from ..utils.pkg import get_pkg_version -from ...exceptions import NotFound from ...exceptions import MissingDependencyException +from ...exceptions import NotFound from ..models.model import Model from ..models.model import ModelContext from ..models.model import ModelOptions from ..models.model import ModelSignature +from ..tag import Tag +from ..utils.pkg import get_pkg_version from .common.pytorch import PyTorchTensorContainer # noqa # type: ignore try: diff --git a/src/bentoml/_internal/frameworks/fastai.py b/src/bentoml/_internal/frameworks/fastai.py index 7a69830138f..55a235cb3a6 100644 --- a/src/bentoml/_internal/frameworks/fastai.py +++ b/src/bentoml/_internal/frameworks/fastai.py @@ -1,19 +1,19 @@ from __future__ import annotations -import typing as t -import logging import contextlib +import logging +import typing as t from types import ModuleType from typing import TYPE_CHECKING import bentoml -from ..utils.pkg import get_pkg_version -from ...exceptions import NotFound -from ...exceptions import InvalidArgument from ...exceptions import BentoMLException +from ...exceptions import InvalidArgument from ...exceptions import MissingDependencyException +from ...exceptions import NotFound from ..models.model import ModelContext +from ..utils.pkg import get_pkg_version # register PyTorchTensorContainer as import side effect. from .common.pytorch import PyTorchTensorContainer @@ -26,10 +26,10 @@ if TYPE_CHECKING: - from .. import external_typing as ext - from ..tag import Tag from ...types import ModelSignature + from .. import external_typing as ext from ..models.model import ModelSignaturesType + from ..tag import Tag try: import torch diff --git a/src/bentoml/_internal/frameworks/flax.py b/src/bentoml/_internal/frameworks/flax.py index 6d941700cc9..cd2abb9acec 100644 --- a/src/bentoml/_internal/frameworks/flax.py +++ b/src/bentoml/_internal/frameworks/flax.py @@ -1,39 +1,39 @@ from __future__ import annotations -import typing as t -import logging import functools -from types import ModuleType +import logging +import typing as t from pickle import UnpicklingError +from types import ModuleType from typing import TYPE_CHECKING import msgpack.exceptions import bentoml -from ..types import LazyType -from ..utils import LazyLoader -from ..utils.pkg import get_pkg_version -from .common.jax import jax -from .common.jax import jnp -from .common.jax import JaxArrayContainer -from ...exceptions import NotFound from ...exceptions import BentoMLException from ...exceptions import MissingDependencyException +from ...exceptions import NotFound from ..models.model import ModelContext from ..models.model import PartialKwargsModelOptions as ModelOptions from ..runner.utils import Params +from ..types import LazyType +from ..utils import LazyLoader +from ..utils.pkg import get_pkg_version +from .common.jax import JaxArrayContainer +from .common.jax import jax +from .common.jax import jnp if TYPE_CHECKING: from flax import struct - from jax.lib import xla_bridge from flax.core import FrozenDict from jax._src.lib.xla_bridge import XlaBackend + from jax.lib import xla_bridge - from .. import external_typing as ext - from ..tag import Tag from ...types import ModelSignature + from .. import external_typing as ext from ..models.model import ModelSignaturesType + from ..tag import Tag else: xla_bridge = LazyLoader("xla_bridge", globals(), "jax.lib.xla_bridge") diff --git a/src/bentoml/_internal/frameworks/keras.py b/src/bentoml/_internal/frameworks/keras.py index 23f693300b9..b05e8e637b6 100644 --- a/src/bentoml/_internal/frameworks/keras.py +++ b/src/bentoml/_internal/frameworks/keras.py @@ -1,32 +1,32 @@ from __future__ import annotations -import typing as t -import logging import functools +import logging +import typing as t from types import ModuleType from typing import TYPE_CHECKING import attr import bentoml -from bentoml import Tag from bentoml import Runnable -from bentoml.models import ModelContext -from bentoml.exceptions import NotFound +from bentoml import Tag from bentoml.exceptions import MissingDependencyException +from bentoml.exceptions import NotFound +from bentoml.models import ModelContext -from ..types import LazyType from ..models.model import ModelSignature from ..models.model import PartialKwargsModelOptions from ..runner.utils import Params +from ..types import LazyType from .utils.tensorflow import get_tf_version logger = logging.getLogger(__name__) if TYPE_CHECKING: # pragma: no cover from .. import external_typing as ext - from ..models.model import ModelSignatureDict from ..external_typing import tensorflow as tf_ext + from ..models.model import ModelSignatureDict KerasArgType = t.Union[t.List[t.Union[int, float]], ext.NpNDArray, tf_ext.Tensor] diff --git a/src/bentoml/_internal/frameworks/lightgbm.py b/src/bentoml/_internal/frameworks/lightgbm.py index 90bd1ff8ef6..a47616aecba 100644 --- a/src/bentoml/_internal/frameworks/lightgbm.py +++ b/src/bentoml/_internal/frameworks/lightgbm.py @@ -1,7 +1,7 @@ from __future__ import annotations -import typing as t import logging +import typing as t from types import ModuleType from typing import TYPE_CHECKING @@ -9,12 +9,12 @@ import bentoml from bentoml import Tag -from bentoml.exceptions import NotFound from bentoml.exceptions import InvalidArgument from bentoml.exceptions import MissingDependencyException +from bentoml.exceptions import NotFound -from ..utils.pkg import get_pkg_version from ..models.model import ModelContext +from ..utils.pkg import get_pkg_version if TYPE_CHECKING: from bentoml.types import ModelSignature diff --git a/src/bentoml/_internal/frameworks/mlflow.py b/src/bentoml/_internal/frameworks/mlflow.py index 9b53fab7ef2..8374aef1a15 100644 --- a/src/bentoml/_internal/frameworks/mlflow.py +++ b/src/bentoml/_internal/frameworks/mlflow.py @@ -1,18 +1,18 @@ from __future__ import annotations +import logging import os import shutil -import typing as t -import logging import tempfile +import typing as t from typing import TYPE_CHECKING import bentoml from bentoml import Tag -from bentoml.models import ModelContext -from bentoml.exceptions import NotFound from bentoml.exceptions import BentoMLException from bentoml.exceptions import MissingDependencyException +from bentoml.exceptions import NotFound +from bentoml.models import ModelContext if TYPE_CHECKING: from types import ModuleType @@ -183,8 +183,8 @@ def import_model( context=context, ) as bento_model: from mlflow.models import Model as MLflowModel - from mlflow.pyfunc import FLAVOR_NAME as PYFUNC_FLAVOR_NAME from mlflow.models.model import MLMODEL_FILE_NAME + from mlflow.pyfunc import FLAVOR_NAME as PYFUNC_FLAVOR_NAME # Explicitly provide a destination dir to mlflow so that we don't # accidentially download into the root of the bento model temp dir diff --git a/src/bentoml/_internal/frameworks/onnx.py b/src/bentoml/_internal/frameworks/onnx.py index 903488cceb1..731f5c9624d 100644 --- a/src/bentoml/_internal/frameworks/onnx.py +++ b/src/bentoml/_internal/frameworks/onnx.py @@ -1,8 +1,8 @@ from __future__ import annotations +import logging import os import typing as t -import logging from types import ModuleType from typing import TYPE_CHECKING @@ -10,21 +10,21 @@ import bentoml from bentoml import Tag -from bentoml.models import ModelContext -from bentoml.models import ModelOptions -from bentoml.exceptions import NotFound from bentoml.exceptions import BentoMLException from bentoml.exceptions import MissingDependencyException +from bentoml.exceptions import NotFound +from bentoml.models import ModelContext +from bentoml.models import ModelOptions -from ..utils.pkg import get_pkg_version from ..utils.pkg import PackageNotFoundError +from ..utils.pkg import get_pkg_version if TYPE_CHECKING: from bentoml.types import ModelSignature from bentoml.types import ModelSignatureDict - from .utils.onnx import ONNXArgType from .utils.onnx import ONNXArgCastedType + from .utils.onnx import ONNXArgType ProvidersType = list[str | tuple[str, dict[str, t.Any]]] diff --git a/src/bentoml/_internal/frameworks/picklable.py b/src/bentoml/_internal/frameworks/picklable.py index 6bc4fbee287..c14e293ebcd 100644 --- a/src/bentoml/_internal/frameworks/picklable.py +++ b/src/bentoml/_internal/frameworks/picklable.py @@ -1,7 +1,7 @@ from __future__ import annotations -import typing as t import logging +import typing as t from types import ModuleType from typing import TYPE_CHECKING @@ -9,9 +9,9 @@ import bentoml from bentoml import Tag +from bentoml.exceptions import NotFound from bentoml.models import Model from bentoml.models import ModelContext -from bentoml.exceptions import NotFound from ..models import PKL_EXT from ..models import SAVE_NAMESPACE diff --git a/src/bentoml/_internal/frameworks/pytorch.py b/src/bentoml/_internal/frameworks/pytorch.py index ca5556db07b..1ef683cf8be 100644 --- a/src/bentoml/_internal/frameworks/pytorch.py +++ b/src/bentoml/_internal/frameworks/pytorch.py @@ -1,24 +1,24 @@ from __future__ import annotations -import typing as t import logging +import typing as t +from pathlib import Path from types import ModuleType from typing import TYPE_CHECKING -from pathlib import Path import cloudpickle import bentoml from bentoml import Tag -from ..types import LazyType -from ..models import Model -from ..utils.pkg import get_pkg_version from ...exceptions import NotFound +from ..models import Model from ..models.model import ModelContext from ..models.model import PartialKwargsModelOptions as ModelOptions -from .common.pytorch import torch +from ..types import LazyType +from ..utils.pkg import get_pkg_version from .common.pytorch import PyTorchTensorContainer +from .common.pytorch import torch __all__ = ["load_model", "save_model", "get_runnable", "get", "PyTorchTensorContainer"] @@ -191,9 +191,9 @@ def get_runnable(bento_model: Model): """ Private API: use :obj:`~bentoml.Model.to_runnable` instead. """ - from .common.pytorch import partial_class from .common.pytorch import PytorchModelRunnable from .common.pytorch import make_pytorch_runnable_method + from .common.pytorch import partial_class partial_kwargs: t.Dict[str, t.Any] = bento_model.info.options.partial_kwargs # type: ignore diff --git a/src/bentoml/_internal/frameworks/pytorch_lightning.py b/src/bentoml/_internal/frameworks/pytorch_lightning.py index b86f469fa28..e7c2a07518f 100644 --- a/src/bentoml/_internal/frameworks/pytorch_lightning.py +++ b/src/bentoml/_internal/frameworks/pytorch_lightning.py @@ -7,12 +7,12 @@ import bentoml from bentoml import Tag -from .torchscript import save_model as script_save_model -from .torchscript import MODEL_FILENAME -from ...exceptions import NotFound from ...exceptions import MissingDependencyException +from ...exceptions import NotFound from ..models.model import Model from .common.pytorch import torch +from .torchscript import MODEL_FILENAME +from .torchscript import save_model as script_save_model if TYPE_CHECKING: from ..models.model import ModelSignaturesType @@ -184,9 +184,9 @@ def get_runnable(bento_model: Model): """ Private API: use :obj:`~bentoml.Model.to_runnable` instead. """ - from .common.pytorch import partial_class from .common.pytorch import PytorchModelRunnable from .common.pytorch import make_pytorch_runnable_method + from .common.pytorch import partial_class for method_name, options in bento_model.info.signatures.items(): PytorchModelRunnable.add_method( diff --git a/src/bentoml/_internal/frameworks/sklearn.py b/src/bentoml/_internal/frameworks/sklearn.py index efe3419d9ac..f505d0b2cb3 100644 --- a/src/bentoml/_internal/frameworks/sklearn.py +++ b/src/bentoml/_internal/frameworks/sklearn.py @@ -1,16 +1,16 @@ from __future__ import annotations -import typing as t import logging +import typing as t from types import ModuleType from typing import TYPE_CHECKING import bentoml from bentoml import Tag +from bentoml.exceptions import MissingDependencyException +from bentoml.exceptions import NotFound from bentoml.models import Model from bentoml.models import ModelContext -from bentoml.exceptions import NotFound -from bentoml.exceptions import MissingDependencyException from ..types import LazyType from ..utils.pkg import get_pkg_version diff --git a/src/bentoml/_internal/frameworks/tensorflow_v2.py b/src/bentoml/_internal/frameworks/tensorflow_v2.py index cf0df71b25f..9a4fd4b0a41 100644 --- a/src/bentoml/_internal/frameworks/tensorflow_v2.py +++ b/src/bentoml/_internal/frameworks/tensorflow_v2.py @@ -1,36 +1,36 @@ from __future__ import annotations +import contextlib +import itertools +import logging import pickle import typing as t -import logging -import itertools -import contextlib from types import ModuleType from typing import TYPE_CHECKING import bentoml -from bentoml import Tag from bentoml import Runnable -from bentoml.models import ModelContext -from bentoml.exceptions import NotFound +from bentoml import Tag from bentoml.exceptions import MissingDependencyException +from bentoml.exceptions import NotFound +from bentoml.models import ModelContext -from ..types import LazyType from ..models.model import ModelSignature from ..models.model import PartialKwargsModelOptions as ModelOptions -from .utils.tensorflow import get_tf_version +from ..runner.container import DataContainer +from ..runner.container import DataContainerRegistry +from ..runner.container import Payload +from ..types import LazyType +from .utils.tensorflow import cast_py_args_to_tf_function_args from .utils.tensorflow import get_input_signatures_v2 from .utils.tensorflow import get_output_signatures_v2 from .utils.tensorflow import get_restorable_functions -from .utils.tensorflow import cast_py_args_to_tf_function_args -from ..runner.container import Payload -from ..runner.container import DataContainer -from ..runner.container import DataContainerRegistry +from .utils.tensorflow import get_tf_version if TYPE_CHECKING: from .. import external_typing as ext - from ..models.model import ModelSignatureDict from ..external_typing import tensorflow as tf_ext + from ..models.model import ModelSignatureDict TFArgType = t.Union[t.List[t.Union[int, float]], ext.NpNDArray, tf_ext.Tensor] TFModelOutputType = tf_ext.EagerTensor | tuple[tf_ext.EagerTensor] diff --git a/src/bentoml/_internal/frameworks/torchscript.py b/src/bentoml/_internal/frameworks/torchscript.py index 940e778893a..7d41d770e97 100644 --- a/src/bentoml/_internal/frameworks/torchscript.py +++ b/src/bentoml/_internal/frameworks/torchscript.py @@ -1,18 +1,18 @@ from __future__ import annotations -import typing as t import logging +import typing as t from types import ModuleType from typing import TYPE_CHECKING import bentoml from bentoml import Tag -from ..utils.pkg import get_pkg_version from ...exceptions import NotFound from ..models.model import Model from ..models.model import ModelContext from ..models.model import PartialKwargsModelOptions as ModelOptions +from ..utils.pkg import get_pkg_version from .common.pytorch import torch if TYPE_CHECKING: @@ -172,9 +172,9 @@ def get_runnable(bento_model: Model): """ Private API: use :obj:`~bentoml.Model.to_runnable` instead. """ - from .common.pytorch import partial_class from .common.pytorch import PytorchModelRunnable from .common.pytorch import make_pytorch_runnable_method + from .common.pytorch import partial_class partial_kwargs: t.Dict[str, t.Any] = bento_model.info.options.partial_kwargs # type: ignore model_runnable_class = partial_class( diff --git a/src/bentoml/_internal/frameworks/transformers.py b/src/bentoml/_internal/frameworks/transformers.py index 2f73d11f5a0..a12ebe487e5 100644 --- a/src/bentoml/_internal/frameworks/transformers.py +++ b/src/bentoml/_internal/frameworks/transformers.py @@ -1,9 +1,9 @@ from __future__ import annotations -import os -import typing as t import logging +import os import platform +import typing as t import warnings from types import ModuleType @@ -11,23 +11,23 @@ import bentoml -from ..tag import Tag -from ..types import LazyType -from ..utils import LazyLoader -from ..utils.pkg import get_pkg_version -from ..utils.pkg import pkg_version_info -from ...exceptions import NotFound from ...exceptions import BentoMLException from ...exceptions import MissingDependencyException +from ...exceptions import NotFound from ..models.model import Model from ..models.model import ModelContext from ..models.model import ModelOptions from ..models.model import ModelSignature +from ..tag import Tag +from ..types import LazyType +from ..utils import LazyLoader +from ..utils.pkg import get_pkg_version +from ..utils.pkg import pkg_version_info if t.TYPE_CHECKING: - import torch - import tensorflow as tf import cloudpickle + import tensorflow as tf + import torch from transformers.models.auto.auto_factory import ( _BaseAutoModelClass as BaseAutoModelClass, ) @@ -696,12 +696,12 @@ def save_model( # The below API are introduced since 4.18 if pkg_version_info("transformers")[:2] >= (4, 18): - from transformers.utils import is_tf_available from transformers.utils import is_flax_available + from transformers.utils import is_tf_available from transformers.utils import is_torch_available else: - from .utils.transformers import is_tf_available from .utils.transformers import is_flax_available + from .utils.transformers import is_tf_available from .utils.transformers import is_torch_available framework_versions = {"transformers": get_pkg_version("transformers")} diff --git a/src/bentoml/_internal/frameworks/utils/onnx.py b/src/bentoml/_internal/frameworks/utils/onnx.py index c9229f054e8..4aea39cacfd 100644 --- a/src/bentoml/_internal/frameworks/utils/onnx.py +++ b/src/bentoml/_internal/frameworks/utils/onnx.py @@ -1,11 +1,11 @@ from __future__ import annotations -import typing as t import logging +import typing as t from typing import TYPE_CHECKING -from ...types import LazyType from ....exceptions import BentoMLException +from ...types import LazyType from ...utils.lazy_loader import LazyLoader if TYPE_CHECKING: diff --git a/src/bentoml/_internal/frameworks/utils/tensorflow.py b/src/bentoml/_internal/frameworks/utils/tensorflow.py index 007c7452312..ff118235721 100644 --- a/src/bentoml/_internal/frameworks/utils/tensorflow.py +++ b/src/bentoml/_internal/frameworks/utils/tensorflow.py @@ -1,8 +1,9 @@ from __future__ import annotations -import typing as t -import logging +import importlib.metadata import importlib.util +import logging +import typing as t from typing import TYPE_CHECKING from bentoml.exceptions import BentoMLException @@ -10,8 +11,6 @@ from ...types import LazyType from ...utils.lazy_loader import LazyLoader -import importlib.metadata - if TYPE_CHECKING: import tensorflow as tf diff --git a/src/bentoml/_internal/frameworks/utils/transformers.py b/src/bentoml/_internal/frameworks/utils/transformers.py index 1394d955942..9336d71d2ee 100644 --- a/src/bentoml/_internal/frameworks/utils/transformers.py +++ b/src/bentoml/_internal/frameworks/utils/transformers.py @@ -1,12 +1,11 @@ from __future__ import annotations -import logging +import importlib.metadata import importlib.util +import logging from packaging import version -import importlib.metadata - logger = logging.getLogger(__name__) diff --git a/src/bentoml/_internal/frameworks/xgboost.py b/src/bentoml/_internal/frameworks/xgboost.py index b76fa2ca034..b5a13bfd122 100644 --- a/src/bentoml/_internal/frameworks/xgboost.py +++ b/src/bentoml/_internal/frameworks/xgboost.py @@ -1,8 +1,8 @@ from __future__ import annotations +import logging import os import typing as t -import logging from types import ModuleType from typing import TYPE_CHECKING @@ -11,14 +11,14 @@ import bentoml from bentoml import Tag -from bentoml.models import ModelOptions -from bentoml.exceptions import NotFound -from bentoml.exceptions import InvalidArgument from bentoml.exceptions import BentoMLException +from bentoml.exceptions import InvalidArgument from bentoml.exceptions import MissingDependencyException +from bentoml.exceptions import NotFound +from bentoml.models import ModelOptions -from ..utils.pkg import get_pkg_version from ..models.model import ModelContext +from ..utils.pkg import get_pkg_version if TYPE_CHECKING: from bentoml.types import ModelSignature diff --git a/src/bentoml/_internal/io_descriptors/__init__.py b/src/bentoml/_internal/io_descriptors/__init__.py index 4b01998dc2c..5be91695a54 100644 --- a/src/bentoml/_internal/io_descriptors/__init__.py +++ b/src/bentoml/_internal/io_descriptors/__init__.py @@ -1,16 +1,16 @@ from __future__ import annotations -from .base import from_spec -from .base import IODescriptor from .base import IO_DESCRIPTOR_REGISTRY +from .base import IODescriptor +from .base import from_spec from .file import File -from .json import JSON -from .text import Text from .image import Image +from .json import JSON +from .multipart import Multipart from .numpy import NumpyNdarray -from .pandas import PandasSeries from .pandas import PandasDataFrame -from .multipart import Multipart +from .pandas import PandasSeries +from .text import Text __all__ = [ "IO_DESCRIPTOR_REGISTRY", diff --git a/src/bentoml/_internal/io_descriptors/base.py b/src/bentoml/_internal/io_descriptors/base.py index e4bdfb9377d..7189a6fe681 100644 --- a/src/bentoml/_internal/io_descriptors/base.py +++ b/src/bentoml/_internal/io_descriptors/base.py @@ -17,10 +17,10 @@ from bentoml.grpc.types import ProtoField - from ..types import LazyType from ..context import ServiceContext as Context - from ..service.openapi.specification import Schema from ..service.openapi.specification import Reference + from ..service.openapi.specification import Schema + from ..types import LazyType InputType = ( UnionType diff --git a/src/bentoml/_internal/io_descriptors/file.py b/src/bentoml/_internal/io_descriptors/file.py index d78e77e756f..d503762d571 100644 --- a/src/bentoml/_internal/io_descriptors/file.py +++ b/src/bentoml/_internal/io_descriptors/file.py @@ -1,28 +1,28 @@ from __future__ import annotations import io +import logging import os import typing as t -import logging from functools import lru_cache -from starlette.requests import Request from multipart.multipart import parse_options_header -from starlette.responses import Response from starlette.datastructures import UploadFile +from starlette.requests import Request +from starlette.responses import Response -from .base import IODescriptor -from ..types import FileLike -from ..utils import resolve_user_filepath -from ..utils.http import set_cookies from ...exceptions import BadInput -from ...exceptions import InvalidArgument from ...exceptions import BentoMLException +from ...exceptions import InvalidArgument from ...exceptions import MissingDependencyException from ...grpc.utils import import_generated_stubs from ..service.openapi import SUCCESS_DESCRIPTION -from ..service.openapi.specification import Schema from ..service.openapi.specification import MediaType +from ..service.openapi.specification import Schema +from ..types import FileLike +from ..utils import resolve_user_filepath +from ..utils.http import set_cookies +from .base import IODescriptor logger = logging.getLogger(__name__) @@ -30,8 +30,8 @@ from bentoml.grpc.v1 import service_pb2 as pb from bentoml.grpc.v1alpha1 import service_pb2 as pb_v1alpha1 - from .base import OpenAPIResponse from ..context import ServiceContext as Context + from .base import OpenAPIResponse FileKind: t.TypeAlias = t.Literal["binaryio", "textio"] else: diff --git a/src/bentoml/_internal/io_descriptors/image.py b/src/bentoml/_internal/io_descriptors/image.py index 20126500a2d..482552d1464 100644 --- a/src/bentoml/_internal/io_descriptors/image.py +++ b/src/bentoml/_internal/io_descriptors/image.py @@ -1,28 +1,28 @@ from __future__ import annotations +import functools import io import typing as t -import functools from urllib.parse import quote -from starlette.requests import Request from multipart.multipart import parse_options_header -from starlette.responses import Response from starlette.datastructures import UploadFile +from starlette.requests import Request +from starlette.responses import Response -from .base import IODescriptor -from ..types import LazyType -from ..utils import LazyLoader -from ..utils import resolve_user_filepath -from ..utils.http import set_cookies from ...exceptions import BadInput -from ...exceptions import InvalidArgument from ...exceptions import InternalServerError +from ...exceptions import InvalidArgument from ...exceptions import MissingDependencyException from ...grpc.utils import import_generated_stubs from ..service.openapi import SUCCESS_DESCRIPTION -from ..service.openapi.specification import Schema from ..service.openapi.specification import MediaType +from ..service.openapi.specification import Schema +from ..types import LazyType +from ..utils import LazyLoader +from ..utils import resolve_user_filepath +from ..utils.http import set_cookies +from .base import IODescriptor PIL_EXC_MSG = "'Pillow' is required to use the Image IO descriptor. Install with 'pip install bentoml[io-image]'." @@ -32,11 +32,11 @@ import PIL import PIL.Image - from .. import external_typing as ext - from .base import OpenAPIResponse - from ..context import ServiceContext as Context from ...grpc.v1 import service_pb2 as pb from ...grpc.v1alpha1 import service_pb2 as pb_v1alpha1 + from .. import external_typing as ext + from ..context import ServiceContext as Context + from .base import OpenAPIResponse _Mode = t.Literal[ "1", "CMYK", "F", "HSV", "I", "L", "LAB", "P", "RGB", "RGBA", "RGBX", "YCbCr" diff --git a/src/bentoml/_internal/io_descriptors/json.py b/src/bentoml/_internal/io_descriptors/json.py index f2884fa8946..1c20a43dc9e 100644 --- a/src/bentoml/_internal/io_descriptors/json.py +++ b/src/bentoml/_internal/io_descriptors/json.py @@ -1,26 +1,26 @@ from __future__ import annotations +import dataclasses import json -import typing as t import logging -import dataclasses +import typing as t import attr from starlette.requests import Request from starlette.responses import Response -from .base import IODescriptor -from ..types import LazyType -from ..utils import LazyLoader -from ..utils import bentoml_cattr -from ..utils.pkg import pkg_version_info -from ..utils.http import set_cookies from ...exceptions import BadInput from ...exceptions import InvalidArgument from ..service.openapi import REF_PREFIX from ..service.openapi import SUCCESS_DESCRIPTION -from ..service.openapi.specification import Schema from ..service.openapi.specification import MediaType +from ..service.openapi.specification import Schema +from ..types import LazyType +from ..utils import LazyLoader +from ..utils import bentoml_cattr +from ..utils.http import set_cookies +from ..utils.pkg import pkg_version_info +from .base import IODescriptor EXC_MSG = "'pydantic' must be installed to use 'pydantic_model'. Install with 'pip install bentoml[io-json]'." @@ -37,8 +37,8 @@ from google.protobuf import struct_pb2 from typing_extensions import Self - from .base import OpenAPIResponse from ..context import ServiceContext as Context + from .base import OpenAPIResponse else: pydantic = LazyLoader("pydantic", globals(), "pydantic", exc_msg=EXC_MSG) diff --git a/src/bentoml/_internal/io_descriptors/multipart.py b/src/bentoml/_internal/io_descriptors/multipart.py index 05aa09eff21..a403529f63e 100644 --- a/src/bentoml/_internal/io_descriptors/multipart.py +++ b/src/bentoml/_internal/io_descriptors/multipart.py @@ -1,22 +1,22 @@ from __future__ import annotations -import typing as t import asyncio +import typing as t -from starlette.requests import Request from multipart.multipart import parse_options_header +from starlette.requests import Request from starlette.responses import Response -from . import from_spec as io_descriptor_from_spec -from .base import IODescriptor -from ...exceptions import InvalidArgument from ...exceptions import BentoMLException +from ...exceptions import InvalidArgument from ...grpc.utils import import_generated_stubs from ..service.openapi import SUCCESS_DESCRIPTION -from ..utils.formparser import populate_multipart_requests -from ..utils.formparser import concat_to_multipart_response -from ..service.openapi.specification import Schema from ..service.openapi.specification import MediaType +from ..service.openapi.specification import Schema +from ..utils.formparser import concat_to_multipart_response +from ..utils.formparser import populate_multipart_requests +from . import from_spec as io_descriptor_from_spec +from .base import IODescriptor if t.TYPE_CHECKING: from types import UnionType @@ -26,9 +26,9 @@ from bentoml.grpc.v1 import service_pb2 as pb from bentoml.grpc.v1alpha1 import service_pb2 as pb_v1alpha1 - from .base import OpenAPIResponse - from ..types import LazyType from ..context import ServiceContext as Context + from ..types import LazyType + from .base import OpenAPIResponse else: pb, _ = import_generated_stubs("v1") pb_v1alpha1, _ = import_generated_stubs("v1alpha1") diff --git a/src/bentoml/_internal/io_descriptors/numpy.py b/src/bentoml/_internal/io_descriptors/numpy.py index cdd37ad213b..02b53b51424 100644 --- a/src/bentoml/_internal/io_descriptors/numpy.py +++ b/src/bentoml/_internal/io_descriptors/numpy.py @@ -1,25 +1,25 @@ from __future__ import annotations import json -import typing as t import logging +import typing as t from functools import lru_cache from starlette.requests import Request from starlette.responses import Response -from .base import IODescriptor -from ..types import LazyType -from ..utils import LazyLoader -from ..utils.http import set_cookies from ...exceptions import BadInput from ...exceptions import InvalidArgument from ...exceptions import UnprocessableEntity -from ...grpc.utils import import_generated_stubs from ...grpc.utils import LATEST_PROTOCOL_VERSION +from ...grpc.utils import import_generated_stubs from ..service.openapi import SUCCESS_DESCRIPTION -from ..service.openapi.specification import Schema from ..service.openapi.specification import MediaType +from ..service.openapi.specification import Schema +from ..types import LazyType +from ..utils import LazyLoader +from ..utils.http import set_cookies +from .base import IODescriptor if t.TYPE_CHECKING: import numpy as np @@ -31,8 +31,8 @@ from bentoml.grpc.v1alpha1 import service_pb2 as pb_v1alpha1 from .. import external_typing as ext - from .base import OpenAPIResponse from ..context import ServiceContext as Context + from .base import OpenAPIResponse else: pb, _ = import_generated_stubs("v1") pb_v1alpha1, _ = import_generated_stubs("v1alpha1") @@ -646,9 +646,9 @@ def to_arrow(self, arr: ext.NpNDArray) -> pyarrow.RecordBatch: return pyarrow.RecordBatch.from_arrays([pyarrow.array(arr)], names=["output"]) def spark_schema(self) -> pyspark.sql.types.StructType: - from pyspark.sql.types import StructType - from pyspark.sql.types import StructField from pyspark.pandas.typedef import as_spark_type + from pyspark.sql.types import StructField + from pyspark.sql.types import StructType if self._dtype is None: raise InvalidArgument( diff --git a/src/bentoml/_internal/io_descriptors/pandas.py b/src/bentoml/_internal/io_descriptors/pandas.py index 4f08a740447..b6efe7a70e1 100644 --- a/src/bentoml/_internal/io_descriptors/pandas.py +++ b/src/bentoml/_internal/io_descriptors/pandas.py @@ -1,29 +1,29 @@ from __future__ import annotations +import functools import io +import logging import os import typing as t -import logging -import functools -from enum import Enum from concurrent.futures import ThreadPoolExecutor +from enum import Enum from starlette.requests import Request from starlette.responses import Response -from .base import IODescriptor -from ..types import LazyType -from ..utils.pkg import find_spec -from ..utils.http import set_cookies from ...exceptions import BadInput from ...exceptions import InvalidArgument -from ...exceptions import UnprocessableEntity from ...exceptions import MissingDependencyException +from ...exceptions import UnprocessableEntity from ...grpc.utils import import_generated_stubs from ..service.openapi import SUCCESS_DESCRIPTION -from ..utils.lazy_loader import LazyLoader -from ..service.openapi.specification import Schema from ..service.openapi.specification import MediaType +from ..service.openapi.specification import Schema +from ..types import LazyType +from ..utils.http import set_cookies +from ..utils.lazy_loader import LazyLoader +from ..utils.pkg import find_spec +from .base import IODescriptor EXC_MSG = "pandas' is required to use PandasDataFrame or PandasSeries. Install with 'pip install bentoml[io-pandas]'" @@ -38,8 +38,8 @@ from bentoml.grpc.v1alpha1 import service_pb2 as pb_v1alpha1 from .. import external_typing as ext - from .base import OpenAPIResponse from ..context import ServiceContext as Context + from .base import OpenAPIResponse else: pb, _ = import_generated_stubs("v1") @@ -751,9 +751,9 @@ def to_arrow(self, df: pd.Series[t.Any]) -> pyarrow.RecordBatch: return pyarrow.RecordBatch.from_pandas(df) def spark_schema(self) -> pyspark.sql.types.StructType: - from pyspark.sql.types import StructType - from pyspark.sql.types import StructField from pyspark.pandas.typedef import as_spark_type + from pyspark.sql.types import StructField + from pyspark.sql.types import StructType if self._dtype is None or self._dtype: raise InvalidArgument( @@ -1211,9 +1211,9 @@ def to_arrow(self, series: pd.Series[t.Any]) -> pyarrow.RecordBatch: return pyarrow.RecordBatch.from_pandas(df) def spark_schema(self) -> pyspark.sql.types.StructType: - from pyspark.sql.types import StructType - from pyspark.sql.types import StructField from pyspark.pandas.typedef import as_spark_type + from pyspark.sql.types import StructField + from pyspark.sql.types import StructType if self._dtype is None or self._dtype is True: raise InvalidArgument( diff --git a/src/bentoml/_internal/io_descriptors/text.py b/src/bentoml/_internal/io_descriptors/text.py index 8a4bc6d2f97..5bfa1ae3ced 100644 --- a/src/bentoml/_internal/io_descriptors/text.py +++ b/src/bentoml/_internal/io_descriptors/text.py @@ -5,20 +5,20 @@ from starlette.requests import Request from starlette.responses import Response -from .base import IODescriptor -from ..utils.http import set_cookies from ...exceptions import BentoMLException from ..service.openapi import SUCCESS_DESCRIPTION -from ..utils.lazy_loader import LazyLoader -from ..service.openapi.specification import Schema from ..service.openapi.specification import MediaType +from ..service.openapi.specification import Schema +from ..utils.http import set_cookies +from ..utils.lazy_loader import LazyLoader +from .base import IODescriptor if t.TYPE_CHECKING: from google.protobuf import wrappers_pb2 from typing_extensions import Self - from .base import OpenAPIResponse from ..context import ServiceContext as Context + from .base import OpenAPIResponse else: wrappers_pb2 = LazyLoader("wrappers_pb2", globals(), "google.protobuf.wrappers_pb2") diff --git a/src/bentoml/_internal/log.py b/src/bentoml/_internal/log.py index 042cd0c3858..e701408d4f5 100644 --- a/src/bentoml/_internal/log.py +++ b/src/bentoml/_internal/log.py @@ -1,14 +1,14 @@ from __future__ import annotations -import typing as t import logging import logging.config +import typing as t from functools import lru_cache -from .context import trace_context -from .context import component_context from .configuration import get_debug_mode from .configuration import get_quiet_mode +from .context import component_context +from .context import trace_context default_factory = logging.getLogRecordFactory() diff --git a/src/bentoml/_internal/marshal/dispatcher.py b/src/bentoml/_internal/marshal/dispatcher.py index b9ba6167d9a..22d929cea51 100644 --- a/src/bentoml/_internal/marshal/dispatcher.py +++ b/src/bentoml/_internal/marshal/dispatcher.py @@ -1,25 +1,25 @@ from __future__ import annotations -import time -import typing as t import asyncio -import logging +import collections import functools +import logging +import time import traceback -import collections +import typing as t +from functools import cached_property import attr import numpy as np -from functools import cached_property from ..utils.alg import TokenBucket logger = logging.getLogger(__name__) if t.TYPE_CHECKING: - from ..runner.utils import Params from ..runner.container import Payload + from ..runner.utils import Params class NonBlockSema: diff --git a/src/bentoml/_internal/models/__init__.py b/src/bentoml/_internal/models/__init__.py index 4a18a96ffe9..1408d6d499d 100644 --- a/src/bentoml/_internal/models/__init__.py +++ b/src/bentoml/_internal/models/__init__.py @@ -1,8 +1,8 @@ from .model import Model -from .model import copy_model -from .model import ModelStore from .model import ModelContext from .model import ModelOptions +from .model import ModelStore +from .model import copy_model # Deprecated. Use framework module local constants and name the saved files with API # Version in mind. E.g.: diff --git a/src/bentoml/_internal/models/model.py b/src/bentoml/_internal/models/model.py index 507a8dc1e1d..171ee2bc652 100644 --- a/src/bentoml/_internal/models/model.py +++ b/src/bentoml/_internal/models/model.py @@ -1,49 +1,49 @@ from __future__ import annotations +import importlib import io +import logging import os import typing as t -import logging -import importlib +from datetime import datetime +from datetime import timezone from sys import version_info as pyver from types import ModuleType -from typing import overload from typing import TYPE_CHECKING -from datetime import datetime -from datetime import timezone +from typing import overload -import fs import attr -import yaml +import cloudpickle # type: ignore (no cloudpickle types) +import fs import fs.errors import fs.mirror -import cloudpickle # type: ignore (no cloudpickle types) -from fs.base import FS -from cattr.gen import override +import yaml from cattr.gen import make_dict_structure_fn from cattr.gen import make_dict_unstructure_fn -from simple_di import inject +from cattr.gen import override +from fs.base import FS from simple_di import Provide +from simple_di import inject -from ..tag import Tag +from ...exceptions import BentoMLException +from ...exceptions import NotFound +from ..configuration import BENTOML_VERSION +from ..configuration.containers import BentoMLContainer from ..store import Store from ..store import StoreItem +from ..tag import Tag from ..types import MetadataDict +from ..types import ModelSignatureDict from ..utils import bentoml_cattr from ..utils import label_validator from ..utils import metadata_validator from ..utils import normalize_labels_value -from ...exceptions import NotFound -from ...exceptions import BentoMLException -from ..configuration import BENTOML_VERSION -from ..configuration.containers import BentoMLContainer -from ..types import ModelSignatureDict if t.TYPE_CHECKING: - from ..types import PathType - from ..runner import Runner from ..runner import Runnable + from ..runner import Runner from ..runner.strategy import Strategy + from ..types import PathType T = t.TypeVar("T") diff --git a/src/bentoml/_internal/monitoring/__init__.py b/src/bentoml/_internal/monitoring/__init__.py index f0e2ecd2d67..abd22128d4a 100644 --- a/src/bentoml/_internal/monitoring/__init__.py +++ b/src/bentoml/_internal/monitoring/__init__.py @@ -1,14 +1,14 @@ from __future__ import annotations -import typing as t -import logging import importlib +import logging +import typing as t +from ...exceptions import MissingDependencyException from .api import monitor from .base import MonitorBase from .base import NoOpMonitor from .default import DefaultMonitor -from ...exceptions import MissingDependencyException logger = logging.getLogger(__name__) diff --git a/src/bentoml/_internal/monitoring/api.py b/src/bentoml/_internal/monitoring/api.py index 68e0425846c..3dc083ff3f1 100644 --- a/src/bentoml/_internal/monitoring/api.py +++ b/src/bentoml/_internal/monitoring/api.py @@ -1,19 +1,19 @@ from __future__ import annotations -import typing as t -import logging import contextlib +import logging import logging.config +import typing as t -from simple_di import inject from simple_di import Provide +from simple_di import inject +from ..configuration.containers import BentoMLContainer +from ..types import LazyType from .base import MT from .base import MonitorBase from .base import NoOpMonitor -from ..types import LazyType from .default import DefaultMonitor -from ..configuration.containers import BentoMLContainer logger = logging.getLogger(__name__) diff --git a/src/bentoml/_internal/monitoring/base.py b/src/bentoml/_internal/monitoring/base.py index eb3b2d7dcfa..fecd5b8693f 100644 --- a/src/bentoml/_internal/monitoring/base.py +++ b/src/bentoml/_internal/monitoring/base.py @@ -1,9 +1,9 @@ from __future__ import annotations -import typing as t -import logging import collections import contextvars +import logging +import typing as t MON_COLUMN_VAR: contextvars.ContextVar[ "dict[str, dict[str, str]] | None" diff --git a/src/bentoml/_internal/monitoring/default.py b/src/bentoml/_internal/monitoring/default.py index a7cb3f9c363..8979046a17d 100644 --- a/src/bentoml/_internal/monitoring/default.py +++ b/src/bentoml/_internal/monitoring/default.py @@ -1,17 +1,17 @@ from __future__ import annotations -import typing as t -import logging -import datetime import collections +import datetime +import logging import logging.config +import typing as t from pathlib import Path import yaml -from .base import MonitorBase -from ..context import trace_context from ..context import component_context +from ..context import trace_context +from .base import MonitorBase if t.TYPE_CHECKING: from ..types import JSONSerializable diff --git a/src/bentoml/_internal/monitoring/otlp.py b/src/bentoml/_internal/monitoring/otlp.py index 643b917a79c..7800ee2c390 100644 --- a/src/bentoml/_internal/monitoring/otlp.py +++ b/src/bentoml/_internal/monitoring/otlp.py @@ -1,30 +1,30 @@ from __future__ import annotations +import collections +import datetime +import logging +import logging.config import os import random import typing as t -import logging -import datetime -import collections -import logging.config # NOTE: AFAIK, they move this function from opentelemetry.sdk.logs to opentelemetry._logs from opentelemetry._logs import set_logger_provider from opentelemetry.sdk._logs import LoggerProvider from opentelemetry.sdk._logs import LoggingHandler -from opentelemetry.sdk.resources import Resource from opentelemetry.sdk._logs.export import BatchLogRecordProcessor -from opentelemetry.sdk.environment_variables import OTEL_EXPORTER_OTLP_HEADERS -from opentelemetry.sdk.environment_variables import OTEL_EXPORTER_OTLP_TIMEOUT -from opentelemetry.sdk.environment_variables import OTEL_EXPORTER_OTLP_ENDPOINT -from opentelemetry.sdk.environment_variables import OTEL_EXPORTER_OTLP_INSECURE from opentelemetry.sdk.environment_variables import OTEL_EXPORTER_OTLP_CERTIFICATE from opentelemetry.sdk.environment_variables import OTEL_EXPORTER_OTLP_COMPRESSION +from opentelemetry.sdk.environment_variables import OTEL_EXPORTER_OTLP_ENDPOINT +from opentelemetry.sdk.environment_variables import OTEL_EXPORTER_OTLP_HEADERS +from opentelemetry.sdk.environment_variables import OTEL_EXPORTER_OTLP_INSECURE +from opentelemetry.sdk.environment_variables import OTEL_EXPORTER_OTLP_TIMEOUT +from opentelemetry.sdk.resources import Resource -from .base import MonitorBase -from ..context import trace_context -from ..context import component_context from ...exceptions import MissingDependencyException +from ..context import component_context +from ..context import trace_context +from .base import MonitorBase try: from opentelemetry.exporter.otlp.proto.http._log_exporter import OTLPLogExporter @@ -135,8 +135,8 @@ def __init__( self._will_export_schema = False def _init_logger(self) -> None: - from opentelemetry.sdk.resources import SERVICE_NAME from opentelemetry.sdk.resources import SERVICE_INSTANCE_ID + from opentelemetry.sdk.resources import SERVICE_NAME from opentelemetry.sdk.resources import OTELResourceDetector # User can optionally configure the resource with the following environment variables. Only diff --git a/src/bentoml/_internal/ray/__init__.py b/src/bentoml/_internal/ray/__init__.py index 9a5728cf272..032f7ce3fb8 100644 --- a/src/bentoml/_internal/ray/__init__.py +++ b/src/bentoml/_internal/ray/__init__.py @@ -10,9 +10,9 @@ from bentoml import Tag from ...exceptions import MissingDependencyException +from ..runner.container import AutoContainer from ..runner.utils import Params from .runner_handle import RayRunnerHandle -from ..runner.container import AutoContainer try: from ray import serve diff --git a/src/bentoml/_internal/ray/runner_handle.py b/src/bentoml/_internal/ray/runner_handle.py index 85f3904427e..93dea10bd09 100644 --- a/src/bentoml/_internal/ray/runner_handle.py +++ b/src/bentoml/_internal/ray/runner_handle.py @@ -1,10 +1,10 @@ from __future__ import annotations -import typing as t import functools +import typing as t -from ..runner import Runner from ...exceptions import MissingDependencyException +from ..runner import Runner from ..runner.runner import RunnerMethod from ..runner.runner_handle import RunnerHandle diff --git a/src/bentoml/_internal/resource.py b/src/bentoml/_internal/resource.py index b1e467fceda..66745bffa95 100644 --- a/src/bentoml/_internal/resource.py +++ b/src/bentoml/_internal/resource.py @@ -1,11 +1,11 @@ from __future__ import annotations +import functools +import logging +import math import os import re -import math import typing as t -import logging -import functools from abc import ABC from abc import abstractmethod diff --git a/src/bentoml/_internal/runner/__init__.py b/src/bentoml/_internal/runner/__init__.py index c0bd5a7c6d3..77e0e2cafa0 100644 --- a/src/bentoml/_internal/runner/__init__.py +++ b/src/bentoml/_internal/runner/__init__.py @@ -1,4 +1,4 @@ -from .runner import Runner from .runnable import Runnable +from .runner import Runner __all__ = ["Runner", "Runnable"] diff --git a/src/bentoml/_internal/runner/container.py b/src/bentoml/_internal/runner/container.py index efe3c98724e..e330dc06ab1 100644 --- a/src/bentoml/_internal/runner/container.py +++ b/src/bentoml/_internal/runner/container.py @@ -2,15 +2,15 @@ import abc import base64 +import itertools import pickle import typing as t -import itertools from ..types import LazyType from ..utils import LazyLoader +from ..utils.pickle import fixed_torch_loads from ..utils.pickle import pep574_dumps from ..utils.pickle import pep574_loads -from ..utils.pickle import fixed_torch_loads SingleType = t.TypeVar("SingleType") BatchType = t.TypeVar("BatchType") diff --git a/src/bentoml/_internal/runner/runnable.py b/src/bentoml/_internal/runner/runnable.py index eef6f682e01..e92410091a3 100644 --- a/src/bentoml/_internal/runner/runnable.py +++ b/src/bentoml/_internal/runner/runnable.py @@ -1,14 +1,14 @@ from __future__ import annotations -import typing as t import logging -from typing import overload +import typing as t from typing import TYPE_CHECKING +from typing import overload import attr -from ..types import LazyType from ...exceptions import BentoMLException +from ..types import LazyType if TYPE_CHECKING: from ..types import AnyType diff --git a/src/bentoml/_internal/runner/runner.py b/src/bentoml/_internal/runner/runner.py index aaaa9e2dd37..0d8517e3929 100644 --- a/src/bentoml/_internal/runner/runner.py +++ b/src/bentoml/_internal/runner/runner.py @@ -1,24 +1,24 @@ from __future__ import annotations -import typing as t import logging +import typing as t from abc import ABC from abc import abstractmethod import attr -from simple_di import inject from simple_di import Provide +from simple_di import inject +from ...exceptions import StateException +from ..configuration.containers import BentoMLContainer +from ..models.model import Model from ..tag import validate_tag_str from ..utils import first_not_none from .runnable import Runnable -from .strategy import Strategy -from .strategy import DefaultStrategy -from ...exceptions import StateException -from ..models.model import Model -from .runner_handle import RunnerHandle from .runner_handle import DummyRunnerHandle -from ..configuration.containers import BentoMLContainer +from .runner_handle import RunnerHandle +from .strategy import DefaultStrategy +from .strategy import Strategy if t.TYPE_CHECKING: from ...triton import Runner as TritonRunner diff --git a/src/bentoml/_internal/runner/runner_handle/__init__.py b/src/bentoml/_internal/runner/runner_handle/__init__.py index c234ba3223f..a65320350dc 100644 --- a/src/bentoml/_internal/runner/runner_handle/__init__.py +++ b/src/bentoml/_internal/runner/runner_handle/__init__.py @@ -1,7 +1,7 @@ from __future__ import annotations -import typing as t import logging +import typing as t from abc import ABC from abc import abstractmethod from typing import TYPE_CHECKING @@ -9,9 +9,9 @@ from ....exceptions import StateException if TYPE_CHECKING: + from ..runner import AbstractRunner from ..runner import Runner from ..runner import RunnerMethod - from ..runner import AbstractRunner R = t.TypeVar("R") P = t.ParamSpec("P") diff --git a/src/bentoml/_internal/runner/runner_handle/local.py b/src/bentoml/_internal/runner/runner_handle/local.py index 486c97d20a9..e0b36a81665 100644 --- a/src/bentoml/_internal/runner/runner_handle/local.py +++ b/src/bentoml/_internal/runner/runner_handle/local.py @@ -1,15 +1,15 @@ from __future__ import annotations -import typing as t import functools +import typing as t from typing import TYPE_CHECKING import anyio -from . import RunnerHandle -from ..utils import Params -from ..container import Payload from ..container import AutoContainer +from ..container import Payload +from ..utils import Params +from . import RunnerHandle if TYPE_CHECKING: from ..runner import Runner diff --git a/src/bentoml/_internal/runner/runner_handle/remote.py b/src/bentoml/_internal/runner/runner_handle/remote.py index e59edb96880..39a3c996618 100644 --- a/src/bentoml/_internal/runner/runner_handle/remote.py +++ b/src/bentoml/_internal/runner/runner_handle/remote.py @@ -1,40 +1,40 @@ from __future__ import annotations -import os -import json -import time -import pickle -import typing as t import asyncio -import logging import functools +import json +import logging +import os +import pickle +import time import traceback +import typing as t from json.decoder import JSONDecodeError from urllib.parse import urlparse -from . import RunnerHandle -from ..utils import Params -from ..utils import PAYLOAD_META_HEADER -from ...utils import LazyLoader -from ...context import component_context -from ..container import Payload -from ...utils.uri import uri_to_path from ....exceptions import RemoteException from ....exceptions import ServiceUnavailable from ...configuration.containers import BentoMLContainer +from ...context import component_context +from ...utils import LazyLoader +from ...utils.uri import uri_to_path +from ..container import Payload +from ..utils import PAYLOAD_META_HEADER +from ..utils import Params +from . import RunnerHandle TRITON_EXC_MSG = "tritonclient is required to use triton with BentoML. Install with 'pip install \"tritonclient[all]>=2.29.0\"'." if t.TYPE_CHECKING: - import yarl import tritonclient.grpc.aio as tritongrpcclient import tritonclient.http.aio as tritonhttpclient + import yarl from aiohttp import BaseConnector from aiohttp.client import ClientSession + from ....triton import Runner as TritonRunner from ..runner import Runner from ..runner import RunnerMethod - from ....triton import Runner as TritonRunner P = t.ParamSpec("P") R = t.TypeVar("R") diff --git a/src/bentoml/_internal/runner/strategy.py b/src/bentoml/_internal/runner/strategy.py index 270e648b712..ac4cbc43823 100644 --- a/src/bentoml/_internal/runner/strategy.py +++ b/src/bentoml/_internal/runner/strategy.py @@ -5,7 +5,8 @@ import math import typing as t -from ..resource import get_resource, system_resources +from ..resource import get_resource +from ..resource import system_resources from .runnable import Runnable logger = logging.getLogger(__name__) diff --git a/src/bentoml/_internal/runner/utils.py b/src/bentoml/_internal/runner/utils.py index 85b61cefe9f..5e3509e3984 100644 --- a/src/bentoml/_internal/runner/utils.py +++ b/src/bentoml/_internal/runner/utils.py @@ -1,8 +1,8 @@ from __future__ import annotations -import typing as t -import logging import itertools +import logging +import typing as t from typing import TYPE_CHECKING from bentoml.exceptions import InvalidArgument diff --git a/src/bentoml/_internal/server/grpc_app.py b/src/bentoml/_internal/server/grpc_app.py index d890117b9b4..4735bc13d80 100644 --- a/src/bentoml/_internal/server/grpc_app.py +++ b/src/bentoml/_internal/server/grpc_app.py @@ -7,6 +7,7 @@ import sys import typing as t from concurrent.futures import ThreadPoolExecutor +from functools import cached_property from functools import partial from typing import TYPE_CHECKING @@ -20,8 +21,6 @@ from ..configuration.containers import BentoMLContainer from ..context import ServiceContext as Context from ..utils import LazyLoader -from functools import cached_property - logger = logging.getLogger(__name__) diff --git a/src/bentoml/_internal/server/http/access.py b/src/bentoml/_internal/server/http/access.py index 3c146abf265..aae2d6b1bb4 100644 --- a/src/bentoml/_internal/server/http/access.py +++ b/src/bentoml/_internal/server/http/access.py @@ -1,9 +1,9 @@ from __future__ import annotations import logging +from contextvars import ContextVar from timeit import default_timer from typing import TYPE_CHECKING -from contextvars import ContextVar if TYPE_CHECKING: from ... import external_typing as ext diff --git a/src/bentoml/_internal/server/http/instruments.py b/src/bentoml/_internal/server/http/instruments.py index 805bd4c12a7..a55d9cfc576 100644 --- a/src/bentoml/_internal/server/http/instruments.py +++ b/src/bentoml/_internal/server/http/instruments.py @@ -1,15 +1,15 @@ from __future__ import annotations -import logging import contextvars +import logging from timeit import default_timer from typing import TYPE_CHECKING -from simple_di import inject from simple_di import Provide +from simple_di import inject -from ...context import component_context from ...configuration.containers import BentoMLContainer +from ...context import component_context if TYPE_CHECKING: from ... import external_typing as ext diff --git a/src/bentoml/_internal/server/metrics/prometheus.py b/src/bentoml/_internal/server/metrics/prometheus.py index f81a5e1b586..0e58fbbf6cb 100644 --- a/src/bentoml/_internal/server/metrics/prometheus.py +++ b/src/bentoml/_internal/server/metrics/prometheus.py @@ -1,11 +1,11 @@ from __future__ import annotations +import logging import os import sys import typing as t -import logging -from typing import TYPE_CHECKING from functools import partial +from typing import TYPE_CHECKING if TYPE_CHECKING: from ... import external_typing as ext @@ -60,11 +60,11 @@ def prometheus_client(self): # step 2: import prometheus_client - import prometheus_client.parser - import prometheus_client.metrics import prometheus_client.exposition + import prometheus_client.metrics import prometheus_client.metrics_core import prometheus_client.multiprocess + import prometheus_client.parser self._imported = True return prometheus_client diff --git a/src/bentoml/_internal/service/inference_api.py b/src/bentoml/_internal/service/inference_api.py index 793d9183b36..a25aaca523c 100644 --- a/src/bentoml/_internal/service/inference_api.py +++ b/src/bentoml/_internal/service/inference_api.py @@ -1,16 +1,16 @@ from __future__ import annotations +import inspect import re import typing as t -import inspect from typing import Optional import yaml -from ..types import is_compatible_type -from ..context import ServiceContext as Context from ...exceptions import InvalidArgument +from ..context import ServiceContext as Context from ..io_descriptors import IODescriptor +from ..types import is_compatible_type RESERVED_API_NAMES = [ "index", diff --git a/src/bentoml/_internal/service/loader.py b/src/bentoml/_internal/service/loader.py index 9dbdce87bf7..dc59a5eb4ac 100644 --- a/src/bentoml/_internal/service/loader.py +++ b/src/bentoml/_internal/service/loader.py @@ -1,29 +1,29 @@ from __future__ import annotations +import importlib +import logging import os import sys import typing as t -import logging -import importlib from typing import TYPE_CHECKING import fs -from simple_di import inject from simple_di import Provide +from simple_di import inject -from ..tag import Tag -from ..bento import Bento -from ..models import ModelStore -from .service import on_load_bento -from ...exceptions import NotFound from ...exceptions import BentoMLException from ...exceptions import ImportServiceError -from ..bento.bento import BENTO_YAML_FILENAME +from ...exceptions import NotFound +from ..bento import Bento from ..bento.bento import BENTO_PROJECT_DIR_NAME +from ..bento.bento import BENTO_YAML_FILENAME from ..bento.bento import DEFAULT_BENTO_BUILD_FILE -from ..configuration import BENTOML_VERSION from ..bento.build_config import BentoBuildConfig +from ..configuration import BENTOML_VERSION from ..configuration.containers import BentoMLContainer +from ..models import ModelStore +from ..tag import Tag +from .service import on_load_bento if TYPE_CHECKING: from ..bento import BentoStore diff --git a/src/bentoml/_internal/service/openapi/__init__.py b/src/bentoml/_internal/service/openapi/__init__.py index 2a0c6091edd..201ef884832 100644 --- a/src/bentoml/_internal/service/openapi/__init__.py +++ b/src/bentoml/_internal/service/openapi/__init__.py @@ -1,31 +1,31 @@ from __future__ import annotations import typing as t +from functools import lru_cache from http import HTTPStatus from typing import TYPE_CHECKING -from functools import lru_cache from deepmerge.merger import Merger -from bentoml.exceptions import NotFound -from bentoml.exceptions import InvalidArgument from bentoml.exceptions import InternalServerError +from bentoml.exceptions import InvalidArgument +from bentoml.exceptions import NotFound -from .utils import REF_PREFIX -from .utils import exception_schema -from .utils import exception_components_schema from ...types import LazyType from ...utils import bentoml_cattr -from .specification import Tag -from .specification import Info +from .specification import Components from .specification import Contact -from .specification import PathItem -from .specification import Response +from .specification import Info from .specification import MediaType +from .specification import OpenAPISpecification from .specification import Operation +from .specification import PathItem from .specification import Reference -from .specification import Components -from .specification import OpenAPISpecification +from .specification import Response +from .specification import Tag +from .utils import REF_PREFIX +from .utils import exception_components_schema +from .utils import exception_schema if TYPE_CHECKING: from .. import Service diff --git a/src/bentoml/_internal/service/openapi/specification.py b/src/bentoml/_internal/service/openapi/specification.py index d27504cda16..f19d40a7814 100644 --- a/src/bentoml/_internal/service/openapi/specification.py +++ b/src/bentoml/_internal/service/openapi/specification.py @@ -10,14 +10,14 @@ """ from __future__ import annotations -import typing as t import logging +import typing as t import attr -import yaml import cattr.errors -from cattr.gen import override +import yaml from cattr.gen import make_dict_unstructure_fn +from cattr.gen import override from ...utils import bentoml_cattr diff --git a/src/bentoml/_internal/service/openapi/utils.py b/src/bentoml/_internal/service/openapi/utils.py index 6e58d28ed35..2dcb2181366 100644 --- a/src/bentoml/_internal/service/openapi/utils.py +++ b/src/bentoml/_internal/service/openapi/utils.py @@ -1,12 +1,12 @@ from __future__ import annotations import typing as t -from typing import TYPE_CHECKING from functools import lru_cache +from typing import TYPE_CHECKING -from bentoml.exceptions import NotFound -from bentoml.exceptions import InvalidArgument from bentoml.exceptions import InternalServerError +from bentoml.exceptions import InvalidArgument +from bentoml.exceptions import NotFound from ...utils import LazyLoader from ...utils.pkg import pkg_version_info diff --git a/src/bentoml/_internal/store.py b/src/bentoml/_internal/store.py index 75b461aa316..a8aee3690fd 100644 --- a/src/bentoml/_internal/store.py +++ b/src/bentoml/_internal/store.py @@ -1,8 +1,8 @@ from __future__ import annotations +import datetime import os import typing as t -import datetime from abc import ABC from abc import abstractmethod from contextlib import contextmanager @@ -11,11 +11,11 @@ import fs.errors from fs.base import FS +from ..exceptions import BentoMLException +from ..exceptions import NotFound +from .exportable import Exportable from .tag import Tag from .types import PathType -from .exportable import Exportable -from ..exceptions import NotFound -from ..exceptions import BentoMLException T = t.TypeVar("T") diff --git a/src/bentoml/_internal/tag.py b/src/bentoml/_internal/tag.py index 6453a68232b..38e29875000 100644 --- a/src/bentoml/_internal/tag.py +++ b/src/bentoml/_internal/tag.py @@ -1,14 +1,14 @@ -import re -import uuid import base64 -import typing as t import logging +import re +import typing as t +import uuid -import fs import attr +import fs -from .utils import bentoml_cattr from ..exceptions import BentoMLException +from .utils import bentoml_cattr logger = logging.getLogger(__name__) diff --git a/src/bentoml/_internal/utils/analytics/__init__.py b/src/bentoml/_internal/utils/analytics/__init__.py index b82a6571bdb..cfc0b1d911d 100644 --- a/src/bentoml/_internal/utils/analytics/__init__.py +++ b/src/bentoml/_internal/utils/analytics/__init__.py @@ -1,13 +1,13 @@ +from .cli_events import cli_events_map +from .schemas import BentoBuildEvent from .schemas import CliEvent from .schemas import ModelSaveEvent -from .schemas import BentoBuildEvent from .schemas import ServeUpdateEvent -from .cli_events import cli_events_map -from .usage_stats import track +from .usage_stats import BENTOML_DO_NOT_TRACK from .usage_stats import ServeInfo -from .usage_stats import track_serve from .usage_stats import get_serve_info -from .usage_stats import BENTOML_DO_NOT_TRACK +from .usage_stats import track +from .usage_stats import track_serve __all__ = [ "track", diff --git a/src/bentoml/_internal/utils/analytics/schemas.py b/src/bentoml/_internal/utils/analytics/schemas.py index a81ec41acd6..64e8aa69b91 100644 --- a/src/bentoml/_internal/utils/analytics/schemas.py +++ b/src/bentoml/_internal/utils/analytics/schemas.py @@ -1,26 +1,27 @@ from __future__ import annotations + import os import re -import uuid import typing as t +import uuid from abc import ABC from datetime import datetime from datetime import timezone +from functools import lru_cache from platform import platform from platform import python_version -from functools import lru_cache import attr -import yaml -import psutil import attr.converters -from simple_di import inject +import psutil +import yaml from simple_di import Provide +from simple_di import inject -from ...utils import bentoml_cattr from ...cloud.config import CloudClientConfig from ...configuration import BENTOML_VERSION from ...configuration.containers import BentoMLContainer +from ...utils import bentoml_cattr if t.TYPE_CHECKING: from pathlib import Path diff --git a/src/bentoml/_internal/utils/analytics/usage_stats.py b/src/bentoml/_internal/utils/analytics/usage_stats.py index b82b382bd46..f87057992e5 100644 --- a/src/bentoml/_internal/utils/analytics/usage_stats.py +++ b/src/bentoml/_internal/utils/analytics/usage_stats.py @@ -1,30 +1,30 @@ from __future__ import annotations -import os -import typing as t +import contextlib import logging +import os import secrets import threading -import contextlib -from typing import TYPE_CHECKING +import typing as t from datetime import datetime from datetime import timezone -from functools import wraps from functools import lru_cache +from functools import wraps +from typing import TYPE_CHECKING import attr import requests -from simple_di import inject from simple_di import Provide +from simple_di import inject +from ...configuration import get_debug_mode +from ...configuration.containers import BentoMLContainer from ...utils import compose +from .schemas import CommonProperties from .schemas import EventMeta from .schemas import ServeInitEvent -from .schemas import TrackingPayload -from .schemas import CommonProperties from .schemas import ServeUpdateEvent -from ...configuration import get_debug_mode -from ...configuration.containers import BentoMLContainer +from .schemas import TrackingPayload if TYPE_CHECKING: P = t.ParamSpec("P") diff --git a/src/bentoml/_internal/utils/benchmark.py b/src/bentoml/_internal/utils/benchmark.py index 1bc92a70b1f..e75f4d42d7c 100644 --- a/src/bentoml/_internal/utils/benchmark.py +++ b/src/bentoml/_internal/utils/benchmark.py @@ -1,6 +1,6 @@ +import asyncio import math import time -import asyncio from collections import defaultdict from tabulate import tabulate diff --git a/src/bentoml/_internal/utils/buildx.py b/src/bentoml/_internal/utils/buildx.py index 008852ccd42..75e84b607b1 100644 --- a/src/bentoml/_internal/utils/buildx.py +++ b/src/bentoml/_internal/utils/buildx.py @@ -8,8 +8,8 @@ import typing as t import warnings -from ..container import health as _internal_container_health from ..container import get_backend +from ..container import health as _internal_container_health __all__ = ["build", "health"] diff --git a/src/bentoml/_internal/utils/circus/watchfilesplugin.py b/src/bentoml/_internal/utils/circus/watchfilesplugin.py index 42513ade3fa..81b0073a63c 100644 --- a/src/bentoml/_internal/utils/circus/watchfilesplugin.py +++ b/src/bentoml/_internal/utils/circus/watchfilesplugin.py @@ -1,23 +1,23 @@ from __future__ import annotations +import logging import os import typing as t -import logging -from typing import TYPE_CHECKING from pathlib import Path from threading import Event from threading import Thread +from typing import TYPE_CHECKING import fs -from watchfiles import watch from circus.plugins import CircusPlugin +from watchfiles import watch -from ...log import configure_server_logging +from ...bento.build_config import BentoBuildConfig +from ...bento.build_config import BentoPathSpec +from ...configuration import is_pypi_installed_bentoml from ...context import component_context +from ...log import configure_server_logging from ...utils.pkg import source_locations -from ...configuration import is_pypi_installed_bentoml -from ...bento.build_config import BentoPathSpec -from ...bento.build_config import BentoBuildConfig if TYPE_CHECKING: from watchfiles.main import FileChange diff --git a/src/bentoml/_internal/utils/dotenv.py b/src/bentoml/_internal/utils/dotenv.py index bdab2a96369..00bd48fb533 100644 --- a/src/bentoml/_internal/utils/dotenv.py +++ b/src/bentoml/_internal/utils/dotenv.py @@ -25,10 +25,10 @@ """ from __future__ import annotations +import logging import os import re import typing as t -import logging logger = logging.getLogger(__name__) diff --git a/src/bentoml/_internal/utils/formparser.py b/src/bentoml/_internal/utils/formparser.py index 7bd415b3c99..65b9f3126d1 100644 --- a/src/bentoml/_internal/utils/formparser.py +++ b/src/bentoml/_internal/utils/formparser.py @@ -1,24 +1,24 @@ from __future__ import annotations import io -import uuid import typing as t +import uuid +from dataclasses import dataclass +from dataclasses import field from enum import Enum from tempfile import SpooledTemporaryFile -from dataclasses import field -from dataclasses import dataclass from urllib.parse import unquote_plus import multipart.multipart as multipart -from starlette.requests import Request -from starlette.responses import Response -from starlette.datastructures import Headers from starlette.datastructures import FormData -from starlette.datastructures import UploadFile +from starlette.datastructures import Headers from starlette.datastructures import MutableHeaders +from starlette.datastructures import UploadFile +from starlette.requests import Request +from starlette.responses import Response -from .http import set_cookies from ...exceptions import BentoMLException +from .http import set_cookies if t.TYPE_CHECKING: from ..context import ServiceContext as Context diff --git a/src/bentoml/_internal/utils/lazy_loader.py b/src/bentoml/_internal/utils/lazy_loader.py index 2793aa4ac26..3ff100e5e57 100644 --- a/src/bentoml/_internal/utils/lazy_loader.py +++ b/src/bentoml/_internal/utils/lazy_loader.py @@ -1,10 +1,10 @@ from __future__ import annotations +import importlib +import logging import sys import types import typing as t -import logging -import importlib from ...exceptions import MissingDependencyException diff --git a/src/bentoml/_internal/utils/pickle.py b/src/bentoml/_internal/utils/pickle.py index 1abc687e705..ae6b4a973fa 100644 --- a/src/bentoml/_internal/utils/pickle.py +++ b/src/bentoml/_internal/utils/pickle.py @@ -1,10 +1,8 @@ from __future__ import annotations import io -import typing as t - import pickle - +import typing as t # Pickle protocol 5 with out-of-band data. ref: https://peps.python.org/pep-0574/ diff --git a/src/bentoml/_internal/utils/pkg.py b/src/bentoml/_internal/utils/pkg.py index cdffbc7d43e..f4c9b4d7b2a 100644 --- a/src/bentoml/_internal/utils/pkg.py +++ b/src/bentoml/_internal/utils/pkg.py @@ -1,11 +1,10 @@ from __future__ import annotations -from types import ModuleType -from typing import cast - import importlib.metadata -from importlib.metadata import PackageNotFoundError import importlib.util +from importlib.metadata import PackageNotFoundError +from types import ModuleType +from typing import cast from packaging.version import Version diff --git a/src/bentoml/_internal/utils/telemetry.py b/src/bentoml/_internal/utils/telemetry.py index 86a39dcc92d..e63bd105e76 100644 --- a/src/bentoml/_internal/utils/telemetry.py +++ b/src/bentoml/_internal/utils/telemetry.py @@ -2,17 +2,17 @@ import typing as t from typing import TYPE_CHECKING -from opentelemetry.trace import get_current_span -from opentelemetry.sdk.trace.sampling import Decision from opentelemetry.sdk.trace.sampling import ALWAYS_ON +from opentelemetry.sdk.trace.sampling import Decision from opentelemetry.sdk.trace.sampling import ParentBased -from opentelemetry.sdk.trace.sampling import StaticSampler from opentelemetry.sdk.trace.sampling import SamplingResult +from opentelemetry.sdk.trace.sampling import StaticSampler from opentelemetry.sdk.trace.sampling import TraceIdRatioBased +from opentelemetry.trace import get_current_span if TYPE_CHECKING: - from opentelemetry.trace import Link from opentelemetry.trace import Context + from opentelemetry.trace import Link from opentelemetry.trace import SpanKind from opentelemetry.trace import TraceState from opentelemetry.util.types import Attributes diff --git a/src/bentoml/_internal/utils/unflatten.py b/src/bentoml/_internal/utils/unflatten.py index f0e4b468e6f..95d461be001 100644 --- a/src/bentoml/_internal/utils/unflatten.py +++ b/src/bentoml/_internal/utils/unflatten.py @@ -35,8 +35,8 @@ POSSIBILITY OF SUCH DAMAGE. """ -from __future__ import annotations from __future__ import absolute_import +from __future__ import annotations import re import sys diff --git a/src/bentoml/bentos.py b/src/bentoml/bentos.py index fcda850fc44..e3a732b6dae 100644 --- a/src/bentoml/bentos.py +++ b/src/bentoml/bentos.py @@ -4,34 +4,34 @@ from __future__ import annotations +import logging import os import re -import typing as t -import logging -import tempfile import subprocess +import tempfile +import typing as t -from simple_di import inject from simple_di import Provide +from simple_di import inject -from .exceptions import BadInput -from .exceptions import InvalidArgument -from .exceptions import BentoMLException -from ._internal.tag import Tag from ._internal.bento import Bento -from ._internal.utils import resolve_user_filepath 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 ._internal.utils.analytics.usage_stats import _usage_event_debugging +from .exceptions import BadInput +from .exceptions import BentoMLException +from .exceptions import InvalidArgument if t.TYPE_CHECKING: - from .server import Server from ._internal.bento import BentoStore - from ._internal.cloud import BentoCloudClient from ._internal.bento.build_config import CondaOptions from ._internal.bento.build_config import DockerOptions - from ._internal.bento.build_config import PythonOptions from ._internal.bento.build_config import ModelSpec + from ._internal.bento.build_config import PythonOptions + from ._internal.cloud import BentoCloudClient + from .server import Server logger = logging.getLogger(__name__) diff --git a/src/bentoml/catboost.py b/src/bentoml/catboost.py index 9d860360772..dcdd292dc60 100644 --- a/src/bentoml/catboost.py +++ b/src/bentoml/catboost.py @@ -1,7 +1,9 @@ +from ._internal.frameworks.catboost import ( + CatBoostOptions as ModelOptions, # type: ignore # noqa +) from ._internal.frameworks.catboost import get +from ._internal.frameworks.catboost import get_runnable from ._internal.frameworks.catboost import load_model from ._internal.frameworks.catboost import save_model -from ._internal.frameworks.catboost import get_runnable -from ._internal.frameworks.catboost import CatBoostOptions as ModelOptions # type: ignore # noqa __all__ = ["load_model", "save_model", "get", "get_runnable"] diff --git a/src/bentoml/cloud.py b/src/bentoml/cloud.py index f8e90bbc60e..66e9c1bca1c 100644 --- a/src/bentoml/cloud.py +++ b/src/bentoml/cloud.py @@ -1,3 +1,3 @@ -from ._internal.cloud import YataiClient as YataiClient from ._internal.cloud import BentoCloudClient as BentoCloudClient from ._internal.cloud import Resource as Resource +from ._internal.cloud import YataiClient as YataiClient diff --git a/src/bentoml/container.py b/src/bentoml/container.py index 2b22a438a27..6d28867e96a 100644 --- a/src/bentoml/container.py +++ b/src/bentoml/container.py @@ -4,31 +4,31 @@ from __future__ import annotations +import logging import os -import sys import shutil +import sys import typing as t -import logging from typing import TYPE_CHECKING -from simple_di import inject from simple_di import Provide +from simple_di import inject -from .exceptions import BentoMLException +from ._internal.configuration.containers import BentoMLContainer from ._internal.container import build as _internal_build -from ._internal.container import health -from ._internal.container import get_backend -from ._internal.container import register_backend from ._internal.container import ( construct_containerfile as _internal_construct_containerfile, ) -from ._internal.configuration.containers import BentoMLContainer +from ._internal.container import get_backend +from ._internal.container import health +from ._internal.container import register_backend +from .exceptions import BentoMLException if TYPE_CHECKING: - from ._internal.tag import Tag from ._internal.bento import BentoStore - from ._internal.types import PathType from ._internal.container.base import ArgType + from ._internal.tag import Tag + from ._internal.types import PathType logger = logging.getLogger(__name__) diff --git a/src/bentoml/detectron.py b/src/bentoml/detectron.py index 3bbbd0e45a7..b01f3ecf01b 100644 --- a/src/bentoml/detectron.py +++ b/src/bentoml/detectron.py @@ -1,7 +1,7 @@ +from ._internal.frameworks.detectron import ModelOptions from ._internal.frameworks.detectron import get +from ._internal.frameworks.detectron import get_runnable from ._internal.frameworks.detectron import load_model from ._internal.frameworks.detectron import save_model -from ._internal.frameworks.detectron import get_runnable -from ._internal.frameworks.detectron import ModelOptions __all__ = ["load_model", "save_model", "get", "get_runnable", "ModelOptions"] diff --git a/src/bentoml/diffusers.py b/src/bentoml/diffusers.py index 8180f4e7c2b..64f3444864e 100644 --- a/src/bentoml/diffusers.py +++ b/src/bentoml/diffusers.py @@ -1,11 +1,11 @@ from __future__ import annotations +from ._internal.frameworks.diffusers import DiffusersOptions as ModelOptions from ._internal.frameworks.diffusers import get -from ._internal.frameworks.diffusers import load_model -from ._internal.frameworks.diffusers import save_model from ._internal.frameworks.diffusers import get_runnable from ._internal.frameworks.diffusers import import_model -from ._internal.frameworks.diffusers import DiffusersOptions as ModelOptions +from ._internal.frameworks.diffusers import load_model +from ._internal.frameworks.diffusers import save_model __all__ = [ "get", diff --git a/src/bentoml/easyocr.py b/src/bentoml/easyocr.py index 7012a153184..0424bb4dbf7 100644 --- a/src/bentoml/easyocr.py +++ b/src/bentoml/easyocr.py @@ -1,6 +1,6 @@ from ._internal.frameworks.easyocr import get +from ._internal.frameworks.easyocr import get_runnable from ._internal.frameworks.easyocr import load_model from ._internal.frameworks.easyocr import save_model -from ._internal.frameworks.easyocr import get_runnable __all__ = ["load_model", "save_model", "get", "get_runnable"] diff --git a/src/bentoml/fastai.py b/src/bentoml/fastai.py index 95466b65835..ea614b79444 100644 --- a/src/bentoml/fastai.py +++ b/src/bentoml/fastai.py @@ -1,6 +1,6 @@ from ._internal.frameworks.fastai import get +from ._internal.frameworks.fastai import get_runnable from ._internal.frameworks.fastai import load_model from ._internal.frameworks.fastai import save_model -from ._internal.frameworks.fastai import get_runnable __all__ = ["load_model", "save_model", "get", "get_runnable"] diff --git a/src/bentoml/flax.py b/src/bentoml/flax.py index d17178ad8f0..d604a4e2552 100644 --- a/src/bentoml/flax.py +++ b/src/bentoml/flax.py @@ -1,7 +1,7 @@ +from ._internal.frameworks.flax import ModelOptions from ._internal.frameworks.flax import get +from ._internal.frameworks.flax import get_runnable from ._internal.frameworks.flax import load_model from ._internal.frameworks.flax import save_model -from ._internal.frameworks.flax import get_runnable -from ._internal.frameworks.flax import ModelOptions __all__ = ["load_model", "save_model", "get", "get_runnable", "ModelOptions"] diff --git a/src/bentoml/grpc/interceptors/access.py b/src/bentoml/grpc/interceptors/access.py index ff60692e999..d6c1f7d3533 100644 --- a/src/bentoml/grpc/interceptors/access.py +++ b/src/bentoml/grpc/interceptors/access.py @@ -1,29 +1,29 @@ from __future__ import annotations -import typing as t -import logging import functools +import logging +import typing as t from timeit import default_timer from typing import TYPE_CHECKING +from bentoml.grpc.utils import GRPC_CONTENT_TYPE +from bentoml.grpc.utils import import_generated_stubs from bentoml.grpc.utils import import_grpc from bentoml.grpc.utils import to_http_status from bentoml.grpc.utils import wrap_rpc_handler -from bentoml.grpc.utils import GRPC_CONTENT_TYPE -from bentoml.grpc.utils import import_generated_stubs if TYPE_CHECKING: import grpc from grpc import aio from grpc.aio._typing import MetadataType # pylint: disable=unused-import - from bentoml.grpc.v1 import service_pb2 as pb + from bentoml.grpc.types import AsyncHandlerMethod + from bentoml.grpc.types import BentoServicerContext + from bentoml.grpc.types import HandlerCallDetails from bentoml.grpc.types import Request from bentoml.grpc.types import Response from bentoml.grpc.types import RpcMethodHandler - from bentoml.grpc.types import AsyncHandlerMethod - from bentoml.grpc.types import HandlerCallDetails - from bentoml.grpc.types import BentoServicerContext + from bentoml.grpc.v1 import service_pb2 as pb else: pb, _ = import_generated_stubs() grpc, aio = import_grpc() diff --git a/src/bentoml/grpc/interceptors/opentelemetry.py b/src/bentoml/grpc/interceptors/opentelemetry.py index 94d61395e29..02ad3e86112 100644 --- a/src/bentoml/grpc/interceptors/opentelemetry.py +++ b/src/bentoml/grpc/interceptors/opentelemetry.py @@ -1,27 +1,27 @@ from __future__ import annotations -import typing as t -import logging import functools -from typing import TYPE_CHECKING +import logging +import typing as t from contextlib import asynccontextmanager +from typing import TYPE_CHECKING -from simple_di import inject -from simple_di import Provide from opentelemetry import trace from opentelemetry.context import attach from opentelemetry.context import detach from opentelemetry.propagate import extract +from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.trace.status import Status from opentelemetry.trace.status import StatusCode -from opentelemetry.semconv.trace import SpanAttributes +from simple_di import Provide +from simple_di import inject -from bentoml.grpc.utils import import_grpc -from bentoml.grpc.utils import wrap_rpc_handler +from bentoml._internal.configuration.containers import BentoMLContainer +from bentoml._internal.utils.pkg import get_pkg_version from bentoml.grpc.utils import GRPC_CONTENT_TYPE +from bentoml.grpc.utils import import_grpc from bentoml.grpc.utils import parse_method_name -from bentoml._internal.utils.pkg import get_pkg_version -from bentoml._internal.configuration.containers import BentoMLContainer +from bentoml.grpc.utils import wrap_rpc_handler if TYPE_CHECKING: import grpc @@ -29,15 +29,15 @@ from grpc.aio._typing import MetadataKey from grpc.aio._typing import MetadataType from grpc.aio._typing import MetadataValue - from opentelemetry.trace import Span from opentelemetry.sdk.trace import TracerProvider + from opentelemetry.trace import Span + from bentoml.grpc.types import AsyncHandlerMethod + from bentoml.grpc.types import BentoServicerContext + from bentoml.grpc.types import HandlerCallDetails from bentoml.grpc.types import Request from bentoml.grpc.types import Response from bentoml.grpc.types import RpcMethodHandler - from bentoml.grpc.types import AsyncHandlerMethod - from bentoml.grpc.types import HandlerCallDetails - from bentoml.grpc.types import BentoServicerContext else: grpc, aio = import_grpc() diff --git a/src/bentoml/grpc/interceptors/prometheus.py b/src/bentoml/grpc/interceptors/prometheus.py index a3446a1a274..75306f53ed1 100644 --- a/src/bentoml/grpc/interceptors/prometheus.py +++ b/src/bentoml/grpc/interceptors/prometheus.py @@ -1,21 +1,21 @@ from __future__ import annotations -import typing as t -import logging -import functools import contextvars +import functools +import logging +import typing as t from timeit import default_timer from typing import TYPE_CHECKING -from simple_di import inject from simple_di import Provide +from simple_di import inject +from bentoml._internal.configuration.containers import BentoMLContainer +from bentoml._internal.context import component_context +from bentoml.grpc.utils import import_generated_stubs from bentoml.grpc.utils import import_grpc from bentoml.grpc.utils import to_http_status from bentoml.grpc.utils import wrap_rpc_handler -from bentoml.grpc.utils import import_generated_stubs -from bentoml._internal.context import component_context -from bentoml._internal.configuration.containers import BentoMLContainer START_TIME_VAR: contextvars.ContextVar[float] = contextvars.ContextVar("START_TIME_VAR") @@ -23,14 +23,14 @@ import grpc from grpc import aio - from bentoml.grpc.v1 import service_pb2 as pb + from bentoml._internal.server.metrics.prometheus import PrometheusClient + from bentoml.grpc.types import AsyncHandlerMethod + from bentoml.grpc.types import BentoServicerContext + from bentoml.grpc.types import HandlerCallDetails from bentoml.grpc.types import Request from bentoml.grpc.types import Response from bentoml.grpc.types import RpcMethodHandler - from bentoml.grpc.types import AsyncHandlerMethod - from bentoml.grpc.types import HandlerCallDetails - from bentoml.grpc.types import BentoServicerContext - from bentoml._internal.server.metrics.prometheus import PrometheusClient + from bentoml.grpc.v1 import service_pb2 as pb else: pb, _ = import_generated_stubs() grpc, aio = import_grpc() diff --git a/src/bentoml/grpc/utils/__init__.py b/src/bentoml/grpc/utils/__init__.py index 71c9c00c158..899781c7d78 100644 --- a/src/bentoml/grpc/utils/__init__.py +++ b/src/bentoml/grpc/utils/__init__.py @@ -1,29 +1,29 @@ from __future__ import annotations -import typing as t import logging +import typing as t +from dataclasses import dataclass +from functools import lru_cache from http import HTTPStatus from typing import TYPE_CHECKING -from functools import lru_cache -from dataclasses import dataclass +from ..._internal.utils import resolve_user_filepath from ...exceptions import InvalidArgument -from ._import_hook import import_grpc -from ._import_hook import import_generated_stubs from ._import_hook import LATEST_PROTOCOL_VERSION -from ..._internal.utils import resolve_user_filepath +from ._import_hook import import_generated_stubs +from ._import_hook import import_grpc if TYPE_CHECKING: from enum import Enum import grpc - from ..v1 import service_pb2 as pb + from ..._internal.io_descriptors import IODescriptor + from ...exceptions import BentoMLException + from ..types import BentoServicerContext from ..types import ProtoField from ..types import RpcMethodHandler - from ..types import BentoServicerContext - from ...exceptions import BentoMLException - from ..._internal.io_descriptors import IODescriptor + from ..v1 import service_pb2 as pb else: pb, _ = import_generated_stubs() diff --git a/src/bentoml/io.py b/src/bentoml/io.py index 06e573750b8..ca862c21179 100644 --- a/src/bentoml/io.py +++ b/src/bentoml/io.py @@ -3,13 +3,13 @@ from ._internal.io_descriptors import from_spec from ._internal.io_descriptors.base import IODescriptor from ._internal.io_descriptors.file import File -from ._internal.io_descriptors.json import JSON -from ._internal.io_descriptors.text import Text from ._internal.io_descriptors.image import Image +from ._internal.io_descriptors.json import JSON +from ._internal.io_descriptors.multipart import Multipart from ._internal.io_descriptors.numpy import NumpyNdarray -from ._internal.io_descriptors.pandas import PandasSeries from ._internal.io_descriptors.pandas import PandasDataFrame -from ._internal.io_descriptors.multipart import Multipart +from ._internal.io_descriptors.pandas import PandasSeries +from ._internal.io_descriptors.text import Text __all__ = [ "File", diff --git a/src/bentoml/keras.py b/src/bentoml/keras.py index d42640aa9d0..0429ae1bed7 100644 --- a/src/bentoml/keras.py +++ b/src/bentoml/keras.py @@ -1,14 +1,14 @@ from __future__ import annotations -import typing as t import logging +import typing as t from typing import TYPE_CHECKING +from ._internal.frameworks.keras import KerasOptions as ModelOptions from ._internal.frameworks.keras import get +from ._internal.frameworks.keras import get_runnable from ._internal.frameworks.keras import load_model from ._internal.frameworks.keras import save_model -from ._internal.frameworks.keras import get_runnable -from ._internal.frameworks.keras import KerasOptions as ModelOptions if TYPE_CHECKING: from ._internal.tag import Tag diff --git a/src/bentoml/lightgbm.py b/src/bentoml/lightgbm.py index 6b0fec1bc07..4d10b414184 100644 --- a/src/bentoml/lightgbm.py +++ b/src/bentoml/lightgbm.py @@ -1,13 +1,13 @@ from __future__ import annotations -import typing as t import logging +import typing as t from typing import TYPE_CHECKING from ._internal.frameworks.lightgbm import get +from ._internal.frameworks.lightgbm import get_runnable from ._internal.frameworks.lightgbm import load_model from ._internal.frameworks.lightgbm import save_model -from ._internal.frameworks.lightgbm import get_runnable if TYPE_CHECKING: from ._internal.tag import Tag diff --git a/src/bentoml/metrics.py b/src/bentoml/metrics.py index a1abd4ed955..1640c66ac1a 100644 --- a/src/bentoml/metrics.py +++ b/src/bentoml/metrics.py @@ -1,11 +1,11 @@ from __future__ import annotations -import typing as t import logging +import typing as t from typing import TYPE_CHECKING -from simple_di import inject from simple_di import Provide +from simple_di import inject from ._internal.configuration.containers import BentoMLContainer diff --git a/src/bentoml/mlflow.py b/src/bentoml/mlflow.py index 43a07aadfa7..8f8c2e929d2 100644 --- a/src/bentoml/mlflow.py +++ b/src/bentoml/mlflow.py @@ -1,9 +1,9 @@ +from ._internal.frameworks.mlflow import MLFLOW_MODEL_FOLDER from ._internal.frameworks.mlflow import get -from ._internal.frameworks.mlflow import load_model +from ._internal.frameworks.mlflow import get_mlflow_model from ._internal.frameworks.mlflow import get_runnable from ._internal.frameworks.mlflow import import_model -from ._internal.frameworks.mlflow import get_mlflow_model -from ._internal.frameworks.mlflow import MLFLOW_MODEL_FOLDER +from ._internal.frameworks.mlflow import load_model __all__ = [ "load_model", diff --git a/src/bentoml/models.py b/src/bentoml/models.py index 083d48d8b58..605dc6ab844 100644 --- a/src/bentoml/models.py +++ b/src/bentoml/models.py @@ -1,27 +1,27 @@ from __future__ import annotations import typing as t +from contextlib import contextmanager from types import ModuleType from typing import TYPE_CHECKING -from contextlib import contextmanager -from simple_di import inject from simple_di import Provide +from simple_di import inject -from .exceptions import BentoMLException -from ._internal.tag import Tag -from ._internal.utils import calc_dir_size +from ._internal.configuration.containers import BentoMLContainer from ._internal.models import Model from ._internal.models import ModelContext from ._internal.models import ModelOptions -from ._internal.utils.analytics import track +from ._internal.tag import Tag +from ._internal.utils import calc_dir_size from ._internal.utils.analytics import ModelSaveEvent -from ._internal.configuration.containers import BentoMLContainer +from ._internal.utils.analytics import track +from .exceptions import BentoMLException if TYPE_CHECKING: + from ._internal.cloud import BentoCloudClient from ._internal.models import ModelStore from ._internal.models.model import ModelSignaturesType - from ._internal.cloud import BentoCloudClient @inject diff --git a/src/bentoml/monitoring.py b/src/bentoml/monitoring.py index 538744bb756..aa6ff097c7d 100644 --- a/src/bentoml/monitoring.py +++ b/src/bentoml/monitoring.py @@ -1,5 +1,5 @@ -from ._internal.monitoring import monitor -from ._internal.monitoring import MonitorBase from ._internal.monitoring import DefaultMonitor +from ._internal.monitoring import MonitorBase +from ._internal.monitoring import monitor __all__ = ["MonitorBase", "monitor", "DefaultMonitor"] diff --git a/src/bentoml/onnx.py b/src/bentoml/onnx.py index dd0608920d7..6f08da0b1f7 100644 --- a/src/bentoml/onnx.py +++ b/src/bentoml/onnx.py @@ -1,14 +1,16 @@ from __future__ import annotations -import typing as t import logging +import typing as t from typing import TYPE_CHECKING +from ._internal.frameworks.onnx import ( + ONNXOptions as ModelOptions, # type: ignore # noqa +) from ._internal.frameworks.onnx import get +from ._internal.frameworks.onnx import get_runnable from ._internal.frameworks.onnx import load_model from ._internal.frameworks.onnx import save_model -from ._internal.frameworks.onnx import ONNXOptions as ModelOptions # type: ignore # noqa -from ._internal.frameworks.onnx import get_runnable if TYPE_CHECKING: from ._internal.tag import Tag diff --git a/src/bentoml/picklable_model.py b/src/bentoml/picklable_model.py index 67dedec4a77..42d5bb83c3f 100644 --- a/src/bentoml/picklable_model.py +++ b/src/bentoml/picklable_model.py @@ -1,7 +1,7 @@ +from ._internal.frameworks.picklable import ModelOptions from ._internal.frameworks.picklable import get +from ._internal.frameworks.picklable import get_runnable from ._internal.frameworks.picklable import load_model from ._internal.frameworks.picklable import save_model -from ._internal.frameworks.picklable import get_runnable -from ._internal.frameworks.picklable import ModelOptions __all__ = ["load_model", "get_runnable", "save_model", "get", "ModelOptions"] diff --git a/src/bentoml/pytorch.py b/src/bentoml/pytorch.py index 580c65a8e49..3dda012c50f 100644 --- a/src/bentoml/pytorch.py +++ b/src/bentoml/pytorch.py @@ -1,14 +1,14 @@ from __future__ import annotations -import typing as t import logging +import typing as t from typing import TYPE_CHECKING +from ._internal.frameworks.pytorch import ModelOptions from ._internal.frameworks.pytorch import get +from ._internal.frameworks.pytorch import get_runnable from ._internal.frameworks.pytorch import load_model from ._internal.frameworks.pytorch import save_model -from ._internal.frameworks.pytorch import get_runnable -from ._internal.frameworks.pytorch import ModelOptions if TYPE_CHECKING: from ._internal.tag import Tag diff --git a/src/bentoml/pytorch_lightning.py b/src/bentoml/pytorch_lightning.py index b7bcf58f83a..96b5487babf 100644 --- a/src/bentoml/pytorch_lightning.py +++ b/src/bentoml/pytorch_lightning.py @@ -1,13 +1,13 @@ from __future__ import annotations -import typing as t import logging +import typing as t from typing import TYPE_CHECKING from ._internal.frameworks.pytorch_lightning import get +from ._internal.frameworks.pytorch_lightning import get_runnable from ._internal.frameworks.pytorch_lightning import load_model from ._internal.frameworks.pytorch_lightning import save_model -from ._internal.frameworks.pytorch_lightning import get_runnable if TYPE_CHECKING: from ._internal.tag import Tag diff --git a/src/bentoml/server.py b/src/bentoml/server.py index 1626ec83bcd..c05d9f6d7e9 100644 --- a/src/bentoml/server.py +++ b/src/bentoml/server.py @@ -1,25 +1,25 @@ from __future__ import annotations +import logging import os -import sys import signal -import typing as t -import logging -import textwrap import subprocess +import sys +import textwrap +import typing as t from abc import ABC from abc import abstractmethod from typing import TYPE_CHECKING -from simple_di import inject from simple_di import Provide +from simple_di import inject -from .exceptions import BentoMLException -from ._internal.tag import Tag from ._internal.bento import Bento -from ._internal.service import Service from ._internal.configuration.containers import BentoMLContainer +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 BentoMLException if TYPE_CHECKING: from types import TracebackType diff --git a/src/bentoml/sklearn.py b/src/bentoml/sklearn.py index b299d549eab..22fc9f9ea45 100644 --- a/src/bentoml/sklearn.py +++ b/src/bentoml/sklearn.py @@ -1,13 +1,13 @@ from __future__ import annotations -import typing as t import logging +import typing as t from typing import TYPE_CHECKING from ._internal.frameworks.sklearn import get +from ._internal.frameworks.sklearn import get_runnable from ._internal.frameworks.sklearn import load_model from ._internal.frameworks.sklearn import save_model -from ._internal.frameworks.sklearn import get_runnable if TYPE_CHECKING: from ._internal.tag import Tag diff --git a/src/bentoml/start.py b/src/bentoml/start.py index 8f5ebbe8e65..fa15a814b88 100644 --- a/src/bentoml/start.py +++ b/src/bentoml/start.py @@ -1,16 +1,16 @@ from __future__ import annotations -import os +import contextlib import json import logging -import contextlib +import os -from simple_di import inject from simple_di import Provide +from simple_di import inject -from .grpc.utils import LATEST_PROTOCOL_VERSION -from ._internal.runner.runner import Runner from ._internal.configuration.containers import BentoMLContainer +from ._internal.runner.runner import Runner +from .grpc.utils import LATEST_PROTOCOL_VERSION logger = logging.getLogger(__name__) @@ -40,11 +40,11 @@ def start_runner_server( prometheus_dir = ensure_prometheus_dir() from . import load - from .serve import create_watcher - from .serve import find_triton_binary from ._internal.utils import reserve_free_port - from ._internal.utils.circus import create_standalone_arbiter from ._internal.utils.analytics import track_serve + from ._internal.utils.circus import create_standalone_arbiter + from .serve import create_watcher + from .serve import find_triton_binary working_dir = os.path.realpath(os.path.expanduser(working_dir)) svc = load(bento_identifier, working_dir=working_dir, standalone_load=True) @@ -160,12 +160,12 @@ def start_http_server( from circus.watcher import Watcher from . import load - from .serve import create_watcher + from ._internal.utils.analytics import track_serve + from ._internal.utils.circus import create_standalone_arbiter from .serve import API_SERVER_NAME - from .serve import construct_ssl_args from .serve import PROMETHEUS_MESSAGE - from ._internal.utils.circus import create_standalone_arbiter - from ._internal.utils.analytics import track_serve + from .serve import construct_ssl_args + from .serve import create_watcher working_dir = os.path.realpath(os.path.expanduser(working_dir)) svc = load(bento_identifier, working_dir=working_dir, standalone_load=True) @@ -270,13 +270,13 @@ def start_grpc_server( from bentoml import load - from .serve import create_watcher - from .serve import construct_ssl_args - from .serve import PROMETHEUS_MESSAGE - from .serve import PROMETHEUS_SERVER_NAME from ._internal.utils import reserve_free_port - from ._internal.utils.circus import create_standalone_arbiter from ._internal.utils.analytics import track_serve + from ._internal.utils.circus import create_standalone_arbiter + from .serve import PROMETHEUS_MESSAGE + from .serve import PROMETHEUS_SERVER_NAME + from .serve import construct_ssl_args + from .serve import create_watcher working_dir = os.path.realpath(os.path.expanduser(working_dir)) svc = load(bento_identifier, working_dir=working_dir, standalone_load=True) diff --git a/src/bentoml/tensorflow.py b/src/bentoml/tensorflow.py index b2e09777180..fbab4095259 100644 --- a/src/bentoml/tensorflow.py +++ b/src/bentoml/tensorflow.py @@ -1,14 +1,14 @@ from __future__ import annotations -import typing as t import logging +import typing as t from typing import TYPE_CHECKING +from ._internal.frameworks.tensorflow_v2 import ModelOptions from ._internal.frameworks.tensorflow_v2 import get +from ._internal.frameworks.tensorflow_v2 import get_runnable from ._internal.frameworks.tensorflow_v2 import load_model from ._internal.frameworks.tensorflow_v2 import save_model -from ._internal.frameworks.tensorflow_v2 import get_runnable -from ._internal.frameworks.tensorflow_v2 import ModelOptions if TYPE_CHECKING: from ._internal.tag import Tag diff --git a/src/bentoml/testing/grpc/__init__.py b/src/bentoml/testing/grpc/__init__.py index 057b56331ef..e8c40a2d8fa 100644 --- a/src/bentoml/testing/grpc/__init__.py +++ b/src/bentoml/testing/grpc/__init__.py @@ -1,31 +1,31 @@ from __future__ import annotations -import typing as t import importlib import traceback -from typing import TYPE_CHECKING +import typing as t from contextlib import ExitStack from contextlib import asynccontextmanager +from typing import TYPE_CHECKING -from ...exceptions import BentoMLException -from ...grpc.utils import import_grpc -from ...grpc.utils import import_generated_stubs -from ...grpc.utils import LATEST_PROTOCOL_VERSION from ..._internal.utils import LazyLoader -from ..._internal.utils import reserve_free_port -from ..._internal.utils import cached_contextmanager from ..._internal.utils import add_experimental_docstring +from ..._internal.utils import cached_contextmanager +from ..._internal.utils import reserve_free_port +from ...exceptions import BentoMLException +from ...grpc.utils import LATEST_PROTOCOL_VERSION +from ...grpc.utils import import_generated_stubs +from ...grpc.utils import import_grpc if TYPE_CHECKING: import grpc import numpy as np + from google.protobuf.message import Message from grpc import aio - from numpy.typing import NDArray from grpc.aio._channel import Channel - from google.protobuf.message import Message + from numpy.typing import NDArray - from ...grpc.v1 import service_pb2 as pb from ..._internal.service import Service + from ...grpc.v1 import service_pb2 as pb else: grpc, aio = import_grpc() # pylint: disable=E1111 np = LazyLoader("np", globals(), "numpy") diff --git a/src/bentoml/testing/pytest/plugin.py b/src/bentoml/testing/pytest/plugin.py index 52dadc6374a..0d09f8710d3 100644 --- a/src/bentoml/testing/pytest/plugin.py +++ b/src/bentoml/testing/pytest/plugin.py @@ -1,10 +1,10 @@ # pylint: disable=unused-argument from __future__ import annotations +import contextlib import os -import typing as t import tempfile -import contextlib +import typing as t from typing import TYPE_CHECKING import psutil @@ -12,21 +12,21 @@ from pytest import MonkeyPatch import bentoml -from bentoml._internal.utils import LazyLoader -from bentoml._internal.utils import validate_or_create_dir -from bentoml._internal.models import ModelContext from bentoml._internal.configuration import CLEAN_BENTOML_VERSION from bentoml._internal.configuration.containers import BentoMLContainer +from bentoml._internal.models import ModelContext +from bentoml._internal.utils import LazyLoader +from bentoml._internal.utils import validate_or_create_dir if TYPE_CHECKING: import numpy as np - from _pytest.main import Session - from _pytest.nodes import Item from _pytest.config import Config from _pytest.config import ExitCode - from _pytest.python import Metafunc - from _pytest.fixtures import FixtureRequest from _pytest.config.argparsing import Parser + from _pytest.fixtures import FixtureRequest + from _pytest.main import Session + from _pytest.nodes import Item + from _pytest.python import Metafunc from bentoml._internal.server.metrics.prometheus import PrometheusClient diff --git a/src/bentoml/testing/server.py b/src/bentoml/testing/server.py index bb1ddea1978..0cc0adc6644 100644 --- a/src/bentoml/testing/server.py +++ b/src/bentoml/testing/server.py @@ -1,37 +1,37 @@ # pylint: disable=redefined-outer-name,not-context-manager from __future__ import annotations +import asyncio +import contextlib +import itertools +import multiprocessing import os +import socket +import subprocess import sys import time -import socket import typing as t import urllib -import asyncio -import itertools -import contextlib -import subprocess import urllib.error import urllib.request -import multiprocessing -from typing import TYPE_CHECKING from contextlib import contextmanager +from typing import TYPE_CHECKING import psutil -from bentoml.grpc.utils import import_grpc from bentoml._internal.tag import Tag from bentoml._internal.utils import LazyLoader -from bentoml._internal.utils import reserve_free_port from bentoml._internal.utils import cached_contextmanager +from bentoml._internal.utils import reserve_free_port +from bentoml.grpc.utils import import_grpc from ..grpc.utils import LATEST_PROTOCOL_VERSION if TYPE_CHECKING: from grpc import aio from grpc_health.v1 import health_pb2 as pb_health - from starlette.datastructures import Headers from starlette.datastructures import FormData + from starlette.datastructures import Headers from bentoml._internal.bento.bento import Bento diff --git a/src/bentoml/testing/utils.py b/src/bentoml/testing/utils.py index 5ec8157a13a..364ad54d08a 100644 --- a/src/bentoml/testing/utils.py +++ b/src/bentoml/testing/utils.py @@ -7,12 +7,12 @@ import multidict if TYPE_CHECKING: - from starlette.types import Send - from starlette.types import Scope - from starlette.types import Receive from aiohttp.typedefs import LooseHeaders - from starlette.datastructures import Headers from starlette.datastructures import FormData + from starlette.datastructures import Headers + from starlette.types import Receive + from starlette.types import Scope + from starlette.types import Send async def parse_multipart_form(headers: "Headers", body: bytes) -> "FormData": diff --git a/src/bentoml/torchscript.py b/src/bentoml/torchscript.py index be1137cb9e8..50d8e4d4cc5 100644 --- a/src/bentoml/torchscript.py +++ b/src/bentoml/torchscript.py @@ -1,14 +1,14 @@ from __future__ import annotations -import typing as t import logging +import typing as t from typing import TYPE_CHECKING +from ._internal.frameworks.torchscript import ModelOptions from ._internal.frameworks.torchscript import get +from ._internal.frameworks.torchscript import get_runnable from ._internal.frameworks.torchscript import load_model from ._internal.frameworks.torchscript import save_model -from ._internal.frameworks.torchscript import get_runnable -from ._internal.frameworks.torchscript import ModelOptions if TYPE_CHECKING: from ._internal.tag import Tag diff --git a/src/bentoml/transformers.py b/src/bentoml/transformers.py index 4e26cae1828..a096cee8fc7 100644 --- a/src/bentoml/transformers.py +++ b/src/bentoml/transformers.py @@ -1,13 +1,13 @@ from __future__ import annotations -import typing as t import logging +import typing as t +from ._internal.frameworks.transformers import TransformersOptions as ModelOptions from ._internal.frameworks.transformers import get +from ._internal.frameworks.transformers import get_runnable from ._internal.frameworks.transformers import load_model from ._internal.frameworks.transformers import save_model -from ._internal.frameworks.transformers import get_runnable -from ._internal.frameworks.transformers import TransformersOptions as ModelOptions if t.TYPE_CHECKING: from ._internal.tag import Tag diff --git a/src/bentoml/triton.py b/src/bentoml/triton.py index b3a50db410e..0fa7d5200e9 100644 --- a/src/bentoml/triton.py +++ b/src/bentoml/triton.py @@ -1,27 +1,25 @@ from __future__ import annotations -import typing as t import logging - -import attr - +import typing as t from functools import cached_property -from simple_di import inject as _inject +import attr from simple_di import Provide as _Provide +from simple_di import inject as _inject -from ._internal.utils import LazyLoader as _LazyLoader from ._internal.configuration import get_debug_mode as _get_debug_mode -from ._internal.runner.runner import RunnerMethod as _RunnerMethod +from ._internal.configuration.containers import BentoMLContainer as _BentoMLContainer +from ._internal.runner.runnable import RunnableMethodConfig as _RunnableMethodConfig from ._internal.runner.runner import AbstractRunner as _AbstractRunner +from ._internal.runner.runner import RunnerMethod as _RunnerMethod from ._internal.runner.runner import object_setattr as _object_setattr -from ._internal.runner.runnable import RunnableMethodConfig as _RunnableMethodConfig from ._internal.runner.runner_handle import DummyRunnerHandle as _DummyRunnerHandle -from ._internal.configuration.containers import BentoMLContainer as _BentoMLContainer from ._internal.runner.runner_handle.remote import TRITON_EXC_MSG as _TRITON_EXC_MSG from ._internal.runner.runner_handle.remote import ( handle_triton_exception as _handle_triton_exception, ) +from ._internal.utils import LazyLoader as _LazyLoader if t.TYPE_CHECKING: import tritonclient.grpc.aio as _tritongrpcclient diff --git a/src/bentoml/xgboost.py b/src/bentoml/xgboost.py index 15b8fb21d07..c0ad717096a 100644 --- a/src/bentoml/xgboost.py +++ b/src/bentoml/xgboost.py @@ -1,14 +1,14 @@ from __future__ import annotations -import typing as t import logging +import typing as t from typing import TYPE_CHECKING +from ._internal.frameworks.xgboost import XGBoostOptions as ModelOptions from ._internal.frameworks.xgboost import get +from ._internal.frameworks.xgboost import get_runnable from ._internal.frameworks.xgboost import load_model from ._internal.frameworks.xgboost import save_model -from ._internal.frameworks.xgboost import get_runnable -from ._internal.frameworks.xgboost import XGBoostOptions as ModelOptions if TYPE_CHECKING: from ._internal.tag import Tag diff --git a/src/bentoml_cli/bentos.py b/src/bentoml_cli/bentos.py index 686e1ca8da0..bff93b99563 100644 --- a/src/bentoml_cli/bentos.py +++ b/src/bentoml_cli/bentos.py @@ -3,19 +3,19 @@ import json import typing as t -import yaml import click -from simple_di import inject -from simple_di import Provide -from rich.table import Table +import yaml from rich.syntax import Syntax +from rich.table import Table +from simple_di import Provide +from simple_di import inject -from bentoml_cli.utils import is_valid_bento_tag from bentoml_cli.utils import is_valid_bento_name +from bentoml_cli.utils import is_valid_bento_tag if t.TYPE_CHECKING: - from click import Group from click import Context + from click import Group from click import Parameter from bentoml._internal.bento import BentoStore @@ -54,17 +54,17 @@ def parse_delete_targets_argument_callback( def add_bento_management_commands(cli: Group): import bentoml from bentoml import Tag - from bentoml.bentos import import_bento - from bentoml._internal.utils import rich_console as console - from bentoml._internal.utils import calc_dir_size - from bentoml._internal.utils import human_readable_size - from bentoml._internal.utils import resolve_user_filepath - from bentoml._internal.bento.bento import Bento from bentoml._internal.bento.bento import DEFAULT_BENTO_BUILD_FILE - from bentoml._internal.configuration import get_quiet_mode + from bentoml._internal.bento.bento import Bento from bentoml._internal.bento.build_config import BentoBuildConfig + from bentoml._internal.configuration import get_quiet_mode from bentoml._internal.configuration.containers import BentoMLContainer + from bentoml._internal.utils import calc_dir_size + from bentoml._internal.utils import human_readable_size + from bentoml._internal.utils import resolve_user_filepath + from bentoml._internal.utils import rich_console as console from bentoml._internal.utils.analytics.usage_stats import _usage_event_debugging + from bentoml.bentos import import_bento bento_store = BentoMLContainer.bento_store.get() cloud_client = BentoMLContainer.bentocloud_client.get() @@ -318,7 +318,6 @@ def build( # type: ignore (not accessed) """Build a new Bento from current directory.""" if output == "tag": from bentoml._internal.configuration import set_quiet_mode - from bentoml._internal.log import configure_logging set_quiet_mode(True) diff --git a/src/bentoml_cli/cli.py b/src/bentoml_cli/cli.py index 0ae74c0cbf9..f18695f07e0 100644 --- a/src/bentoml_cli/cli.py +++ b/src/bentoml_cli/cli.py @@ -3,15 +3,15 @@ import click import psutil +from bentoml_cli.bentos import add_bento_management_commands +from bentoml_cli.cloud import add_cloud_command +from bentoml_cli.containerize import add_containerize_command +from bentoml_cli.deployment import add_deployment_command from bentoml_cli.env import add_env_command +from bentoml_cli.models import add_model_management_commands from bentoml_cli.serve import add_serve_command from bentoml_cli.start import add_start_command from bentoml_cli.utils import BentoMLCommandGroup -from bentoml_cli.cloud import add_cloud_command -from bentoml_cli.bentos import add_bento_management_commands -from bentoml_cli.models import add_model_management_commands -from bentoml_cli.containerize import add_containerize_command -from bentoml_cli.deployment import add_deployment_command def create_bentoml_cli() -> click.Group: diff --git a/src/bentoml_cli/cloud.py b/src/bentoml_cli/cloud.py index 039d4006ba8..f44bce7a82a 100644 --- a/src/bentoml_cli/cloud.py +++ b/src/bentoml_cli/cloud.py @@ -1,20 +1,21 @@ from __future__ import annotations -import click import json + +import click import click_option_group as cog def add_cloud_command(cli: click.Group) -> click.Group: - from bentoml_cli.utils import BentoMLCommandGroup - from bentoml.exceptions import CLIException - from bentoml._internal.configuration import get_quiet_mode - from bentoml._internal.utils import bentoml_cattr from bentoml._internal.cloud.client import RestApiClient - from bentoml._internal.cloud.config import add_context + from bentoml._internal.cloud.config import CloudClientConfig from bentoml._internal.cloud.config import CloudClientContext + from bentoml._internal.cloud.config import add_context from bentoml._internal.cloud.config import default_context_name - from bentoml._internal.cloud.config import CloudClientConfig + from bentoml._internal.configuration import get_quiet_mode + from bentoml._internal.utils import bentoml_cattr + from bentoml.exceptions import CLIException + from bentoml_cli.utils import BentoMLCommandGroup @cli.group(name="cloud", aliases=["yatai"], cls=BentoMLCommandGroup) def cloud(): diff --git a/src/bentoml_cli/containerize.py b/src/bentoml_cli/containerize.py index 12351cc4593..348afdd1d08 100644 --- a/src/bentoml_cli/containerize.py +++ b/src/bentoml_cli/containerize.py @@ -1,19 +1,19 @@ from __future__ import annotations -import sys -import shutil -import typing as t -import logging -import tempfile import itertools +import logging +import shutil import subprocess -from typing import TYPE_CHECKING +import sys +import tempfile +import typing as t from functools import partial +from typing import TYPE_CHECKING if TYPE_CHECKING: - from click import Group from click import Command from click import Context + from click import Group from click import Parameter from bentoml._internal.container import DefaultBuilder @@ -355,16 +355,16 @@ def add_containerize_command(cli: Group) -> None: from click_option_group import optgroup from bentoml import container - from bentoml_cli.utils import opt_callback - from bentoml_cli.utils import kwargs_transformers - from bentoml_cli.utils import normalize_none_type - from bentoml_cli.utils import validate_container_tag - from bentoml.exceptions import BentoMLException + from bentoml._internal.configuration import get_debug_mode from bentoml._internal.container import FEATURES - from bentoml._internal.container import enable_buildkit from bentoml._internal.container import REGISTERED_BACKENDS from bentoml._internal.container import determine_container_tag - from bentoml._internal.configuration import get_debug_mode + from bentoml._internal.container import enable_buildkit + from bentoml.exceptions import BentoMLException + from bentoml_cli.utils import kwargs_transformers + from bentoml_cli.utils import normalize_none_type + from bentoml_cli.utils import opt_callback + from bentoml_cli.utils import validate_container_tag @cli.command() @click.argument("bento_tag", type=click.STRING, metavar="BENTO:TAG") diff --git a/src/bentoml_cli/deployment.py b/src/bentoml_cli/deployment.py index fb600b754e4..62d72cd6d34 100644 --- a/src/bentoml_cli/deployment.py +++ b/src/bentoml_cli/deployment.py @@ -1,23 +1,27 @@ from __future__ import annotations -import click import typing as t +import click + if t.TYPE_CHECKING: TupleStrAny = tuple[str, ...] - from bentoml._internal.cloud.schemas import DeploymentSchema from bentoml._internal.cloud.schemas import DeploymentListSchema + from bentoml._internal.cloud.schemas import DeploymentSchema else: TupleStrAny = tuple def add_deployment_command(cli: click.Group) -> None: import json - from bentoml_cli.utils import BentoMLCommandGroup - from bentoml._internal.configuration.containers import BentoMLContainer - from bentoml._internal.utils import rich_console as console, bentoml_cattr + from rich.table import Table + from bentoml._internal.configuration.containers import BentoMLContainer + from bentoml._internal.utils import bentoml_cattr + from bentoml._internal.utils import rich_console as console + from bentoml_cli.utils import BentoMLCommandGroup + client = BentoMLContainer.bentocloud_client.get() output_option = click.option( "-o", diff --git a/src/bentoml_cli/env.py b/src/bentoml_cli/env.py index 68b1f6f28ea..4ea2c98e2d3 100644 --- a/src/bentoml_cli/env.py +++ b/src/bentoml_cli/env.py @@ -1,12 +1,12 @@ from __future__ import annotations import os -import sys +import platform import shlex import shutil -import typing as t -import platform import subprocess +import sys +import typing as t from gettext import gettext import click @@ -106,9 +106,9 @@ def pretty_format( def add_env_command(cli: click.Group) -> None: from bentoml import __version__ as BENTOML_VERSION - from bentoml.exceptions import CLIException - from bentoml._internal.utils.pkg import get_pkg_version from bentoml._internal.utils.pkg import PackageNotFoundError + from bentoml._internal.utils.pkg import get_pkg_version + from bentoml.exceptions import CLIException @cli.command(help=gettext("Print environment info and exit")) @click.option( diff --git a/src/bentoml_cli/env_manager.py b/src/bentoml_cli/env_manager.py index bb26fe66dbc..34a246a026c 100644 --- a/src/bentoml_cli/env_manager.py +++ b/src/bentoml_cli/env_manager.py @@ -1,28 +1,28 @@ from __future__ import annotations +import functools +import logging import os import re import sys import typing as t -import logging -import functools from shutil import which -import fs import click -from simple_di import inject +import fs from simple_di import Provide +from simple_di import inject -from bentoml.exceptions import NotFound as BentoNotFound -from bentoml.exceptions import BentoMLException -from bentoml._internal.bento.bento import Bento -from bentoml._internal.bento.bento import BentoStore from bentoml._internal.bento.bento import BENTO_YAML_FILENAME from bentoml._internal.bento.bento import DEFAULT_BENTO_BUILD_FILE -from bentoml._internal.env_manager import EnvManager +from bentoml._internal.bento.bento import Bento +from bentoml._internal.bento.bento import BentoStore from bentoml._internal.configuration import get_debug_mode -from bentoml._internal.env_manager.envs import Environment from bentoml._internal.configuration.containers import BentoMLContainer +from bentoml._internal.env_manager import EnvManager +from bentoml._internal.env_manager.envs import Environment +from bentoml.exceptions import BentoMLException +from bentoml.exceptions import NotFound as BentoNotFound if t.TYPE_CHECKING: P = t.ParamSpec("P") diff --git a/src/bentoml_cli/models.py b/src/bentoml_cli/models.py index 9798f0eefce..b62e4d93398 100644 --- a/src/bentoml_cli/models.py +++ b/src/bentoml_cli/models.py @@ -4,18 +4,18 @@ import typing as t from typing import TYPE_CHECKING -import yaml import click -from rich.table import Table +import yaml from rich.syntax import Syntax +from rich.table import Table -from bentoml_cli.utils import is_valid_bento_tag from bentoml_cli.utils import BentoMLCommandGroup from bentoml_cli.utils import is_valid_bento_name +from bentoml_cli.utils import is_valid_bento_tag if TYPE_CHECKING: - from click import Group from click import Context + from click import Group from click import Parameter @@ -42,15 +42,15 @@ def parse_delete_targets_argument_callback( def add_model_management_commands(cli: Group) -> None: from bentoml import Tag - from bentoml.models import import_model - from bentoml.exceptions import InvalidArgument - from bentoml._internal.utils import rich_console as console - from bentoml._internal.utils import calc_dir_size - from bentoml._internal.utils import human_readable_size - from bentoml._internal.utils import resolve_user_filepath from bentoml._internal.bento.bento import DEFAULT_BENTO_BUILD_FILE from bentoml._internal.bento.build_config import BentoBuildConfig from bentoml._internal.configuration.containers import BentoMLContainer + from bentoml._internal.utils import calc_dir_size + from bentoml._internal.utils import human_readable_size + from bentoml._internal.utils import resolve_user_filepath + from bentoml._internal.utils import rich_console as console + from bentoml.exceptions import InvalidArgument + from bentoml.models import import_model model_store = BentoMLContainer.model_store.get() cloud_client = BentoMLContainer.bentocloud_client.get() diff --git a/src/bentoml_cli/serve.py b/src/bentoml_cli/serve.py index 077bbbf235b..1c0de48fb27 100644 --- a/src/bentoml_cli/serve.py +++ b/src/bentoml_cli/serve.py @@ -1,9 +1,9 @@ from __future__ import annotations +import logging import os import sys import typing as t -import logging import click @@ -47,10 +47,10 @@ def decorator(f: F[t.Any]) -> t.Callable[[F[t.Any]], click.Command]: def add_serve_command(cli: click.Group) -> None: - from bentoml.grpc.utils import LATEST_PROTOCOL_VERSION + from bentoml._internal.configuration.containers import BentoMLContainer from bentoml._internal.log import configure_server_logging + from bentoml.grpc.utils import LATEST_PROTOCOL_VERSION from bentoml_cli.env_manager import env_manager - from bentoml._internal.configuration.containers import BentoMLContainer @cli.command(aliases=["serve-http"]) @click.argument("bento", type=click.STRING, default=".") diff --git a/src/bentoml_cli/start.py b/src/bentoml_cli/start.py index df7c276e01a..b59cd00a18c 100644 --- a/src/bentoml_cli/start.py +++ b/src/bentoml_cli/start.py @@ -1,9 +1,9 @@ from __future__ import annotations -import os -import sys import json import logging +import os +import sys from urllib.parse import urlparse import click @@ -12,9 +12,9 @@ def add_start_command(cli: click.Group) -> None: - from bentoml.grpc.utils import LATEST_PROTOCOL_VERSION - from bentoml._internal.utils import add_experimental_docstring from bentoml._internal.configuration.containers import BentoMLContainer + from bentoml._internal.utils import add_experimental_docstring + from bentoml.grpc.utils import LATEST_PROTOCOL_VERSION @cli.command(hidden=True) @click.argument("bento", type=click.STRING, default=".") diff --git a/src/bentoml_cli/utils.py b/src/bentoml_cli/utils.py index a13098ae044..1a1643a3956 100644 --- a/src/bentoml_cli/utils.py +++ b/src/bentoml_cli/utils.py @@ -1,12 +1,12 @@ from __future__ import annotations +import difflib +import functools +import logging import os import re import time import typing as t -import difflib -import logging -import functools from typing import TYPE_CHECKING import click @@ -14,12 +14,12 @@ from click.exceptions import UsageError if TYPE_CHECKING: - from click import Option from click import Command - from click import Group from click import Context - from click import Parameter + from click import Group from click import HelpFormatter + from click import Option + from click import Parameter P = t.ParamSpec("P") @@ -217,11 +217,11 @@ def serve(): ... @staticmethod def bentoml_common_params(func: F[P]) -> WrappedCLI[bool, bool]: # NOTE: update NUMBER_OF_COMMON_PARAMS when adding option. - from bentoml._internal.log import configure_logging from bentoml._internal.configuration import DEBUG_ENV_VAR from bentoml._internal.configuration import QUIET_ENV_VAR from bentoml._internal.configuration import set_debug_mode from bentoml._internal.configuration import set_quiet_mode + from bentoml._internal.log import configure_logging from bentoml._internal.utils.analytics import BENTOML_DO_NOT_TRACK @click.option( @@ -273,10 +273,10 @@ def bentoml_track_usage( cmd_group: click.Group, **kwargs: t.Any, ) -> WrappedCLI[bool]: - from bentoml._internal.utils.analytics import track + from bentoml._internal.utils.analytics import BENTOML_DO_NOT_TRACK from bentoml._internal.utils.analytics import CliEvent from bentoml._internal.utils.analytics import cli_events_map - from bentoml._internal.utils.analytics import BENTOML_DO_NOT_TRACK + from bentoml._internal.utils.analytics import track command_name = kwargs.get("name", func.__name__) @@ -327,8 +327,8 @@ def get_tracking_event(return_value: t.Any) -> CliEvent: def raise_click_exception( func: F[P] | WrappedCLI[bool], cmd_group: click.Group, **kwargs: t.Any ) -> ClickFunctionWrapper[t.Any]: - from bentoml.exceptions import BentoMLException from bentoml._internal.configuration import get_debug_mode + from bentoml.exceptions import BentoMLException command_name = kwargs.get("name", func.__name__) diff --git a/src/bentoml_cli/worker/grpc_api_server.py b/src/bentoml_cli/worker/grpc_api_server.py index 6bb58d7f886..660e0ba46f4 100644 --- a/src/bentoml_cli/worker/grpc_api_server.py +++ b/src/bentoml_cli/worker/grpc_api_server.py @@ -109,9 +109,9 @@ def main( """ import bentoml - from bentoml._internal.log import configure_server_logging - from bentoml._internal.context import component_context from bentoml._internal.configuration.containers import BentoMLContainer + from bentoml._internal.context import component_context + from bentoml._internal.log import configure_server_logging component_context.component_type = "grpc_api_server" component_context.component_index = worker_id diff --git a/src/bentoml_cli/worker/grpc_prometheus_server.py b/src/bentoml_cli/worker/grpc_prometheus_server.py index 328020b389c..52bce7de69f 100644 --- a/src/bentoml_cli/worker/grpc_prometheus_server.py +++ b/src/bentoml_cli/worker/grpc_prometheus_server.py @@ -51,14 +51,14 @@ def main(fd: int, backlog: int, prometheus_dir: str | None): import psutil import uvicorn - from starlette.middleware import Middleware from starlette.applications import Starlette + from starlette.middleware import Middleware from starlette.middleware.wsgi import WSGIMiddleware # TODO: a2wsgi - from bentoml._internal.log import configure_server_logging - from bentoml._internal.context import component_context from bentoml._internal.configuration import get_debug_mode from bentoml._internal.configuration.containers import BentoMLContainer + from bentoml._internal.context import component_context + from bentoml._internal.log import configure_server_logging component_context.component_type = "prom_server" diff --git a/src/bentoml_cli/worker/http_api_server.py b/src/bentoml_cli/worker/http_api_server.py index c6ec5a84b67..91d667c5ae2 100644 --- a/src/bentoml_cli/worker/http_api_server.py +++ b/src/bentoml_cli/worker/http_api_server.py @@ -114,9 +114,9 @@ def main( import psutil import bentoml - from bentoml._internal.log import configure_server_logging - from bentoml._internal.context import component_context from bentoml._internal.configuration.containers import BentoMLContainer + from bentoml._internal.context import component_context + from bentoml._internal.log import configure_server_logging component_context.component_type = "api_server" component_context.component_index = worker_id diff --git a/src/bentoml_cli/worker/runner.py b/src/bentoml_cli/worker/runner.py index 319d6dbb2d6..7e856593b7a 100644 --- a/src/bentoml_cli/worker/runner.py +++ b/src/bentoml_cli/worker/runner.py @@ -1,8 +1,8 @@ from __future__ import annotations +import json import os import sys -import json import typing as t import click diff --git a/tests/e2e/bento_server_grpc/context_server_interceptor.py b/tests/e2e/bento_server_grpc/context_server_interceptor.py index dd565cfae7a..d1d4633ff8f 100644 --- a/tests/e2e/bento_server_grpc/context_server_interceptor.py +++ b/tests/e2e/bento_server_grpc/context_server_interceptor.py @@ -1,19 +1,19 @@ from __future__ import annotations -import typing as t -import functools import dataclasses +import functools +import typing as t from typing import TYPE_CHECKING from grpc import aio if TYPE_CHECKING: + from bentoml.grpc.types import AsyncHandlerMethod + from bentoml.grpc.types import BentoServicerContext + from bentoml.grpc.types import HandlerCallDetails from bentoml.grpc.types import Request from bentoml.grpc.types import Response from bentoml.grpc.types import RpcMethodHandler - from bentoml.grpc.types import AsyncHandlerMethod - from bentoml.grpc.types import HandlerCallDetails - from bentoml.grpc.types import BentoServicerContext @dataclasses.dataclass diff --git a/tests/e2e/bento_server_grpc/python_model.py b/tests/e2e/bento_server_grpc/python_model.py index 2acf9715e17..25162aec1c8 100644 --- a/tests/e2e/bento_server_grpc/python_model.py +++ b/tests/e2e/bento_server_grpc/python_model.py @@ -1,7 +1,7 @@ from __future__ import annotations -from typing import Any from typing import TYPE_CHECKING +from typing import Any import numpy as np import pandas as pd diff --git a/tests/e2e/bento_server_grpc/service.py b/tests/e2e/bento_server_grpc/service.py index 97e46847624..587f4a39810 100644 --- a/tests/e2e/bento_server_grpc/service.py +++ b/tests/e2e/bento_server_grpc/service.py @@ -4,20 +4,20 @@ import typing as t from typing import TYPE_CHECKING -from pydantic import BaseModel from context_server_interceptor import AsyncContextInterceptor +from pydantic import BaseModel import bentoml -from bentoml.io import File +from bentoml._internal.utils import LazyLoader +from bentoml._internal.utils.metrics import exponential_buckets from bentoml.io import JSON -from bentoml.io import Text +from bentoml.io import File from bentoml.io import Image from bentoml.io import Multipart from bentoml.io import NumpyNdarray -from bentoml.io import PandasSeries from bentoml.io import PandasDataFrame -from bentoml._internal.utils import LazyLoader -from bentoml._internal.utils.metrics import exponential_buckets +from bentoml.io import PandasSeries +from bentoml.io import Text if TYPE_CHECKING: import numpy as np @@ -25,10 +25,10 @@ import PIL.Image from numpy.typing import NDArray + from bentoml._internal.runner.runner import RunnerMethod from bentoml._internal.types import FileLike from bentoml._internal.types import JSONSerializable from bentoml.picklable_model import get_runnable - from bentoml._internal.runner.runner import RunnerMethod RunnableImpl = get_runnable(bentoml.picklable_model.get("py_model.case-1.grpc.e2e")) diff --git a/tests/e2e/bento_server_grpc/tests/conftest.py b/tests/e2e/bento_server_grpc/tests/conftest.py index c5fc7f033df..821faaefabb 100644 --- a/tests/e2e/bento_server_grpc/tests/conftest.py +++ b/tests/e2e/bento_server_grpc/tests/conftest.py @@ -2,9 +2,9 @@ from __future__ import annotations import os +import subprocess import sys import typing as t -import subprocess from typing import TYPE_CHECKING import psutil @@ -13,9 +13,9 @@ if TYPE_CHECKING: from contextlib import ExitStack + from _pytest.config import Config from _pytest.main import Session from _pytest.nodes import Item - from _pytest.config import Config PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) diff --git a/tests/e2e/bento_server_grpc/tests/test_custom_components.py b/tests/e2e/bento_server_grpc/tests/test_custom_components.py index 268e4777888..a149fe55b03 100644 --- a/tests/e2e/bento_server_grpc/tests/test_custom_components.py +++ b/tests/e2e/bento_server_grpc/tests/test_custom_components.py @@ -3,12 +3,12 @@ import typing as t import pytest +from google.protobuf import wrappers_pb2 from grpc import aio from grpc_health.v1 import health_pb2 as pb_health -from google.protobuf import wrappers_pb2 -from bentoml.testing.grpc import create_channel from bentoml.testing.grpc import async_client_call +from bentoml.testing.grpc import create_channel @pytest.mark.asyncio diff --git a/tests/e2e/bento_server_grpc/tests/test_descriptors.py b/tests/e2e/bento_server_grpc/tests/test_descriptors.py index b6ce653b3ef..95b3fabc68f 100644 --- a/tests/e2e/bento_server_grpc/tests/test_descriptors.py +++ b/tests/e2e/bento_server_grpc/tests/test_descriptors.py @@ -3,18 +3,18 @@ import io import random import traceback -from typing import TYPE_CHECKING from functools import partial +from typing import TYPE_CHECKING import pytest -from bentoml.grpc.utils import import_grpc +from bentoml._internal.types import LazyType +from bentoml._internal.utils import LazyLoader from bentoml.grpc.utils import import_generated_stubs -from bentoml.testing.grpc import create_channel +from bentoml.grpc.utils import import_grpc from bentoml.testing.grpc import async_client_call +from bentoml.testing.grpc import create_channel from bentoml.testing.grpc import randomize_pb_ndarray -from bentoml._internal.types import LazyType -from bentoml._internal.utils import LazyLoader if TYPE_CHECKING: import grpc @@ -24,8 +24,8 @@ from google.protobuf import struct_pb2 from google.protobuf import wrappers_pb2 - from bentoml.grpc.v1 import service_pb2 as pb from bentoml._internal import external_typing as ext + from bentoml.grpc.v1 import service_pb2 as pb else: pb, _ = import_generated_stubs() grpc, _ = import_grpc() diff --git a/tests/e2e/bento_server_http/tests/conftest.py b/tests/e2e/bento_server_http/tests/conftest.py index 911e17fc6d5..185b20b97bb 100644 --- a/tests/e2e/bento_server_http/tests/conftest.py +++ b/tests/e2e/bento_server_http/tests/conftest.py @@ -2,9 +2,9 @@ from __future__ import annotations import os +import subprocess import sys import typing as t -import subprocess from typing import TYPE_CHECKING import pytest @@ -12,10 +12,10 @@ if TYPE_CHECKING: from contextlib import ExitStack - from _pytest.main import Session - from _pytest.nodes import Item from _pytest.config import Config from _pytest.fixtures import FixtureRequest as _PytestFixtureRequest + from _pytest.main import Session + from _pytest.nodes import Item class FixtureRequest(_PytestFixtureRequest): param: str diff --git a/tests/e2e/bento_server_http/tests/test_io.py b/tests/e2e/bento_server_http/tests/test_io.py index cdd14f62ce1..7956a74e903 100644 --- a/tests/e2e/bento_server_http/tests/test_io.py +++ b/tests/e2e/bento_server_http/tests/test_io.py @@ -4,9 +4,9 @@ import json from typing import TYPE_CHECKING +import aiohttp import numpy as np import pytest -import aiohttp from bentoml.testing.utils import async_request from bentoml.testing.utils import parse_multipart_form diff --git a/tests/e2e/bento_server_http/tests/test_meta.py b/tests/e2e/bento_server_http/tests/test_meta.py index a244a9712f8..de235071de0 100644 --- a/tests/e2e/bento_server_http/tests/test_meta.py +++ b/tests/e2e/bento_server_http/tests/test_meta.py @@ -2,8 +2,8 @@ from __future__ import annotations -import time import asyncio +import time from pathlib import Path import pytest diff --git a/tests/integration/frameworks/conftest.py b/tests/integration/frameworks/conftest.py index 20f74636a7c..056d8bc12db 100644 --- a/tests/integration/frameworks/conftest.py +++ b/tests/integration/frameworks/conftest.py @@ -1,19 +1,19 @@ from __future__ import annotations -import os -import typing as t import logging +import os import pkgutil +import typing as t +from importlib import import_module from types import ModuleType from typing import TYPE_CHECKING -from importlib import import_module import pytest if TYPE_CHECKING: - from _pytest.nodes import Item from _pytest.config import Config from _pytest.config.argparsing import Parser + from _pytest.nodes import Item from .models import FrameworkTestModel diff --git a/tests/integration/frameworks/mlflow/MNIST/mnist_autolog_example.py b/tests/integration/frameworks/mlflow/MNIST/mnist_autolog_example.py index 5fc70150989..68bd66bfcce 100644 --- a/tests/integration/frameworks/mlflow/MNIST/mnist_autolog_example.py +++ b/tests/integration/frameworks/mlflow/MNIST/mnist_autolog_example.py @@ -8,22 +8,22 @@ # pylint: disable=arguments-differ # pylint: disable=unused-argument # pylint: disable=abstract-method -import os import logging +import os from argparse import ArgumentParser -import torch import mlflow import mlflow.pytorch import pytorch_lightning as pl +import torch +from pytorch_lightning.callbacks import LearningRateMonitor +from pytorch_lightning.callbacks import ModelCheckpoint +from pytorch_lightning.callbacks.early_stopping import EarlyStopping from torch.nn import functional as F -from torchvision import datasets -from torchvision import transforms from torch.utils.data import DataLoader from torch.utils.data import random_split -from pytorch_lightning.callbacks import ModelCheckpoint -from pytorch_lightning.callbacks import LearningRateMonitor -from pytorch_lightning.callbacks.early_stopping import EarlyStopping +from torchvision import datasets +from torchvision import transforms try: from torchmetrics.functional import accuracy diff --git a/tests/integration/frameworks/mlflow/test_apis.py b/tests/integration/frameworks/mlflow/test_apis.py index 54c64195117..da7b45ed5d3 100644 --- a/tests/integration/frameworks/mlflow/test_apis.py +++ b/tests/integration/frameworks/mlflow/test_apis.py @@ -2,22 +2,22 @@ import os import typing as t -from typing import TYPE_CHECKING from pathlib import Path +from typing import TYPE_CHECKING -import numpy as np import mlflow -import pytest import mlflow.models import mlflow.sklearn import mlflow.tracking +import numpy as np +import pytest from sklearn.datasets import load_iris from sklearn.neighbors import KNeighborsClassifier import bentoml -from bentoml.exceptions import NotFound -from bentoml.exceptions import BentoMLException from bentoml._internal.models.model import ModelContext +from bentoml.exceptions import BentoMLException +from bentoml.exceptions import NotFound if TYPE_CHECKING: from sklearn.utils import Bunch diff --git a/tests/integration/frameworks/models/catboost.py b/tests/integration/frameworks/models/catboost.py index 987291ed981..88e8698d83a 100644 --- a/tests/integration/frameworks/models/catboost.py +++ b/tests/integration/frameworks/models/catboost.py @@ -3,16 +3,16 @@ import typing as t from typing import TYPE_CHECKING -from sklearn import metrics from catboost import CatBoostClassifier +from sklearn import metrics from sklearn.datasets import make_classification from sklearn.model_selection import train_test_split import bentoml from . import FrameworkTestModel -from . import FrameworkTestModelInput as Input from . import FrameworkTestModelConfiguration as Config +from . import FrameworkTestModelInput as Input if TYPE_CHECKING: import bentoml._internal.external_typing as ext diff --git a/tests/integration/frameworks/models/detectron.py b/tests/integration/frameworks/models/detectron.py index 543b29303e8..c28b81551c3 100644 --- a/tests/integration/frameworks/models/detectron.py +++ b/tests/integration/frameworks/models/detectron.py @@ -2,21 +2,21 @@ import typing as t -import numpy as np -import torch -import requests import detectron2.config as Cf import detectron2.engine as E -import detectron2.modeling as M import detectron2.model_zoo as Mz -from PIL import Image +import detectron2.modeling as M +import numpy as np +import requests +import torch from detectron2.data import transforms as T +from PIL import Image import bentoml from . import FrameworkTestModel as Model -from . import FrameworkTestModelInput as Input from . import FrameworkTestModelConfiguration as Config +from . import FrameworkTestModelInput as Input if t.TYPE_CHECKING: import torch.nn as nn diff --git a/tests/integration/frameworks/models/diffusers.py b/tests/integration/frameworks/models/diffusers.py index e162c327e7f..6731d2e614b 100644 --- a/tests/integration/frameworks/models/diffusers.py +++ b/tests/integration/frameworks/models/diffusers.py @@ -1,13 +1,13 @@ from __future__ import annotations -import numpy as np import diffusers +import numpy as np import bentoml from . import FrameworkTestModel -from . import FrameworkTestModelInput as Input from . import FrameworkTestModelConfiguration as Config +from . import FrameworkTestModelInput as Input framework = bentoml.diffusers diff --git a/tests/integration/frameworks/models/easyocr.py b/tests/integration/frameworks/models/easyocr.py index 310c5433518..c1cafcb05f7 100644 --- a/tests/integration/frameworks/models/easyocr.py +++ b/tests/integration/frameworks/models/easyocr.py @@ -2,16 +2,16 @@ import typing as t -import numpy as np import easyocr +import numpy as np import requests from PIL import Image import bentoml from . import FrameworkTestModel -from . import FrameworkTestModelInput as Input from . import FrameworkTestModelConfiguration as Config +from . import FrameworkTestModelInput as Input framework = bentoml.easyocr backward_compatible = False diff --git a/tests/integration/frameworks/models/fastai.py b/tests/integration/frameworks/models/fastai.py index 1163e33b83f..77d34e2c386 100644 --- a/tests/integration/frameworks/models/fastai.py +++ b/tests/integration/frameworks/models/fastai.py @@ -6,20 +6,20 @@ import numpy as np import pandas as pd import torch.nn as nn +from fastai.data.block import DataBlock from fastai.learner import Learner from fastai.metrics import accuracy -from sklearn.datasets import load_iris -from fastai.data.block import DataBlock +from fastai.tabular.all import TabularDataLoaders +from fastai.tabular.all import tabular_learner from fastai.torch_core import Module from fastai.torch_core import set_seed -from fastai.tabular.all import tabular_learner -from fastai.tabular.all import TabularDataLoaders +from sklearn.datasets import load_iris import bentoml from . import FrameworkTestModel -from . import FrameworkTestModelInput as Input from . import FrameworkTestModelConfiguration as Config +from . import FrameworkTestModelInput as Input if TYPE_CHECKING: from sklearn.utils import Bunch diff --git a/tests/integration/frameworks/models/flax.py b/tests/integration/frameworks/models/flax.py index eb66360112e..0df5f84411b 100644 --- a/tests/integration/frameworks/models/flax.py +++ b/tests/integration/frameworks/models/flax.py @@ -4,15 +4,15 @@ import chex import jax.numpy as jnp -from jax import random from flax import linen as nn +from jax import random from jax.nn import initializers import bentoml from . import FrameworkTestModel -from . import FrameworkTestModelInput as Input from . import FrameworkTestModelConfiguration as Config +from . import FrameworkTestModelInput as Input framework = bentoml.flax diff --git a/tests/integration/frameworks/models/keras.py b/tests/integration/frameworks/models/keras.py index d90c31c5cb1..910c02443a7 100644 --- a/tests/integration/frameworks/models/keras.py +++ b/tests/integration/frameworks/models/keras.py @@ -4,16 +4,16 @@ from typing import TYPE_CHECKING import keras -import numpy as np -import tensorflow as tf import keras.layers import keras.optimizers +import numpy as np +import tensorflow as tf import bentoml from . import FrameworkTestModel -from . import FrameworkTestModelInput as Input from . import FrameworkTestModelConfiguration as Config +from . import FrameworkTestModelInput as Input if TYPE_CHECKING: from bentoml._internal import external_typing as ext diff --git a/tests/integration/frameworks/models/lightgbm.py b/tests/integration/frameworks/models/lightgbm.py index 716889a1a73..a2f545cc536 100644 --- a/tests/integration/frameworks/models/lightgbm.py +++ b/tests/integration/frameworks/models/lightgbm.py @@ -1,15 +1,15 @@ from __future__ import annotations +import lightgbm as lgb import numpy as np import pandas as pd -import lightgbm as lgb from sklearn.datasets import load_breast_cancer import bentoml from . import FrameworkTestModel -from . import FrameworkTestModelInput as Input from . import FrameworkTestModelConfiguration as Config +from . import FrameworkTestModelInput as Input framework = bentoml.lightgbm diff --git a/tests/integration/frameworks/models/onnx.py b/tests/integration/frameworks/models/onnx.py index 7c6828f957d..f7d4f4197a2 100644 --- a/tests/integration/frameworks/models/onnx.py +++ b/tests/integration/frameworks/models/onnx.py @@ -1,30 +1,30 @@ from __future__ import annotations import os -import typing as t import tempfile +import typing as t from typing import TYPE_CHECKING -import onnx import numpy as np -import torch +import onnx +import onnxruntime as ort import sklearn +import torch import torch.nn as nn -import onnxruntime as ort from skl2onnx import convert_sklearn -from sklearn.datasets import load_iris -from sklearn.ensemble import RandomForestClassifier -from sklearn.preprocessing import LabelEncoder -from sklearn.model_selection import train_test_split from skl2onnx.common.data_types import FloatTensorType from skl2onnx.common.data_types import Int64TensorType from skl2onnx.common.data_types import StringTensorType +from sklearn.datasets import load_iris +from sklearn.ensemble import RandomForestClassifier +from sklearn.model_selection import train_test_split +from sklearn.preprocessing import LabelEncoder import bentoml from . import FrameworkTestModel -from . import FrameworkTestModelInput as Input from . import FrameworkTestModelConfiguration as Config +from . import FrameworkTestModelInput as Input if TYPE_CHECKING: import bentoml._internal.external_typing as ext diff --git a/tests/integration/frameworks/models/picklable_model.py b/tests/integration/frameworks/models/picklable_model.py index ecbbb3b0d79..634990d14f3 100644 --- a/tests/integration/frameworks/models/picklable_model.py +++ b/tests/integration/frameworks/models/picklable_model.py @@ -5,8 +5,8 @@ import bentoml from . import FrameworkTestModel -from . import FrameworkTestModelInput as Input from . import FrameworkTestModelConfiguration as Config +from . import FrameworkTestModelInput as Input framework = bentoml.picklable_model diff --git a/tests/integration/frameworks/models/pytorch.py b/tests/integration/frameworks/models/pytorch.py index dea76bfd219..e0b5d1638b1 100644 --- a/tests/integration/frameworks/models/pytorch.py +++ b/tests/integration/frameworks/models/pytorch.py @@ -9,8 +9,8 @@ import bentoml from . import FrameworkTestModel -from . import FrameworkTestModelInput as Input from . import FrameworkTestModelConfiguration as Config +from . import FrameworkTestModelInput as Input framework = bentoml.pytorch diff --git a/tests/integration/frameworks/models/pytorch_lightning.py b/tests/integration/frameworks/models/pytorch_lightning.py index fe14e08112b..a2aabbe5da3 100644 --- a/tests/integration/frameworks/models/pytorch_lightning.py +++ b/tests/integration/frameworks/models/pytorch_lightning.py @@ -1,16 +1,16 @@ from __future__ import annotations +import pytorch_lightning as pl import torch import torch.nn -import pytorch_lightning as pl import bentoml from . import FrameworkTestModel -from . import FrameworkTestModelInput as Input from . import FrameworkTestModelConfiguration as Config -from .torchscript import test_y +from . import FrameworkTestModelInput as Input from .torchscript import test_x_list +from .torchscript import test_y framework = bentoml.pytorch_lightning diff --git a/tests/integration/frameworks/models/sklearn.py b/tests/integration/frameworks/models/sklearn.py index a7e4a99a1bd..6c5b3a2fe64 100644 --- a/tests/integration/frameworks/models/sklearn.py +++ b/tests/integration/frameworks/models/sklearn.py @@ -10,8 +10,8 @@ import bentoml from . import FrameworkTestModel -from . import FrameworkTestModelInput as Input from . import FrameworkTestModelConfiguration as Config +from . import FrameworkTestModelInput as Input if TYPE_CHECKING: from sklearn.utils import Bunch diff --git a/tests/integration/frameworks/models/tensorflow.py b/tests/integration/frameworks/models/tensorflow.py index c2832b457f7..49ed7942874 100644 --- a/tests/integration/frameworks/models/tensorflow.py +++ b/tests/integration/frameworks/models/tensorflow.py @@ -9,8 +9,8 @@ import bentoml from . import FrameworkTestModel -from . import FrameworkTestModelInput as Input from . import FrameworkTestModelConfiguration as Config +from . import FrameworkTestModelInput as Input if t.TYPE_CHECKING: from bentoml._internal.external_typing import tensorflow as tf_ext diff --git a/tests/integration/frameworks/models/torchscript.py b/tests/integration/frameworks/models/torchscript.py index 086d47896ea..78608719735 100644 --- a/tests/integration/frameworks/models/torchscript.py +++ b/tests/integration/frameworks/models/torchscript.py @@ -1,15 +1,15 @@ from __future__ import annotations import numpy as np -import torch import pandas as pd +import torch import torch.nn import bentoml from . import FrameworkTestModel -from . import FrameworkTestModelInput as Input from . import FrameworkTestModelConfiguration as Config +from . import FrameworkTestModelInput as Input framework = bentoml.torchscript diff --git a/tests/integration/frameworks/models/transformers.py b/tests/integration/frameworks/models/transformers.py index ad5eafd9d8f..b521c97c088 100644 --- a/tests/integration/frameworks/models/transformers.py +++ b/tests/integration/frameworks/models/transformers.py @@ -1,39 +1,39 @@ from __future__ import annotations -import typing as t import importlib +import typing as t import numpy as np import requests import tensorflow as tf import transformers -from PIL import Image from datasets import load_dataset +from PIL import Image from transformers import Pipeline -from transformers.utils import is_tf_available -from transformers.utils import is_torch_available -from transformers.pipelines import get_task from transformers.pipelines import get_supported_tasks +from transformers.pipelines import get_task from transformers.testing_utils import nested_simplify from transformers.trainer_utils import set_seed +from transformers.utils import is_tf_available +from transformers.utils import is_torch_available import bentoml +from bentoml._internal.frameworks.transformers import SimpleDefaultMapping from bentoml._internal.frameworks.transformers import TaskDefinition +from bentoml._internal.frameworks.transformers import convert_to_autoclass from bentoml._internal.frameworks.transformers import delete_pipeline from bentoml._internal.frameworks.transformers import register_pipeline -from bentoml._internal.frameworks.transformers import convert_to_autoclass -from bentoml._internal.frameworks.transformers import SimpleDefaultMapping from . import FrameworkTestModel as Model -from . import FrameworkTestModelInput as Input from . import FrameworkTestModelConfiguration as Config +from . import FrameworkTestModelInput as Input if t.TYPE_CHECKING: import torch from numpy.typing import NDArray - from transformers.utils.generic import ModelOutput from transformers.pipelines.base import GenericTensor from transformers.tokenization_utils_base import BatchEncoding + from transformers.utils.generic import ModelOutput from bentoml._internal.external_typing import transformers as transformers_ext diff --git a/tests/integration/frameworks/models/xgboost.py b/tests/integration/frameworks/models/xgboost.py index 6035f08689b..85a5ef60e26 100644 --- a/tests/integration/frameworks/models/xgboost.py +++ b/tests/integration/frameworks/models/xgboost.py @@ -7,14 +7,14 @@ import numpy as np import pandas as pd import xgboost as xgb -from sklearn.datasets import load_iris from sklearn.datasets import load_breast_cancer +from sklearn.datasets import load_iris import bentoml from . import FrameworkTestModel -from . import FrameworkTestModelInput as Input from . import FrameworkTestModelConfiguration as Config +from . import FrameworkTestModelInput as Input if TYPE_CHECKING: from sklearn.utils import Bunch diff --git a/tests/integration/frameworks/test_fastai_unit.py b/tests/integration/frameworks/test_fastai_unit.py index 28053a03158..d6f8959809b 100644 --- a/tests/integration/frameworks/test_fastai_unit.py +++ b/tests/integration/frameworks/test_fastai_unit.py @@ -1,28 +1,28 @@ from __future__ import annotations +import logging import re import typing as t -import logging from typing import TYPE_CHECKING from unittest.mock import Mock -from unittest.mock import patch from unittest.mock import PropertyMock +from unittest.mock import patch -import torch import pytest -import torch.nn as nn +import torch import torch.functional as F -from fastai.data.core import TfmdDL -from fastai.data.core import Datasets +import torch.nn as nn from fastai.data.core import DataLoaders +from fastai.data.core import Datasets +from fastai.data.core import TfmdDL +from fastai.data.transforms import Transform from fastai.test_utils import synth_learner from fastai.torch_core import Module from fastcore.foundation import L -from fastai.data.transforms import Transform import bentoml -from bentoml.exceptions import InvalidArgument from bentoml.exceptions import BentoMLException +from bentoml.exceptions import InvalidArgument from tests.integration.frameworks.models.fastai import custom_model if TYPE_CHECKING: diff --git a/tests/integration/frameworks/test_frameworks.py b/tests/integration/frameworks/test_frameworks.py index 61b15f505dc..5bdf3a98a7f 100644 --- a/tests/integration/frameworks/test_frameworks.py +++ b/tests/integration/frameworks/test_frameworks.py @@ -1,20 +1,20 @@ from __future__ import annotations +import logging import os import types import typing as t -import logging from typing import TYPE_CHECKING import pytest import bentoml -from bentoml.exceptions import NotFound from bentoml._internal.models.model import ModelContext from bentoml._internal.models.model import ModelSignature from bentoml._internal.runner.runner import Runner -from bentoml._internal.runner.strategy import DefaultStrategy from bentoml._internal.runner.runner_handle.local import LocalRunnerRef +from bentoml._internal.runner.strategy import DefaultStrategy +from bentoml.exceptions import NotFound from .models import FrameworkTestModel @@ -233,9 +233,9 @@ def test_runner_batching( test_model: FrameworkTestModel, saved_model: bentoml.Model, ): + from bentoml._internal.runner.container import AutoContainer from bentoml._internal.runner.utils import Params from bentoml._internal.runner.utils import payload_paramss_to_batch_params - from bentoml._internal.runner.container import AutoContainer ran_tests = False diff --git a/tests/integration/frameworks/test_pytorch_unit.py b/tests/integration/frameworks/test_pytorch_unit.py index c4518a0153c..26284dc03c6 100644 --- a/tests/integration/frameworks/test_pytorch_unit.py +++ b/tests/integration/frameworks/test_pytorch_unit.py @@ -1,10 +1,10 @@ from __future__ import annotations -import torch import pytest +import torch -from bentoml._internal.runner.container import AutoContainer from bentoml._internal.frameworks.pytorch import PyTorchTensorContainer +from bentoml._internal.runner.container import AutoContainer @pytest.mark.parametrize("batch_axis", [0, 1]) diff --git a/tests/integration/frameworks/test_tensorflow_unit.py b/tests/integration/frameworks/test_tensorflow_unit.py index 400dcc67f13..166f5e74517 100644 --- a/tests/integration/frameworks/test_tensorflow_unit.py +++ b/tests/integration/frameworks/test_tensorflow_unit.py @@ -7,9 +7,9 @@ import pytest import tensorflow as tf -from bentoml._internal.types import LazyType from bentoml._internal.runner.container import AutoContainer from bentoml._internal.runner.container import DataContainerRegistry +from bentoml._internal.types import LazyType if TYPE_CHECKING: from bentoml._internal.external_typing import tensorflow as ext diff --git a/tests/integration/frameworks/test_transformers_unit.py b/tests/integration/frameworks/test_transformers_unit.py index f7434459cad..e80814fa410 100644 --- a/tests/integration/frameworks/test_transformers_unit.py +++ b/tests/integration/frameworks/test_transformers_unit.py @@ -1,18 +1,18 @@ from __future__ import annotations +import logging import os import typing as t -import logging import pytest import transformers -from transformers.pipelines import pipeline # type: ignore -from transformers.pipelines import check_task # type: ignore -from transformers.trainer_utils import set_seed -from transformers.models.auto.modeling_auto import AutoModelForCausalLM from transformers.models.auto.modeling_auto import AutoModelForAudioClassification +from transformers.models.auto.modeling_auto import AutoModelForCausalLM from transformers.models.auto.modeling_auto import AutoModelForSequenceClassification +from transformers.pipelines import check_task # type: ignore +from transformers.pipelines import pipeline # type: ignore from transformers.pipelines.audio_classification import AudioClassificationPipeline +from transformers.trainer_utils import set_seed import bentoml from bentoml.exceptions import BentoMLException diff --git a/tests/test_cli_regression.py b/tests/test_cli_regression.py index 9c46d56240c..536d0f46459 100644 --- a/tests/test_cli_regression.py +++ b/tests/test_cli_regression.py @@ -1,7 +1,7 @@ from __future__ import annotations -import time import shlex +import time from click.testing import CliRunner diff --git a/tests/unit/_internal/bento/test_bento.py b/tests/unit/_internal/bento/test_bento.py index ea4df16f9e8..3dcfbee7393 100644 --- a/tests/unit/_internal/bento/test_bento.py +++ b/tests/unit/_internal/bento/test_bento.py @@ -2,10 +2,10 @@ from __future__ import annotations import os -from sys import version_info -from typing import TYPE_CHECKING from datetime import datetime from datetime import timezone +from sys import version_info +from typing import TYPE_CHECKING import fs import pytest @@ -13,13 +13,13 @@ from bentoml import Tag from bentoml import bentos from bentoml._internal.bento import Bento -from bentoml._internal.models import ModelStore -from bentoml._internal.bento.bento import BentoInfo from bentoml._internal.bento.bento import BentoApiInfo +from bentoml._internal.bento.bento import BentoInfo from bentoml._internal.bento.bento import BentoModelInfo from bentoml._internal.bento.bento import BentoRunnerInfo -from bentoml._internal.configuration import BENTOML_VERSION from bentoml._internal.bento.build_config import BentoBuildConfig +from bentoml._internal.configuration import BENTOML_VERSION +from bentoml._internal.models import ModelStore if TYPE_CHECKING: from pathlib import Path diff --git a/tests/unit/_internal/bento/test_service_serialization.py b/tests/unit/_internal/bento/test_service_serialization.py index e7f5500a361..eb43baad0ff 100644 --- a/tests/unit/_internal/bento/test_service_serialization.py +++ b/tests/unit/_internal/bento/test_service_serialization.py @@ -6,13 +6,13 @@ from unittest.mock import ANY from unittest.mock import MagicMock -import pytest import cloudpickle +import pytest import bentoml -from bentoml.exceptions import NotFound -from bentoml._internal.tag import Tag from bentoml._internal.configuration.containers import BentoMLContainer +from bentoml._internal.tag import Tag +from bentoml.exceptions import NotFound from .test_bento import build_test_bento diff --git a/tests/unit/_internal/cloud/test_deployment.py b/tests/unit/_internal/cloud/test_deployment.py index 825bde7e68b..eb68fe6507a 100644 --- a/tests/unit/_internal/cloud/test_deployment.py +++ b/tests/unit/_internal/cloud/test_deployment.py @@ -1,38 +1,38 @@ from __future__ import annotations -from datetime import datetime import typing as t +from datetime import datetime from unittest.mock import patch + +import attr import pytest -from bentoml._internal.cloud.schemas import ( - BentoFullSchema, - BentoImageBuildStatus, - BentoManifestSchema, - BentoRepositorySchema, - BentoUploadStatus, - ClusterSchema, - DeploymentMode, - DeploymentRevisionSchema, - DeploymentRevisionStatus, - DeploymentSchema, - DeploymentStatus, - DeploymentTargetSchema, - ResourceType, -) -from bentoml._internal.cloud.schemas import DeploymentTargetType -from bentoml._internal.cloud.schemas import UpdateDeploymentSchema -from bentoml.cloud import BentoCloudClient -from bentoml.cloud import Resource + +from bentoml._internal.cloud.schemas import BentoFullSchema +from bentoml._internal.cloud.schemas import BentoImageBuildStatus +from bentoml._internal.cloud.schemas import BentoManifestSchema +from bentoml._internal.cloud.schemas import BentoRepositorySchema +from bentoml._internal.cloud.schemas import BentoUploadStatus +from bentoml._internal.cloud.schemas import ClusterSchema from bentoml._internal.cloud.schemas import CreateDeploymentSchema from bentoml._internal.cloud.schemas import CreateDeploymentTargetSchema -from bentoml._internal.cloud.schemas import DeploymentTargetConfig -from bentoml._internal.cloud.schemas import DeploymentTargetRunnerConfig -from bentoml._internal.cloud.schemas import LabelItemSchema +from bentoml._internal.cloud.schemas import DeploymentMode +from bentoml._internal.cloud.schemas import DeploymentRevisionSchema +from bentoml._internal.cloud.schemas import DeploymentRevisionStatus +from bentoml._internal.cloud.schemas import DeploymentSchema +from bentoml._internal.cloud.schemas import DeploymentStatus from bentoml._internal.cloud.schemas import DeploymentTargetCanaryRule from bentoml._internal.cloud.schemas import DeploymentTargetCanaryRuleType +from bentoml._internal.cloud.schemas import DeploymentTargetConfig from bentoml._internal.cloud.schemas import DeploymentTargetHPAConf +from bentoml._internal.cloud.schemas import DeploymentTargetRunnerConfig +from bentoml._internal.cloud.schemas import DeploymentTargetSchema +from bentoml._internal.cloud.schemas import DeploymentTargetType +from bentoml._internal.cloud.schemas import LabelItemSchema +from bentoml._internal.cloud.schemas import ResourceType +from bentoml._internal.cloud.schemas import UpdateDeploymentSchema from bentoml._internal.cloud.schemas import UserSchema -import attr +from bentoml.cloud import BentoCloudClient +from bentoml.cloud import Resource if t.TYPE_CHECKING: from unittest.mock import MagicMock diff --git a/tests/unit/_internal/configuration/test_helpers.py b/tests/unit/_internal/configuration/test_helpers.py index 4de637434e6..e9b908ae48b 100644 --- a/tests/unit/_internal/configuration/test_helpers.py +++ b/tests/unit/_internal/configuration/test_helpers.py @@ -5,11 +5,11 @@ import pytest -from bentoml.exceptions import BentoMLConfigException from bentoml._internal.configuration.helpers import flatten_dict -from bentoml._internal.configuration.helpers import rename_fields -from bentoml._internal.configuration.helpers import load_config_file from bentoml._internal.configuration.helpers import is_valid_ip_address +from bentoml._internal.configuration.helpers import load_config_file +from bentoml._internal.configuration.helpers import rename_fields +from bentoml.exceptions import BentoMLConfigException if TYPE_CHECKING: from pathlib import Path diff --git a/tests/unit/_internal/configuration/test_v1_migration.py b/tests/unit/_internal/configuration/test_v1_migration.py index ad7eae29294..1376462be1b 100644 --- a/tests/unit/_internal/configuration/test_v1_migration.py +++ b/tests/unit/_internal/configuration/test_v1_migration.py @@ -1,7 +1,7 @@ from __future__ import annotations -import typing as t import logging +import typing as t from typing import TYPE_CHECKING import pytest diff --git a/tests/unit/_internal/io/test_custom.py b/tests/unit/_internal/io/test_custom.py index 856f688c655..997aebe1903 100644 --- a/tests/unit/_internal/io/test_custom.py +++ b/tests/unit/_internal/io/test_custom.py @@ -7,12 +7,12 @@ from starlette.responses import Response import bentoml -from bentoml.io import IODescriptor -from bentoml.exceptions import BentoMLException -from bentoml._internal.utils.http import set_cookies from bentoml._internal.service.openapi import SUCCESS_DESCRIPTION -from bentoml._internal.service.openapi.specification import Schema from bentoml._internal.service.openapi.specification import MediaType +from bentoml._internal.service.openapi.specification import Schema +from bentoml._internal.utils.http import set_cookies +from bentoml.exceptions import BentoMLException +from bentoml.io import IODescriptor if TYPE_CHECKING: from google.protobuf import wrappers_pb2 diff --git a/tests/unit/_internal/io/test_file.py b/tests/unit/_internal/io/test_file.py index aa2550388a4..bccab01f999 100644 --- a/tests/unit/_internal/io/test_file.py +++ b/tests/unit/_internal/io/test_file.py @@ -5,9 +5,9 @@ import pytest -from bentoml.io import File from bentoml.exceptions import BadInput from bentoml.grpc.utils import import_generated_stubs +from bentoml.io import File if TYPE_CHECKING: from bentoml.grpc.v1 import service_pb2 as pb diff --git a/tests/unit/_internal/io/test_image.py b/tests/unit/_internal/io/test_image.py index b14acb46801..6d8c96b3475 100644 --- a/tests/unit/_internal/io/test_image.py +++ b/tests/unit/_internal/io/test_image.py @@ -5,11 +5,11 @@ import pytest -from bentoml.io import Image +from bentoml._internal.utils import LazyLoader from bentoml.exceptions import BadInput from bentoml.exceptions import InvalidArgument from bentoml.grpc.utils import import_generated_stubs -from bentoml._internal.utils import LazyLoader +from bentoml.io import Image if TYPE_CHECKING: import numpy as np diff --git a/tests/unit/_internal/io/test_json.py b/tests/unit/_internal/io/test_json.py index 63365d84480..fd087c1ff41 100644 --- a/tests/unit/_internal/io/test_json.py +++ b/tests/unit/_internal/io/test_json.py @@ -1,31 +1,31 @@ from __future__ import annotations -import json -import typing as t import asyncio +import json import logging -from typing import TYPE_CHECKING -from functools import partial +import typing as t from dataclasses import dataclass +from functools import partial +from typing import TYPE_CHECKING import attr import numpy as np import pandas as pd -import pytest import pydantic +import pytest -from bentoml.io import JSON +from bentoml._internal.io_descriptors.json import DefaultJsonEncoder +from bentoml._internal.utils import LazyLoader from bentoml.exceptions import BadInput from bentoml.grpc.utils import import_generated_stubs -from bentoml._internal.utils import LazyLoader -from bentoml._internal.io_descriptors.json import DefaultJsonEncoder +from bentoml.io import JSON if TYPE_CHECKING: from _pytest.logging import LogCaptureFixture from google.protobuf import struct_pb2 - from bentoml.grpc.v1 import service_pb2 as pb from bentoml._internal.service.openapi.specification import Schema + from bentoml.grpc.v1 import service_pb2 as pb else: pb, _ = import_generated_stubs() struct_pb2 = LazyLoader("struct_pb2", globals(), "google.protobuf.struct_pb2") diff --git a/tests/unit/_internal/io/test_multipart.py b/tests/unit/_internal/io/test_multipart.py index 2ada31b2039..7055f92a383 100644 --- a/tests/unit/_internal/io/test_multipart.py +++ b/tests/unit/_internal/io/test_multipart.py @@ -5,12 +5,12 @@ import pytest +from bentoml._internal.utils import LazyLoader +from bentoml.exceptions import InvalidArgument +from bentoml.grpc.utils import import_generated_stubs from bentoml.io import JSON from bentoml.io import Image from bentoml.io import Multipart -from bentoml.exceptions import InvalidArgument -from bentoml.grpc.utils import import_generated_stubs -from bentoml._internal.utils import LazyLoader example = Multipart(arg1=JSON(), arg2=Image(mime_type="image/bmp", pilmode="RGB")) diff --git a/tests/unit/_internal/io/test_numpy.py b/tests/unit/_internal/io/test_numpy.py index 5a9ef333fbd..b21a3d17f17 100644 --- a/tests/unit/_internal/io/test_numpy.py +++ b/tests/unit/_internal/io/test_numpy.py @@ -2,17 +2,17 @@ from __future__ import annotations import logging -from typing import TYPE_CHECKING from functools import partial +from typing import TYPE_CHECKING import numpy as np import pytest -from bentoml.io import NumpyNdarray +from bentoml._internal.service.openapi.specification import Schema from bentoml.exceptions import BadInput from bentoml.exceptions import BentoMLException from bentoml.grpc.utils import import_generated_stubs -from bentoml._internal.service.openapi.specification import Schema +from bentoml.io import NumpyNdarray if TYPE_CHECKING: from _pytest.logging import LogCaptureFixture diff --git a/tests/unit/_internal/io/test_text.py b/tests/unit/_internal/io/test_text.py index 6a698787f14..64cffc6c954 100644 --- a/tests/unit/_internal/io/test_text.py +++ b/tests/unit/_internal/io/test_text.py @@ -4,10 +4,10 @@ import pytest -from bentoml.io import Text +from bentoml._internal.utils import LazyLoader from bentoml.exceptions import BentoMLException from bentoml.grpc.utils import import_generated_stubs -from bentoml._internal.utils import LazyLoader +from bentoml.io import Text if TYPE_CHECKING: from google.protobuf import wrappers_pb2 diff --git a/tests/unit/_internal/models/test_model.py b/tests/unit/_internal/models/test_model.py index 843046a2414..047c74810c8 100644 --- a/tests/unit/_internal/models/test_model.py +++ b/tests/unit/_internal/models/test_model.py @@ -1,25 +1,25 @@ from __future__ import annotations import os -from sys import version_info as pyver -from typing import TYPE_CHECKING from datetime import datetime from datetime import timezone +from sys import version_info as pyver +from typing import TYPE_CHECKING -import fs import attr +import fs +import fs.errors import numpy as np import pytest -import fs.errors from bentoml import Tag -from bentoml.exceptions import BentoMLException -from bentoml.testing.pytest import TEST_MODEL_CONTEXT +from bentoml._internal.configuration import BENTOML_VERSION from bentoml._internal.models import ModelOptions as InternalModelOptions from bentoml._internal.models.model import Model from bentoml._internal.models.model import ModelInfo from bentoml._internal.models.model import ModelStore -from bentoml._internal.configuration import BENTOML_VERSION +from bentoml.exceptions import BentoMLException +from bentoml.testing.pytest import TEST_MODEL_CONTEXT if TYPE_CHECKING: from pathlib import Path diff --git a/tests/unit/_internal/service_loader/bento_with_models/service.py b/tests/unit/_internal/service_loader/bento_with_models/service.py index 808e3cf85d7..83a991babb5 100644 --- a/tests/unit/_internal/service_loader/bento_with_models/service.py +++ b/tests/unit/_internal/service_loader/bento_with_models/service.py @@ -1,6 +1,5 @@ import bentoml - test_model = bentoml.models.get("testmodel") # get by alias another_model = bentoml.models.get("another") diff --git a/tests/unit/_internal/service_loader/test_import_service.py b/tests/unit/_internal/service_loader/test_import_service.py index b7ed6a8f310..fdebd0dd090 100644 --- a/tests/unit/_internal/service_loader/test_import_service.py +++ b/tests/unit/_internal/service_loader/test_import_service.py @@ -1,7 +1,7 @@ import pytest -from bentoml.exceptions import ImportServiceError from bentoml._internal.service.loader import import_service +from bentoml.exceptions import ImportServiceError @pytest.mark.usefixtures("change_test_dir") diff --git a/tests/unit/_internal/service_loader/test_service_loader.py b/tests/unit/_internal/service_loader/test_service_loader.py index 6334072981d..2ac50795191 100644 --- a/tests/unit/_internal/service_loader/test_service_loader.py +++ b/tests/unit/_internal/service_loader/test_service_loader.py @@ -1,9 +1,10 @@ -import pytest import sys -from bentoml._internal.service.loader import load +import pytest + from bentoml._internal.bento import Bento from bentoml._internal.bento.build_config import BentoBuildConfig +from bentoml._internal.service.loader import load @pytest.mark.usefixtures("change_test_dir", "model_store") diff --git a/tests/unit/_internal/test_resource.py b/tests/unit/_internal/test_resource.py index d5214e35c68..0fb2a2110cc 100644 --- a/tests/unit/_internal/test_resource.py +++ b/tests/unit/_internal/test_resource.py @@ -4,12 +4,12 @@ import bentoml import bentoml.exceptions -from bentoml.exceptions import BentoMLConfigException -from bentoml._internal.resource import Resource from bentoml._internal.resource import CpuResource +from bentoml._internal.resource import NvidiaGpuResource +from bentoml._internal.resource import Resource from bentoml._internal.resource import get_resource from bentoml._internal.resource import system_resources -from bentoml._internal.resource import NvidiaGpuResource +from bentoml.exceptions import BentoMLConfigException class DummyResource(Resource[str], resource_id="dummy"): diff --git a/tests/unit/_internal/test_service_api.py b/tests/unit/_internal/test_service_api.py index d17e146bd2c..001cf50a379 100644 --- a/tests/unit/_internal/test_service_api.py +++ b/tests/unit/_internal/test_service_api.py @@ -9,8 +9,8 @@ import pytest import bentoml -from bentoml.io import Text from bentoml.exceptions import BentoMLException +from bentoml.io import Text if TYPE_CHECKING: from _pytest.logging import LogCaptureFixture diff --git a/tests/unit/_internal/test_store.py b/tests/unit/_internal/test_store.py index 05b6cbc0663..d82ffa81e9c 100644 --- a/tests/unit/_internal/test_store.py +++ b/tests/unit/_internal/test_store.py @@ -2,18 +2,18 @@ import sys import time import typing as t -from typing import TYPE_CHECKING from datetime import datetime +from typing import TYPE_CHECKING -import fs import attr +import fs import pytest from bentoml import Tag -from bentoml.exceptions import NotFound -from bentoml.exceptions import BentoMLException from bentoml._internal.store import Store from bentoml._internal.store import StoreItem +from bentoml.exceptions import BentoMLException +from bentoml.exceptions import NotFound if sys.version_info < (3, 7): from backports.datetime_fromisoformat import MonkeyPatch diff --git a/tests/unit/_internal/utils/circus/test_watchfilesplugin.py b/tests/unit/_internal/utils/circus/test_watchfilesplugin.py index c5af4d58880..0420e6150f2 100644 --- a/tests/unit/_internal/utils/circus/test_watchfilesplugin.py +++ b/tests/unit/_internal/utils/circus/test_watchfilesplugin.py @@ -1,18 +1,18 @@ from __future__ import annotations +import logging import os import typing as t -import logging -from typing import TYPE_CHECKING from pathlib import Path +from typing import TYPE_CHECKING from unittest import skipUnless from unittest.mock import patch import pytest from circus.tests.support import TestCircus -from bentoml._internal.utils.pkg import source_locations from bentoml._internal.utils.circus.watchfilesplugin import ServiceReloaderPlugin +from bentoml._internal.utils.pkg import source_locations if TYPE_CHECKING: from unittest import TestCase diff --git a/tests/unit/_internal/utils/test_analytics.py b/tests/unit/_internal/utils/test_analytics.py index b8353ab5de9..01fc2718457 100644 --- a/tests/unit/_internal/utils/test_analytics.py +++ b/tests/unit/_internal/utils/test_analytics.py @@ -4,13 +4,16 @@ import logging import typing as t from typing import TYPE_CHECKING -from unittest.mock import Mock, patch +from unittest.mock import Mock +from unittest.mock import patch import pytest -from prometheus_client.parser import ( - text_string_to_metric_families, -) # type: ignore (no prometheus types) -from schema import And, Or, Schema +from prometheus_client.parser import text_string_to_metric_families + +# type: ignore (no prometheus types) +from schema import And +from schema import Or +from schema import Schema import bentoml from bentoml._internal.utils import analytics diff --git a/tests/unit/_internal/utils/test_metrics.py b/tests/unit/_internal/utils/test_metrics.py index ed480a7a15e..a1adbef5717 100644 --- a/tests/unit/_internal/utils/test_metrics.py +++ b/tests/unit/_internal/utils/test_metrics.py @@ -3,9 +3,9 @@ import math from bentoml._internal.utils.metrics import INF -from bentoml._internal.utils.metrics import metric_name -from bentoml._internal.utils.metrics import linear_buckets from bentoml._internal.utils.metrics import exponential_buckets +from bentoml._internal.utils.metrics import linear_buckets +from bentoml._internal.utils.metrics import metric_name def _assert_equal(actual: tuple[float, ...], expected: tuple[float, ...]): diff --git a/tests/unit/bentoml_cli/test_env_manager.py b/tests/unit/bentoml_cli/test_env_manager.py index fdb166e6f66..b6b1f9dd248 100644 --- a/tests/unit/bentoml_cli/test_env_manager.py +++ b/tests/unit/bentoml_cli/test_env_manager.py @@ -1,7 +1,6 @@ from __future__ import annotations import pytest - from bentoml_cli.env_manager import remove_env_arg testdata = [ diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index f8f38a74b64..467371498c0 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -1,13 +1,13 @@ # pylint: disable=unused-argument from __future__ import annotations -import typing as t import logging +import typing as t from typing import TYPE_CHECKING -import yaml -import pytest import cloudpickle +import pytest +import yaml import bentoml from bentoml.testing.pytest import TEST_MODEL_CONTEXT @@ -42,8 +42,8 @@ def reload_directory( ├── service.py └── train.py """ - from bentoml._internal.utils import bentoml_cattr from bentoml._internal.bento.build_config import BentoBuildConfig + from bentoml._internal.utils import bentoml_cattr root = tmp_path_factory.mktemp("reload_directory") # create a models directory diff --git a/tests/unit/grpc/interceptors/test_access.py b/tests/unit/grpc/interceptors/test_access.py index 3c47fc6664f..dc80b49b20b 100644 --- a/tests/unit/grpc/interceptors/test_access.py +++ b/tests/unit/grpc/interceptors/test_access.py @@ -1,40 +1,40 @@ # pylint: disable=unused-argument from __future__ import annotations -import typing as t -import logging import functools +import logging +import typing as t from typing import TYPE_CHECKING import pytest -from tests.proto import service_test_pb2 as pb_test -from tests.proto import service_test_pb2_grpc as services_test +from bentoml._internal.utils import LazyLoader +from bentoml.grpc.interceptors.access import AccessLogServerInterceptor +from bentoml.grpc.interceptors.opentelemetry import AsyncOpenTelemetryServerInterceptor +from bentoml.grpc.utils import import_generated_stubs from bentoml.grpc.utils import import_grpc from bentoml.grpc.utils import wrap_rpc_handler -from bentoml.grpc.utils import import_generated_stubs -from bentoml.testing.grpc import create_channel from bentoml.testing.grpc import async_client_call -from bentoml.testing.grpc import make_standalone_server +from bentoml.testing.grpc import create_channel from bentoml.testing.grpc import create_test_bento_servicer -from bentoml._internal.utils import LazyLoader +from bentoml.testing.grpc import make_standalone_server +from tests.proto import service_test_pb2 as pb_test +from tests.proto import service_test_pb2_grpc as services_test from tests.unit.grpc.conftest import TestServiceServicer -from bentoml.grpc.interceptors.access import AccessLogServerInterceptor -from bentoml.grpc.interceptors.opentelemetry import AsyncOpenTelemetryServerInterceptor if TYPE_CHECKING: import grpc - from grpc import aio from _pytest.logging import LogCaptureFixture from google.protobuf import wrappers_pb2 + from grpc import aio from bentoml import Service + from bentoml.grpc.types import AsyncHandlerMethod + from bentoml.grpc.types import BentoServicerContext + from bentoml.grpc.types import HandlerCallDetails from bentoml.grpc.types import Request from bentoml.grpc.types import Response from bentoml.grpc.types import RpcMethodHandler - from bentoml.grpc.types import AsyncHandlerMethod - from bentoml.grpc.types import HandlerCallDetails - from bentoml.grpc.types import BentoServicerContext else: grpc, aio = import_grpc() wrappers_pb2 = LazyLoader("wrappers_pb2", globals(), "google.protobuf.wrappers_pb2") diff --git a/tests/unit/grpc/interceptors/test_prometheus.py b/tests/unit/grpc/interceptors/test_prometheus.py index 26da32d70c6..3bda7812bec 100644 --- a/tests/unit/grpc/interceptors/test_prometheus.py +++ b/tests/unit/grpc/interceptors/test_prometheus.py @@ -1,26 +1,26 @@ from __future__ import annotations import sys -import typing as t import tempfile -from typing import TYPE_CHECKING +import typing as t from asyncio import Future +from typing import TYPE_CHECKING from unittest.mock import MagicMock import pytest -from tests.proto import service_test_pb2 as pb_test -from tests.proto import service_test_pb2_grpc as services_test -from bentoml.grpc.utils import import_grpc +from bentoml._internal.configuration.containers import BentoMLContainer +from bentoml._internal.utils import LazyLoader +from bentoml.grpc.interceptors.prometheus import PrometheusServerInterceptor from bentoml.grpc.utils import import_generated_stubs -from bentoml.testing.grpc import create_channel +from bentoml.grpc.utils import import_grpc from bentoml.testing.grpc import async_client_call -from bentoml.testing.grpc import make_standalone_server +from bentoml.testing.grpc import create_channel from bentoml.testing.grpc import create_test_bento_servicer -from bentoml._internal.utils import LazyLoader +from bentoml.testing.grpc import make_standalone_server +from tests.proto import service_test_pb2 as pb_test +from tests.proto import service_test_pb2_grpc as services_test from tests.unit.grpc.conftest import TestServiceServicer -from bentoml.grpc.interceptors.prometheus import PrometheusServerInterceptor -from bentoml._internal.configuration.containers import BentoMLContainer if TYPE_CHECKING: import grpc diff --git a/tests/unit/grpc/test_grpc_utils.py b/tests/unit/grpc/test_grpc_utils.py index 6ea89191d2b..730373e6bc0 100644 --- a/tests/unit/grpc/test_grpc_utils.py +++ b/tests/unit/grpc/test_grpc_utils.py @@ -8,13 +8,13 @@ import pytest from bentoml.exceptions import BadInput -from bentoml.exceptions import InvalidArgument from bentoml.exceptions import BentoMLException +from bentoml.exceptions import InvalidArgument from bentoml.grpc.utils import MethodName -from bentoml.grpc.utils import to_http_status from bentoml.grpc.utils import grpc_status_code -from bentoml.grpc.utils import wrap_rpc_handler from bentoml.grpc.utils import parse_method_name +from bentoml.grpc.utils import to_http_status +from bentoml.grpc.utils import wrap_rpc_handler @pytest.mark.parametrize( diff --git a/tests/unit/test_models.py b/tests/unit/test_models.py index 36c81695308..96397258431 100644 --- a/tests/unit/test_models.py +++ b/tests/unit/test_models.py @@ -1,18 +1,17 @@ +import importlib.metadata import os -import time import random import string +import time from sys import version_info as pyver from typing import TYPE_CHECKING -import importlib.metadata - import pytest import bentoml -from bentoml.exceptions import NotFound -from bentoml._internal.models import ModelStore from bentoml._internal.models import ModelContext +from bentoml._internal.models import ModelStore +from bentoml.exceptions import NotFound if TYPE_CHECKING: from pathlib import Path