Skip to content

Commit

Permalink
refactor: change project structura
Browse files Browse the repository at this point in the history
  • Loading branch information
Lancetnik committed Sep 13, 2024
1 parent 432b498 commit dc8deef
Show file tree
Hide file tree
Showing 313 changed files with 1,348 additions and 1,963 deletions.
2 changes: 1 addition & 1 deletion docs/docs_src/confluent/publisher_object/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pydantic import BaseModel, Field, NonNegativeFloat

from faststream import FastStream, Logger
from faststream._compat import model_to_json
from faststream._internal._compat import model_to_json
from faststream.confluent import KafkaBroker, TestKafkaBroker

broker = KafkaBroker("localhost:9092")
Expand Down
2 changes: 1 addition & 1 deletion docs/docs_src/kafka/publisher_object/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pydantic import BaseModel, Field, NonNegativeFloat

from faststream import FastStream, Logger
from faststream._compat import model_to_json
from faststream._internal._compat import model_to_json
from faststream.kafka import KafkaBroker, TestKafkaBroker

broker = KafkaBroker("localhost:9092")
Expand Down
22 changes: 16 additions & 6 deletions faststream/__init__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
"""A Python framework for building services interacting with Apache Kafka, RabbitMQ, NATS and Redis."""

from faststream.annotations import ContextRepo, Logger, NoCast
from faststream._internal.context import context
from faststream._internal.testing.app import TestApp
from faststream._internal.utils import apply_types
from faststream.annotations import ContextRepo, Logger
from faststream.app import FastStream
from faststream.broker.middlewares import BaseMiddleware, ExceptionMiddleware
from faststream.broker.response import Response
from faststream.testing.app import TestApp
from faststream.utils import Context, Depends, Header, Path, apply_types, context
from faststream.middlewares import BaseMiddleware, ExceptionMiddleware
from faststream.params import (
Context,
Depends,
Header,
NoCast,
Path,
)
from faststream.response import Response

__all__ = (
# app
"FastStream",
"TestApp",
# utils
"apply_types",
# context
"context",
# params
"Context",
"Header",
"Path",
"Depends",
"NoCast",
# annotations
"Logger",
"ContextRepo",
"NoCast",
# middlewares
"BaseMiddleware",
"ExceptionMiddleware",
Expand Down
2 changes: 1 addition & 1 deletion faststream/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import warnings

try:
from faststream.cli.main import cli
from faststream._internal.cli.main import cli
except ImportError:
has_typer = False
else:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion faststream/_compat.py → faststream/_internal/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)
from pydantic import BaseModel as BaseModel

from faststream.types import AnyDict
from faststream._internal.basic_types import AnyDict

IS_WINDOWS = (
sys.platform == "win32" or sys.platform == "cygwin" or sys.platform == "msys"
Expand Down
16 changes: 1 addition & 15 deletions faststream/types.py → faststream/_internal/basic_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class StandardDataclass(Protocol):
]

try:
from faststream._compat import BaseModel
from faststream._internal._compat import BaseModel

SendableMessage: TypeAlias = Union[
BaseModel,
Expand Down Expand Up @@ -107,17 +107,3 @@ def log(
exc_info: Any = None,
extra: Optional[Mapping[str, Any]] = None,
) -> None: ...


class _EmptyPlaceholder:
def __repr__(self) -> str:
return "EMPTY"

def __eq__(self, other: object) -> bool:
if not isinstance(other, _EmptyPlaceholder):
return NotImplemented

return True


EMPTY: Any = _EmptyPlaceholder()
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
Optional,
)

from faststream.broker.types import MsgType
from ..types import (
BrokerMiddleware,
CustomCallable,
MsgType,
)

if TYPE_CHECKING:
from fast_depends.dependencies import Depends

from faststream.broker.publisher.proto import PublisherProto
from faststream.broker.subscriber.proto import SubscriberProto
from faststream.broker.types import (
BrokerMiddleware,
CustomCallable,
)
from faststream._internal.publisher.proto import PublisherProto
from faststream._internal.subscriber.proto import SubscriberProto


