Skip to content

Commit

Permalink
Merge branch 'main' into kafka-concurrent-sub
Browse files Browse the repository at this point in the history
  • Loading branch information
Flosckow authored Nov 21, 2024
2 parents f662a8b + f751238 commit efdd821
Show file tree
Hide file tree
Showing 24 changed files with 487 additions and 81 deletions.
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"filename": "docs/docs/en/release.md",
"hashed_secret": "35675e68f4b5af7b995d9205ad0fc43842f16450",
"is_verified": false,
"line_number": 1812,
"line_number": 1850,
"is_secret": false
}
],
Expand All @@ -178,5 +178,5 @@
}
]
},
"generated_at": "2024-10-20T20:04:20Z"
"generated_at": "2024-11-15T07:38:53Z"
}
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
<a href="https://t.me/python_faststream" target="_blank">
<img alt="Telegram" src="https://img.shields.io/badge/-telegram-black?color=blue&logo=telegram&label=RU"/>
</a>

<br/>

<a href="https://gurubase.io/g/faststream" target="_blank">
<img src="https://img.shields.io/badge/Gurubase-Ask%20FastStream%20Guru-006BFF" alt="Gurubase"/>
</a>
</p>

---
Expand Down
6 changes: 6 additions & 0 deletions docs/docs/en/faststream.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ search:
<a href="https://t.me/python_faststream" target="_blank">
<img alt="Telegram" src="https://img.shields.io/badge/-telegram-black?color=blue&logo=telegram&label=RU"/>
</a>

<br/>

<a href="https://gurubase.io/g/faststream" target="_blank">
<img alt="Gurubase" src="https://img.shields.io/badge/Gurubase-Ask%20FastStream%20Guru-006BFF"/>
</a>
</p>

---
Expand Down
38 changes: 38 additions & 0 deletions docs/docs/en/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,44 @@ hide:
---

# Release Notes
## 0.5.30

