Skip to content

Commit

Permalink
Merge pull request #20 from stealthrocket/fmt-imports
Browse files Browse the repository at this point in the history
  • Loading branch information
pelletier authored Feb 2, 2024
2 parents 2bdc183 + f3b2416 commit cbe54c6
Show file tree
Hide file tree
Showing 28 changed files with 80 additions and 73 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dev:
$(PYTHON) -m pip install -e .[dev]

fmt:
$(PYTHON) -m isort .
$(PYTHON) -m black .

typecheck:
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ dependencies = [
[project.optional-dependencies]
dev = [
"black==24.1.0",
"isort==5.13.2",
"mypy==1.8.0",
"fastapi==0.109.0",
"httpx==0.26.0",
"coverage==7.4.1"
]

[tool.isort]
profile = "black"
src_paths = ["src"]

[tool.coverage.run]
omit = [
Expand Down
13 changes: 6 additions & 7 deletions src/dispatch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@
"""

from __future__ import annotations
import pickle

import os
from urllib.parse import urlparse
from functools import cached_property
import pickle
from collections.abc import Iterable
from typing import Any, TypeAlias
from dataclasses import dataclass
from typing import Any, TypeAlias
from urllib.parse import urlparse

import grpc
import google.protobuf
import google.protobuf.any_pb2
import google.protobuf.message
import google.protobuf.wrappers_pb2
import grpc

import dispatch.coroutine
import dispatch.sdk.v1.endpoint_pb2 as endpoint_pb
import dispatch.sdk.v1.endpoint_pb2_grpc as endpoint_grpc
import dispatch.coroutine


__all__ = ["Client", "ExecutionID", "ExecutionInput", "ExecutionDef"]

Expand Down
4 changes: 2 additions & 2 deletions src/dispatch/coroutine.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
"""

from __future__ import annotations

import enum
import pickle
from typing import Any, Callable
from dataclasses import dataclass
from typing import Any, Callable

import google.protobuf.message

from dispatch.sdk.v1 import executor_pb2 as executor_pb
from dispatch.sdk.v1 import status_pb2 as status_pb


# Most types in this package are thin wrappers around the various protobuf
# messages of ring.coroutine.v1. They provide some safeguards and ergonomics.

Expand Down
1 change: 1 addition & 0 deletions src/dispatch/experimental/durable/durable.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from types import FunctionType, GeneratorType

from .generator import DurableGenerator
from .registry import register_function

Expand Down
2 changes: 1 addition & 1 deletion src/dispatch/experimental/durable/frame.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from types import FrameType
from typing import Any, Tuple, Generator
from typing import Any, Generator, Tuple

def get_frame_ip(frame: FrameType | Generator) -> int: ...
def set_frame_ip(frame: FrameType | Generator, ip: int): ...
Expand Down
6 changes: 3 additions & 3 deletions src/dispatch/experimental/durable/generator.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from types import GeneratorType, TracebackType, CodeType, FrameType
from types import CodeType, FrameType, GeneratorType, TracebackType
from typing import Generator, TypeVar
from .registry import lookup_function
from . import frame as ext

from . import frame as ext
from .registry import lookup_function

_YieldT = TypeVar("_YieldT", covariant=True)
_SendT = TypeVar("_SendT", contravariant=True)
Expand Down
1 change: 0 additions & 1 deletion src/dispatch/experimental/durable/registry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from types import FunctionType


_REGISTRY: dict[str, FunctionType] = {}


Expand Down
2 changes: 1 addition & 1 deletion src/dispatch/experimental/multicolor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .compile import compile_function
from .yields import yields, CustomYield, GeneratorYield
from .yields import CustomYield, GeneratorYield, yields

__all__ = ["compile_function", "yields", "CustomYield", "GeneratorYield"]
5 changes: 3 additions & 2 deletions src/dispatch/experimental/multicolor/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
from enum import Enum
from types import FunctionType, GeneratorType, MethodType
from typing import cast

from .desugar import desugar_function
from .generator import is_generator, empty_generator
from .parse import parse_function, NoSourceError, repair_indentation
from .generator import empty_generator, is_generator
from .parse import NoSourceError, parse_function, repair_indentation
from .template import rewrite_template
from .yields import CustomYield, GeneratorYield

Expand Down
2 changes: 1 addition & 1 deletion src/dispatch/experimental/multicolor/parse.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ast
import inspect
from typing import cast
from types import FunctionType
from typing import cast


def parse_function(fn: FunctionType) -> tuple[ast.Module, ast.FunctionDef]:
Expand Down
4 changes: 2 additions & 2 deletions src/dispatch/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ def read_root():
"""

import os
from typing import Any, Dict
from collections.abc import Callable
from typing import Dict

import fastapi
import fastapi.responses
from httpx import _urlparse

from dispatch.sdk.v1 import executor_pb2 as executor_pb
import dispatch.coroutine
from dispatch.sdk.v1 import executor_pb2 as executor_pb


def configure(
Expand Down
1 change: 0 additions & 1 deletion src/dispatch/sdk/v1/endpoint_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions src/dispatch/sdk/v1/endpoint_pb2.pyi
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from typing import ClassVar as _ClassVar
from typing import Iterable as _Iterable
from typing import Mapping as _Mapping
from typing import Optional as _Optional
from typing import Union as _Union

from google.protobuf import any_pb2 as _any_pb2
from google.protobuf import duration_pb2 as _duration_pb2
from google.protobuf.internal import containers as _containers
from google.protobuf import descriptor as _descriptor
from google.protobuf import duration_pb2 as _duration_pb2
from google.protobuf import message as _message
from typing import (
ClassVar as _ClassVar,
Iterable as _Iterable,
Mapping as _Mapping,
Optional as _Optional,
Union as _Union,
)
from google.protobuf.internal import containers as _containers

DESCRIPTOR: _descriptor.FileDescriptor

Expand Down
2 changes: 1 addition & 1 deletion src/dispatch/sdk/v1/executor_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions src/dispatch/sdk/v1/executor_pb2.pyi
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from dispatch.sdk.v1 import status_pb2 as _status_pb2
from typing import ClassVar as _ClassVar
from typing import Iterable as _Iterable
from typing import Mapping as _Mapping
from typing import Optional as _Optional
from typing import Union as _Union

from google.protobuf import any_pb2 as _any_pb2
from google.protobuf import duration_pb2 as _duration_pb2
from google.protobuf.internal import containers as _containers
from google.protobuf import descriptor as _descriptor
from google.protobuf import duration_pb2 as _duration_pb2
from google.protobuf import message as _message
from typing import (
ClassVar as _ClassVar,
Iterable as _Iterable,
Mapping as _Mapping,
Optional as _Optional,
Union as _Union,
)
from google.protobuf.internal import containers as _containers

from dispatch.sdk.v1 import status_pb2 as _status_pb2

DESCRIPTOR: _descriptor.FileDescriptor

Expand Down
15 changes: 7 additions & 8 deletions src/dispatch/sdk/v1/key_pb2.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from google.protobuf.internal import containers as _containers
from typing import ClassVar as _ClassVar
from typing import Iterable as _Iterable
from typing import Mapping as _Mapping
from typing import Optional as _Optional
from typing import Union as _Union

from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from typing import (
ClassVar as _ClassVar,
Iterable as _Iterable,
Mapping as _Mapping,
Optional as _Optional,
Union as _Union,
)
from google.protobuf.internal import containers as _containers

DESCRIPTOR: _descriptor.FileDescriptor

Expand Down
5 changes: 3 additions & 2 deletions src/dispatch/sdk/v1/status_pb2.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from google.protobuf.internal import enum_type_wrapper as _enum_type_wrapper
from google.protobuf import descriptor as _descriptor
from typing import ClassVar as _ClassVar

from google.protobuf import descriptor as _descriptor
from google.protobuf.internal import enum_type_wrapper as _enum_type_wrapper

DESCRIPTOR: _descriptor.FileDescriptor

class Status(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
Expand Down
1 change: 1 addition & 0 deletions tests/dispatch/experimental/durable/test_frame.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest

from dispatch.experimental.durable import frame as ext


Expand Down
3 changes: 2 additions & 1 deletion tests/dispatch/experimental/durable/test_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
import pickle
import unittest

from dispatch.experimental.durable import durable


Expand Down
7 changes: 4 additions & 3 deletions tests/dispatch/experimental/multicolor/test_compile.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import time
import unittest
from enum import Enum
from types import FunctionType
from typing import Any

from dispatch.experimental.multicolor import (
compile_function,
yields,
CustomYield,
GeneratorYield,
compile_function,
yields,
)
from enum import Enum


class YieldTypes(Enum):
Expand Down
4 changes: 2 additions & 2 deletions tests/dispatch/experimental/multicolor/test_desugar.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import ast
import unittest
from types import FunctionType
from dispatch.experimental.multicolor.parse import parse_function
from dispatch.experimental.multicolor.desugar import desugar_function

from dispatch.experimental.multicolor.desugar import desugar_function
from dispatch.experimental.multicolor.parse import parse_function

# Disable lint checks:
# ruff: noqa
Expand Down
3 changes: 2 additions & 1 deletion tests/dispatch/experimental/multicolor/test_generator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
from dispatch.experimental.multicolor.parse import parse_function

from dispatch.experimental.multicolor.generator import YieldCounter, is_generator
from dispatch.experimental.multicolor.parse import parse_function


class TestYieldCounter(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/executor_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import httpx
import grpc
import httpx

from dispatch.sdk.v1 import executor_pb2 as executor_pb
from dispatch.sdk.v1 import executor_pb2_grpc as executor_grpc
Expand Down
5 changes: 1 addition & 4 deletions tests/task_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@

import dispatch.sdk.v1.endpoint_pb2 as endpoint_pb
import dispatch.sdk.v1.endpoint_pb2_grpc as endpoint_grpc

import dispatch.sdk.v1.executor_pb2 as executor_pb
import dispatch.sdk.v1.executor_pb2_grpc as executor_grpc

from dispatch import Client, ExecutionInput, ExecutionID

from dispatch import Client, ExecutionID, ExecutionInput

_test_auth_token = "THIS_IS_A_TEST_AUTH_TOKEN"

Expand Down
5 changes: 3 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
from unittest import mock

import grpc
from google.protobuf import wrappers_pb2, any_pb2
from google.protobuf import any_pb2, wrappers_pb2

from dispatch import Client, ExecutionInput, ExecutionID
from dispatch import Client, ExecutionID, ExecutionInput
from dispatch.coroutine import _any_unpickle as any_unpickle

from .task_service import ServerTest


Expand Down
9 changes: 5 additions & 4 deletions tests/test_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
import unittest
from typing import Any

import httpx
import fastapi
from fastapi.testclient import TestClient
import google.protobuf.wrappers_pb2
import httpx
from fastapi.testclient import TestClient

import dispatch.fastapi
import dispatch.coroutine
from dispatch.coroutine import Input, Output, Error, Status
import dispatch.fastapi
from dispatch.coroutine import Error, Input, Output, Status
from dispatch.sdk.v1 import executor_pb2 as executor_pb

from . import executor_service


Expand Down
9 changes: 5 additions & 4 deletions tests/test_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import fastapi
from fastapi.testclient import TestClient

from dispatch import Client, ExecutionInput, ExecutionID
from dispatch.coroutine import Input, Output, Error, Status
from dispatch.coroutine import _any_unpickle as any_unpickle
import dispatch.fastapi
from .test_client import ServerTest
from dispatch import Client, ExecutionID, ExecutionInput
from dispatch.coroutine import Error, Input, Output, Status
from dispatch.coroutine import _any_unpickle as any_unpickle

from . import executor_service
from .test_client import ServerTest


class TestFullFastapi(unittest.TestCase):
Expand Down

0 comments on commit cbe54c6

Please sign in to comment.