class ABCBroker(Generic[MsgType]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,37 @@

from typing_extensions import Annotated, Doc, Self

from faststream._compat import is_test_env
from faststream.broker.core.logging import LoggingBroker
from faststream.broker.middlewares.logging import CriticalLogMiddleware
from faststream.broker.proto import SetupAble
from faststream.broker.subscriber.proto import SubscriberProto
from faststream.broker.types import (
from faststream._internal._compat import is_test_env
from faststream._internal.context.repository import context
from faststream._internal.log.logging import set_logger_fmt
from faststream._internal.proto import SetupAble
from faststream._internal.subscriber.proto import SubscriberProto
from faststream._internal.types import (
AsyncCustomCallable,
BrokerMiddleware,
ConnectionType,
CustomCallable,
MsgType,
)
from faststream._internal.utils.functions import return_input, to_async
from faststream.exceptions import NOT_CONNECTED_YET
from faststream.log.logging import set_logger_fmt
from faststream.utils.context.repository import context
from faststream.utils.functions import return_input, to_async
from faststream.middlewares.logging import CriticalLogMiddleware

from .logging_mixin import LoggingBroker

if TYPE_CHECKING:
from types import TracebackType

from fast_depends.dependencies import Depends

from faststream.broker.message import StreamMessage
from faststream.broker.publisher.proto import ProducerProto, PublisherProto
from faststream._internal.basic_types import AnyDict, Decorator, LoggerProto
from faststream._internal.publisher.proto import (
ProducerProto,
PublisherProto,
)
from faststream.message import StreamMessage
from faststream.security import BaseSecurity
from faststream.specification.schema.tag import Tag, TagDict
from faststream.types import AnyDict, Decorator, LoggerProto


class BrokerUsecase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

from typing_extensions import Annotated, Doc

from faststream.broker.core.abc import ABCBroker
from faststream.broker.types import MsgType
from faststream.types import EMPTY
from faststream._internal.constants import EMPTY

from ..types import MsgType
from .abc_broker import ABCBroker

if TYPE_CHECKING:
from faststream.types import AnyDict, LoggerProto
from faststream._internal.basic_types import AnyDict, LoggerProto


class LoggingBroker(ABCBroker[MsgType]):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
Optional,
)

from faststream.broker.core.abc import ABCBroker
from faststream.broker.types import MsgType
from ..types import (
BrokerMiddleware,
CustomCallable,
MsgType,
)
from .abc_broker import ABCBroker

if TYPE_CHECKING:
from fast_depends.dependencies import Depends

from faststream.broker.types import (
BrokerMiddleware,
CustomCallable,
)
from faststream.types import AnyDict
from faststream._internal.basic_types import AnyDict


class ArgsContainer:
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import typer
from pydantic import ValidationError

from faststream._compat import json_dumps, model_parse
from faststream.cli.utils.imports import import_from_string
from faststream._internal._compat import json_dumps, model_parse
from faststream._internal.cli.utils.imports import import_from_string
from faststream.exceptions import INSTALL_WATCHFILES, INSTALL_YAML, SCHEMA_NOT_SUPPORTED
from faststream.specification.asyncapi.generate import get_app_schema
from faststream.specification.asyncapi.site import serve_app
Expand Down Expand Up @@ -71,7 +71,7 @@ def serve(

if reload:
try:
from faststream.cli.supervisors.watchfiles import WatchReloader
from faststream._internal.cli.supervisors.watchfiles import WatchReloader

except ImportError:
warnings.warn(INSTALL_WATCHFILES, category=ImportWarning, stacklevel=1)
Expand Down
16 changes: 8 additions & 8 deletions faststream/cli/main.py → faststream/_internal/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

from faststream import FastStream
from faststream.__about__ import __version__
from faststream.cli.docs import asyncapi_app
from faststream.cli.utils.imports import import_from_string
from faststream.cli.utils.logs import LogLevels, get_log_level, set_log_level
from faststream.cli.utils.parser import parse_cli_args
from faststream._internal.cli.docs import asyncapi_app
from faststream._internal.cli.utils.imports import import_from_string
from faststream._internal.cli.utils.logs import LogLevels, get_log_level, set_log_level
from faststream._internal.cli.utils.parser import parse_cli_args
from faststream.exceptions import INSTALL_WATCHFILES, SetupError, ValidationError

if TYPE_CHECKING:
from faststream.broker.core.usecase import BrokerUsecase
from faststream.types import AnyDict, SettingField
from faststream._internal.basic_types import AnyDict, SettingField
from faststream._internal.broker.broker import BrokerUsecase

cli = typer.Typer(pretty_exceptions_short=True)
cli.add_typer(asyncapi_app, name="docs", help="Documentations commands")
Expand Down Expand Up @@ -120,7 +120,7 @@ def run(

if reload:
try:
from faststream.cli.supervisors.watchfiles import WatchReloader
from faststream._internal.cli.supervisors.watchfiles import WatchReloader
except ImportError:
warnings.warn(INSTALL_WATCHFILES, category=ImportWarning, stacklevel=1)
_run(*args)
Expand All @@ -140,7 +140,7 @@ def run(
).run()

elif workers > 1:
from faststream.cli.supervisors.multiprocess import Multiprocess
from faststream._internal.cli.supervisors.multiprocess import Multiprocess

Multiprocess(
target=_run,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from multiprocessing.context import SpawnProcess
from typing import TYPE_CHECKING, Any, Optional, Tuple

from faststream.cli.supervisors.utils import get_subprocess, set_exit
from faststream.log import logger
from faststream._internal.cli.supervisors.utils import get_subprocess, set_exit
from faststream._internal.log import logger

if TYPE_CHECKING:
from faststream.types import DecoratedCallable
from faststream._internal.basic_types import DecoratedCallable


class BaseReload:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import signal
from typing import TYPE_CHECKING, Any, List, Tuple

from faststream.cli.supervisors.basereload import BaseReload
from faststream.log import logger
from faststream._internal.cli.supervisors.basereload import BaseReload
from faststream._internal.log import logger

if TYPE_CHECKING:
from multiprocessing.context import SpawnProcess

from faststream.types import DecoratedCallable
from faststream._internal.basic_types import DecoratedCallable


class Multiprocess(BaseReload):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from multiprocessing.context import SpawnProcess
from types import FrameType

from faststream.types import DecoratedCallableNone
from faststream._internal.basic_types import DecoratedCallableNone

multiprocessing.allow_connection_pickling()
spawn = multiprocessing.get_context("spawn")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

import watchfiles

from faststream.cli.supervisors.basereload import BaseReload
from faststream.log import logger
from faststream._internal.cli.supervisors.basereload import BaseReload
from faststream._internal.log import logger

if TYPE_CHECKING:
from faststream.types import DecoratedCallable
from faststream._internal.basic_types import DecoratedCallable


class ExtendedFilter(watchfiles.PythonFilter):
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from typing import TYPE_CHECKING, DefaultDict, Optional, Union

if TYPE_CHECKING:
from faststream._internal.basic_types import LoggerProto
from faststream.app import FastStream
from faststream.types import LoggerProto


class LogLevels(str, Enum):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import TYPE_CHECKING, Dict, List, Tuple

if TYPE_CHECKING:
from faststream.types import SettingField
from faststream._internal.basic_types import SettingField


def parse_cli_args(*args: str) -> Tuple[str, Dict[str, "SettingField"]]:
Expand Down
25 changes: 25 additions & 0 deletions faststream/_internal/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from enum import Enum
from typing import Any

ContentType = str


class ContentTypes(str, Enum):
"""A class to represent content types."""

text = "text/plain"
json = "application/json"


class _EmptyPlaceholder:
def __repr__(self) -> str:
return "EMPTY"

def __eq__(self, other: object) -> bool:
if not isinstance(other, _EmptyPlaceholder):
return NotImplemented

return True


EMPTY: Any = _EmptyPlaceholder()
8 changes: 8 additions & 0 deletions faststream/_internal/context/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .context_type import Context
from .repository import ContextRepo, context

__all__ = (
"context",
"Context",
"ContextRepo",
)
Loading

0 comments on commit dc8deef

Please sign in to comment.