### What's Changed
* Introducing FastStream Guru on Gurubase.io by [@kursataktas](https://github.com/kursataktas){.external-link target="_blank"} in [#1903](https://github.com/airtai/faststream/pull/1903){.external-link target="_blank"}
* docs: add gurubase badge to the doc by [@Lancetnik](https://github.com/Lancetnik){.external-link target="_blank"} in [#1905](https://github.com/airtai/faststream/pull/1905){.external-link target="_blank"}
* fix: allow users to pass `nkeys_seed_str` as argument for NATS broker. by [@Drakorgaur](https://github.com/Drakorgaur){.external-link target="_blank"} in [#1908](https://github.com/airtai/faststream/pull/1908){.external-link target="_blank"}
* Add more warning's to nats subscription factory by [@sheldygg](https://github.com/sheldygg){.external-link target="_blank"} in [#1907](https://github.com/airtai/faststream/pull/1907){.external-link target="_blank"}
* fix: correct working with dependencies versions by [@Lancetnik](https://github.com/Lancetnik){.external-link target="_blank"} in [#1918](https://github.com/airtai/faststream/pull/1918){.external-link target="_blank"}

### New Contributors
* [@kursataktas](https://github.com/kursataktas){.external-link target="_blank"} made their first contribution in [#1903](https://github.com/airtai/faststream/pull/1903){.external-link target="_blank"}
* [@Drakorgaur](https://github.com/Drakorgaur){.external-link target="_blank"} made their first contribution in [#1908](https://github.com/airtai/faststream/pull/1908){.external-link target="_blank"}

**Full Changelog**: [#0.5.29...0.5.30](https://github.com/airtai/faststream/compare/0.5.29...0.5.30){.external-link target="_blank"}

## 0.5.29

### What's Changed

* feat: add explicit message source enum by [@Lancetnik](https://github.com/Lancetnik){.external-link target="_blank"} in [#1866](https://github.com/airtai/faststream/pull/1866){.external-link target="_blank"}
* Change uv manual installation to setup-uv in CI by [@pavelepanov](https://github.com/pavelepanov){.external-link target="_blank"} in [#1871](https://github.com/airtai/faststream/pull/1871){.external-link target="_blank"}
* refactor: make Task and Concurrent mixins broker-agnostic by [@Lancetnik](https://github.com/Lancetnik){.external-link target="_blank"} in [#1873](https://github.com/airtai/faststream/pull/1873){.external-link target="_blank"}
* Add support for environment variables in faststream run command by [@ulbwa](https://github.com/ulbwa){.external-link target="_blank"} in [#1876](https://github.com/airtai/faststream/pull/1876){.external-link target="_blank"}
* fastapi example update by [@xodiumx](https://github.com/xodiumx){.external-link target="_blank"} in [#1875](https://github.com/airtai/faststream/pull/1875){.external-link target="_blank"}
* Do not import `fake_context` if not needed by [@sobolevn](https://github.com/sobolevn){.external-link target="_blank"} in [#1877](https://github.com/airtai/faststream/pull/1877){.external-link target="_blank"}
* build: add warning about manual lifespan_context by [@vectorvp](https://github.com/vectorvp){.external-link target="_blank"} in [#1878](https://github.com/airtai/faststream/pull/1878){.external-link target="_blank"}
* Add trending badge by [@davorrunje](https://github.com/davorrunje){.external-link target="_blank"} in [#1882](https://github.com/airtai/faststream/pull/1882){.external-link target="_blank"}
* feat: add class method to create a baggage instance from headers by [@vectorvp](https://github.com/vectorvp){.external-link target="_blank"} in [#1885](https://github.com/airtai/faststream/pull/1885){.external-link target="_blank"}
* ops: update docker compose commands to compose V2 in scripts by [@vectorvp](https://github.com/vectorvp){.external-link target="_blank"} in [#1889](https://github.com/airtai/faststream/pull/1889){.external-link target="_blank"}

### New Contributors
* [@pavelepanov](https://github.com/pavelepanov){.external-link target="_blank"} made their first contribution in [#1871](https://github.com/airtai/faststream/pull/1871){.external-link target="_blank"}
* [@xodiumx](https://github.com/xodiumx){.external-link target="_blank"} made their first contribution in [#1875](https://github.com/airtai/faststream/pull/1875){.external-link target="_blank"}
* [@sobolevn](https://github.com/sobolevn){.external-link target="_blank"} made their first contribution in [#1877](https://github.com/airtai/faststream/pull/1877){.external-link target="_blank"}
* [@vectorvp](https://github.com/vectorvp){.external-link target="_blank"} made their first contribution in [#1878](https://github.com/airtai/faststream/pull/1878){.external-link target="_blank"}

**Full Changelog**: [#0.5.28...0.5.29](https://github.com/airtai/faststream/compare/0.5.28...0.5.29){.external-link target="_blank"}

## 0.5.28

### What's Changed
Expand Down
2 changes: 1 addition & 1 deletion faststream/__about__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Simple and fast framework to create message brokers based microservices."""

__version__ = "0.5.28"
__version__ = "0.5.30"

SERVICE_NAME = f"faststream-{__version__}"
17 changes: 10 additions & 7 deletions faststream/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
from importlib.metadata import version as get_version
from typing import Any, Callable, Dict, Mapping, Optional, Type, TypeVar, Union

from fast_depends._compat import PYDANTIC_V2 as PYDANTIC_V2
from fast_depends._compat import ( # type: ignore[attr-defined]
PYDANTIC_VERSION as PYDANTIC_VERSION,
)
from pydantic import BaseModel as BaseModel
from pydantic.version import VERSION as PYDANTIC_VERSION

from faststream.types import AnyDict

Expand Down Expand Up @@ -57,8 +54,13 @@ def json_dumps(*a: Any, **kw: Any) -> bytes:

JsonSchemaValue = Mapping[str, Any]

major, minor, *_ = PYDANTIC_VERSION.split(".")
_PYDANTCI_MAJOR, _PYDANTIC_MINOR = int(major), int(minor)

PYDANTIC_V2 = _PYDANTCI_MAJOR >= 2

if PYDANTIC_V2:
if PYDANTIC_VERSION >= "2.4.0":
if _PYDANTIC_MINOR >= 4:
from pydantic.annotated_handlers import (
GetJsonSchemaHandler as GetJsonSchemaHandler,
)
Expand Down Expand Up @@ -150,8 +152,9 @@ def with_info_plain_validator_function( # type: ignore[misc]
return {}


anyio_major = int(get_version("anyio").split(".")[0])
ANYIO_V3 = anyio_major == 3
major, *_ = get_version("anyio").split(".")
_ANYIO_MAJOR = int(major)
ANYIO_V3 = _ANYIO_MAJOR == 3


if ANYIO_V3:
Expand Down
2 changes: 2 additions & 0 deletions faststream/asgi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,14 @@ async def run(
port = int(run_extra_options.pop("port", 8000)) # type: ignore[arg-type]
workers = int(run_extra_options.pop("workers", 1)) # type: ignore[arg-type]
host = str(run_extra_options.pop("host", "localhost"))
fd = int(run_extra_options.pop("fd", -1)) # type: ignore[arg-type]
config = uvicorn.Config(
self,
host=host,
port=port,
log_level=log_level,
workers=workers,
fd=fd if fd != -1 else None,
**run_extra_options,
)
server = uvicorn.Server(config)
Expand Down
28 changes: 23 additions & 5 deletions faststream/broker/fastapi/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,29 @@
from fastapi.dependencies.models import Dependant
from fastapi.requests import Request

major, minor, patch, *_ = map(int, FASTAPI_VERSION.split("."))
FASTAPI_V2 = major > 0 or minor > 100
FASTAPI_V106 = major > 0 or minor >= 106
FASTAPI_v102_3 = major > 0 or minor > 112 or (minor == 112 and patch > 2)
FASTAPI_v102_4 = major > 0 or minor > 112 or (minor == 112 and patch > 3)
major, minor, patch, *_ = FASTAPI_VERSION.split(".")

_FASTAPI_MAJOR, _FASTAPI_MINOR = int(major), int(minor)

FASTAPI_V2 = _FASTAPI_MAJOR > 0 or _FASTAPI_MINOR > 100
FASTAPI_V106 = _FASTAPI_MAJOR > 0 or _FASTAPI_MINOR >= 106

try:
_FASTAPI_PATCH = int(patch)
except ValueError:
FASTAPI_v102_3 = True
FASTAPI_v102_4 = True
else:
FASTAPI_v102_3 = (
_FASTAPI_MAJOR > 0
or _FASTAPI_MINOR > 112
or (_FASTAPI_MINOR == 112 and _FASTAPI_PATCH > 2)
)
FASTAPI_v102_4 = (
_FASTAPI_MAJOR > 0
or _FASTAPI_MINOR > 112
or (_FASTAPI_MINOR == 112 and _FASTAPI_PATCH > 3)
)

__all__ = (
"create_response_field",
Expand Down
21 changes: 19 additions & 2 deletions faststream/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ def run(
_run(*args)

else:
_run(*args)
_run_imported_app(
app_obj,
extra_options=extra,
log_level=casted_log_level,
)


def _run(
Expand All @@ -168,11 +172,24 @@ def _run(
extra_options: Dict[str, "SettingField"],
is_factory: bool,
log_level: int = logging.NOTSET,
app_level: int = logging.INFO,
app_level: int = logging.INFO, # option for reloader only
) -> None:
"""Runs the specified application."""
_, app_obj = import_from_string(app, is_factory=is_factory)
_run_imported_app(
app_obj,
extra_options=extra_options,
log_level=log_level,
app_level=app_level,
)


def _run_imported_app(
app_obj: "Application",
extra_options: Dict[str, "SettingField"],
log_level: int = logging.NOTSET,
app_level: int = logging.INFO, # option for reloader only
) -> None:
if not isinstance(app_obj, Application):
raise typer.BadParameter(
f'Imported object "{app_obj}" must be "Application" type.',
Expand Down
4 changes: 2 additions & 2 deletions faststream/cli/utils/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import TYPE_CHECKING, DefaultDict, Optional, Union

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


Expand Down Expand Up @@ -64,7 +64,7 @@ def get_log_level(level: Union[LogLevels, str, int]) -> int:
return LOG_LEVELS[level.lower()]


def set_log_level(level: int, app: "FastStream") -> None:
def set_log_level(level: int, app: "Application") -> None:
"""Sets the log level for an application."""
if app.logger and getattr(app.logger, "setLevel", None):
app.logger.setLevel(level) # type: ignore[attr-defined]
Expand Down
11 changes: 10 additions & 1 deletion faststream/nats/broker/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ class NatsInitKwargs(TypedDict, total=False):
Doc("A user credentials file or tuple of files."),
]
nkeys_seed: Annotated[
Optional[str],
Doc("Path-like object containing nkeys seed that will be used."),
]
nkeys_seed_str: Annotated[
Optional[str],
Doc("Nkeys seed to be used."),
]
Expand Down Expand Up @@ -350,7 +354,11 @@ def __init__(
] = None,
nkeys_seed: Annotated[
Optional[str],
Doc("Nkeys seed to be used."),
Doc("Path-like object containing nkeys seed that will be used."),
] = None,
nkeys_seed_str: Annotated[
Optional[str],
Doc("Raw nkeys seed to be used."),
] = None,
inbox_prefix: Annotated[
Union[str, bytes],
Expand Down Expand Up @@ -509,6 +517,7 @@ def __init__(
token=token,
user_credentials=user_credentials,
nkeys_seed=nkeys_seed,
nkeys_seed_str=nkeys_seed_str,
**secure_kwargs,
# callbacks
error_cb=self._log_connection_broken(error_cb),
Expand Down
4 changes: 2 additions & 2 deletions faststream/nats/broker/registrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ def subscriber( # type: ignore[override]
Doc("Enable Heartbeats for a consumer to detect failures."),
] = None,
flow_control: Annotated[
bool,
Optional[bool],
Doc("Enable Flow Control for a consumer."),
] = False,
] = None,
deliver_policy: Annotated[
Optional["api.DeliverPolicy"],
Doc("Deliver Policy to be used for subscription."),
Expand Down
4 changes: 2 additions & 2 deletions faststream/nats/fastapi/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,9 @@ def subscriber( # type: ignore[override]
Doc("Enable Heartbeats for a consumer to detect failures."),
] = None,
flow_control: Annotated[
bool,
Optional[bool],
Doc("Enable Flow Control for a consumer."),
] = False,
] = None,
deliver_policy: Annotated[
Optional["api.DeliverPolicy"],
Doc("Deliver Policy to be used for subscription."),
Expand Down
5 changes: 5 additions & 0 deletions faststream/nats/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ async def ack(self) -> None:
await self.raw_message.ack()
await super().ack()

async def ack_sync(self) -> None:
if not self.raw_message._ackd:
await self.raw_message.ack_sync()
await super().ack()

async def nack(
self,
delay: Union[int, float, None] = None,
Expand Down
4 changes: 2 additions & 2 deletions faststream/nats/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ def __init__(
Doc("Enable Heartbeats for a consumer to detect failures."),
] = None,
flow_control: Annotated[
bool,
Optional[bool],
Doc("Enable Flow Control for a consumer."),
] = False,
] = None,
deliver_policy: Annotated[
Optional["api.DeliverPolicy"],
Doc("Deliver Policy to be used for subscription."),
Expand Down
Loading

0 comments on commit efdd821

Please sign in to comment.