Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable isort #327

Merged
merged 11 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ lint.select = [
"F", # see: https://pypi.org/project/pyflakes
"N", # see: https://pypi.org/project/pep8-naming
# "D", # see: https://pypi.org/project/pydocstyle
"I", # implementation for isort
]
lint.extend-select = [
"C4", # see: https://pypi.org/project/flake8-comprehensions
Expand All @@ -108,7 +109,6 @@ exclude = [
"dist",
"docs"
]
lint.ignore-init-module-imports = true

[tool.ruff.lint.per-file-ignores]
"setup.py" = ["D100", "SIM115"]
Expand Down
8 changes: 4 additions & 4 deletions src/litserve/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from litserve import test_examples
from litserve.__about__ import * # noqa: F403
from litserve.api import LitAPI
from litserve.server import LitServer, Request, Response
from litserve import test_examples
from litserve.specs.openai import OpenAISpec
from litserve.callbacks import Callback
from litserve.loggers import Logger
from litserve.server import LitServer, Request, Response
from litserve.specs.openai import OpenAISpec

__all__ = ["LitAPI", "LitServer", "Request", "Response", "test_examples", "OpenAISpec", "Callback", "Logger"]
__all__ = ["LitAPI", "LitServer", "Request", "Response", "OpenAISpec", "test_examples", "Callback", "Logger"]
3 changes: 2 additions & 1 deletion src/litserve/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter, RawTextHelpFormatter
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser, RawTextHelpFormatter

from litserve.docker_builder import dockerize


Expand Down
2 changes: 1 addition & 1 deletion src/litserve/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import json
import warnings
from abc import ABC, abstractmethod
from typing import Optional
from queue import Queue
from typing import Optional

from pydantic import BaseModel

Expand Down
2 changes: 1 addition & 1 deletion src/litserve/callbacks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .base import Callback, CallbackRunner, EventTypes, NoopCallback
from litserve.callbacks.base import Callback, CallbackRunner, EventTypes, NoopCallback

__all__ = ["Callback", "CallbackRunner", "EventTypes", "NoopCallback"]
2 changes: 1 addition & 1 deletion src/litserve/callbacks/defaults/metric_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import typing
from logging import getLogger

from ..base import Callback
from litserve.callbacks.base import Callback

if typing.TYPE_CHECKING:
from litserve import LitAPI
Expand Down
2 changes: 1 addition & 1 deletion src/litserve/docker_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
# limitations under the License.
import logging
import os
import warnings
from pathlib import Path

import warnings
import litserve as ls

logger = logging.getLogger(__name__)
Expand Down
4 changes: 2 additions & 2 deletions src/litserve/loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import functools
import logging
import multiprocessing as mp
import pickle
from abc import ABC, abstractmethod
from typing import List, Optional, Union, TYPE_CHECKING
from typing import TYPE_CHECKING, List, Optional, Union

from starlette.types import ASGIApp
import logging

module_logger = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions src/litserve/specs/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from fastapi.responses import StreamingResponse
from pydantic import BaseModel, Field

from ..utils import LitAPIStatus, azip, load_and_raise
from .base import LitSpec
from litserve.specs.base import LitSpec
from litserve.utils import LitAPIStatus, azip, load_and_raise

if typing.TYPE_CHECKING:
from litserve import LitServer
Expand Down
6 changes: 3 additions & 3 deletions src/litserve/test_examples/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from .simple_example import SimpleBatchedAPI, SimpleLitAPI, SimpleTorchAPI, SimpleStreamAPI
from .openai_spec_example import (
from litserve.test_examples.openai_spec_example import (
OpenAIBatchContext,
TestAPI,
TestAPIWithCustomEncode,
TestAPIWithStructuredOutput,
TestAPIWithToolCalls,
OpenAIBatchContext,
)
from litserve.test_examples.simple_example import SimpleBatchedAPI, SimpleLitAPI, SimpleStreamAPI, SimpleTorchAPI

__all__ = [
"SimpleLitAPI",
Expand Down
10 changes: 5 additions & 5 deletions src/litserve/test_examples/openai_spec_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
# limitations under the License.
import time

import litserve as ls
from litserve.api import LitAPI
from litserve.specs.openai import ChatMessage


class TestAPI(ls.LitAPI):
class TestAPI(LitAPI):
def setup(self, device):
self.model = None

Expand Down Expand Up @@ -53,7 +53,7 @@ def encode_response(self, output):
)


class OpenAIBatchContext(ls.LitAPI):
class OpenAIBatchContext(LitAPI):
def setup(self, device: str) -> None:
self.model = None

Expand Down Expand Up @@ -82,7 +82,7 @@ def encode_response(self, output_stream, context):
assert ctx["temperature"] == 1.0, f"context {ctx} is not 1.0"


class OpenAIWithUsage(ls.LitAPI):
class OpenAIWithUsage(LitAPI):
def setup(self, device):
self.model = None

Expand All @@ -96,7 +96,7 @@ def predict(self, x):
}


class OpenAIWithUsageEncodeResponse(ls.LitAPI):
class OpenAIWithUsageEncodeResponse(LitAPI):
def setup(self, device):
self.model = None

Expand Down
10 changes: 5 additions & 5 deletions src/litserve/test_examples/simple_example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import litserve as ls
from litserve.api import LitAPI


class SimpleLitAPI(ls.LitAPI):
class SimpleLitAPI(LitAPI):
def setup(self, device):
# Set up the model, so it can be called in `predict`.
self.model = lambda x: x**2
Expand All @@ -19,7 +19,7 @@ def encode_response(self, output):
return {"output": output}


class SimpleBatchedAPI(ls.LitAPI):
class SimpleBatchedAPI(LitAPI):
def setup(self, device) -> None:
self.model = lambda x: x**2

Expand All @@ -35,7 +35,7 @@ def encode_response(self, output):
return {"output": output}


class SimpleTorchAPI(ls.LitAPI):
class SimpleTorchAPI(LitAPI):
def setup(self, device):
# move the model to the correct device
# keep track of the device for moving data accordingly
Expand Down Expand Up @@ -69,7 +69,7 @@ def encode_response(self, output):
return {"output": float(output)}


class SimpleStreamAPI(ls.LitAPI):
class SimpleStreamAPI(LitAPI):
"""
Run as:
```
Expand Down
1 change: 0 additions & 1 deletion src/litserve/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

from fastapi import HTTPException


if TYPE_CHECKING:
from litserve.server import LitServer

Expand Down
9 changes: 5 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import time
import psutil
from typing import Generator

from litserve.server import LitServer
import psutil
import pytest
from litserve.api import LitAPI
from litserve.utils import wrap_litserve_start
from fastapi import Request, Response
from fastapi.testclient import TestClient

from litserve.api import LitAPI
from litserve.server import LitServer
from litserve.utils import wrap_litserve_start


class SimpleLitAPI(LitAPI):
def setup(self, device):
Expand Down
3 changes: 1 addition & 2 deletions tests/e2e/default_openai_with_batching.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from litserve.test_examples.openai_spec_example import OpenAIBatchContext

import litserve as ls
from litserve.test_examples.openai_spec_example import OpenAIBatchContext

if __name__ == "__main__":
api = OpenAIBatchContext()
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/default_openaispec.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import litserve as ls
from litserve import OpenAISpec
from litserve.test_examples.openai_spec_example import TestAPI
import litserve as ls

if __name__ == "__main__":
server = ls.LitServer(TestAPI(), spec=OpenAISpec())
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/default_openaispec_tools.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import litserve as ls
from litserve import OpenAISpec
from litserve.test_examples.openai_spec_example import TestAPI
from litserve.specs.openai import ChatMessage
from litserve.test_examples.openai_spec_example import TestAPI


class TestAPIWithToolCalls(TestAPI):
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/default_single_streaming.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from litserve import LitServer, LitAPI
from litserve import LitAPI, LitServer


class SimpleStreamingAPI(LitAPI):
Expand Down
5 changes: 2 additions & 3 deletions tests/e2e/default_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from litserve.test_examples.openai_spec_example import TestAPI
from litserve.specs.openai import OpenAISpec

import litserve as ls
from litserve.specs.openai import OpenAISpec
from litserve.test_examples.openai_spec_example import TestAPI

if __name__ == "__main__":
server = ls.LitServer(TestAPI(), spec=OpenAISpec())
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
# limitations under the License.
import json
import os
import psutil
import requests
import subprocess
import time
from functools import wraps

import psutil
import requests
from openai import OpenAI
from functools import wraps


def e2e_from_file(filename):
Expand Down
5 changes: 3 additions & 2 deletions tests/minimal_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import subprocess
import psutil
import time
import json
import urllib.request

import psutil


def main():
process = subprocess.Popen(
Expand Down
2 changes: 1 addition & 1 deletion tests/parity_fastapi/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import random
import time

import numpy as np
import requests
import torch
from PIL import Image
import numpy as np

device = "cuda" if torch.cuda.is_available() else "cpu"
device = "mps" if torch.backends.mps.is_available() else device
Expand Down
1 change: 0 additions & 1 deletion tests/parity_fastapi/ls-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import litserve as ls


device = "cuda" if torch.cuda.is_available() else "cpu"
device = "mps" if torch.backends.mps.is_available() else device
conf = {
Expand Down
11 changes: 5 additions & 6 deletions tests/parity_fastapi/main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import torch
import requests

from benchmark import run_bench
import psutil
import subprocess
import time

from functools import wraps

import psutil
import requests
import torch
from benchmark import run_bench

CONF = {
"cpu": {"num_requests": 50},
"mps": {"num_requests": 50},
Expand Down
4 changes: 2 additions & 2 deletions tests/perf_test/bert/benchmark.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import time
import logging
import time

import requests
from utils import benchmark
from tenacity import retry, stop_after_attempt
from utils import benchmark

# Configuration
SERVER_URL = "http://0.0.0.0:8000/predict"
Expand Down
1 change: 1 addition & 0 deletions tests/perf_test/bert/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import torch
from jsonargparse import CLI
from transformers import AutoModelForSequenceClassification, AutoTokenizer, BertConfig

import litserve as ls

# Set float32 matrix multiplication precision if GPU is available and capable
Expand Down
5 changes: 3 additions & 2 deletions tests/simple_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from litserve.server import LitServer
from litserve.api import LitAPI
from fastapi import Request, Response

from litserve.api import LitAPI
from litserve.server import LitServer


class SimpleLitAPI(LitAPI):
def setup(self, device):
Expand Down
2 changes: 1 addition & 1 deletion tests/simple_server_diff_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from litserve.server import LitServer
from litserve.api import LitAPI
from litserve.server import LitServer


class SimpleLitAPI(LitAPI):
Expand Down
Loading
Loading