Skip to content

Commit

Permalink
Merge branch 'main' into incorrect-parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Flosckow authored Sep 13, 2024
2 parents 45238ff + 6a06a38 commit bec9b32
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 60 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/pr_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'
run: |
python -m pip install uv
uv pip install --system .[kafka,test-core]
uv pip install --system .[kafka,test-core,cli]
- name: Test
run: >
bash scripts/test.sh
Expand Down Expand Up @@ -209,7 +209,7 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'
run: |
python -m pip install uv
uv pip install --system .[confluent,test-core]
uv pip install --system .[confluent,test-core,cli]
- name: Test
run: >
bash scripts/test.sh
Expand Down Expand Up @@ -278,7 +278,7 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'
run: |
python -m pip install uv
uv pip install --system .[rabbit,test-core]
uv pip install --system .[rabbit,test-core,cli]
- name: Test
run: >
bash scripts/test.sh
Expand Down Expand Up @@ -336,7 +336,7 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'
run: |
python -m pip install uv
uv pip install --system .[nats,test-core]
uv pip install --system .[nats,test-core,cli]
- name: Test
run: >
bash scripts/test.sh
Expand Down Expand Up @@ -394,7 +394,7 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'
run: |
python -m pip install uv
uv pip install --system .[redis,test-core]
uv pip install --system .[redis,test-core,cli]
- name: Test
run: >
bash scripts/test.sh
Expand Down
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": 1655,
"line_number": 1689,
"is_secret": false
}
],
Expand All @@ -178,5 +178,5 @@
}
]
},
"generated_at": "2024-09-06T15:06:47Z"
"generated_at": "2024-09-10T05:07:49Z"
}
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ async def test_invalid():

The application can be started using built-in **FastStream** CLI command.

Before running the service, install **FastStream CLI** using the following command:

```shell
pip install "faststream[cli]"
```

To run the service, use the **FastStream CLI** command and pass the module (in this case, the file where the app implementation is located) and the app symbol to the command.

``` shell
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ search:
- [HTTP Async Frameworks](getting-started/integrations/frameworks/index.md)
- [FastAPI Plugin](getting-started/integrations/fastapi/index.md)
- [Django](getting-started/integrations/django/index.md)
- [CLI commands](getting-started/cli/index.md)
- [CLI](getting-started/cli/index.md)
- [ASGI](getting-started/asgi.md)
- [OpenTelemetry](getting-started/opentelemetry/index.md)
- [Logging](getting-started/logging.md)
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 @@ -141,6 +141,12 @@ Using pytest, the test for our service would look like this:

The application can be started using the built-in **FastStream** CLI command.

!!! note
Before running the service, install **FastStream CLI** using the following command:
```shell
pip install "faststream[cli]"
```

To run the service, use the **FastStream CLI** command and pass the module (in this case, the file where the app implementation is located) and the app symbol to the command.

```shell
Expand Down
10 changes: 10 additions & 0 deletions docs/docs/en/getting-started/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ search:
!!! quote ""
Thanks to [*typer*](https://typer.tiangolo.com/){.external-link target="_blank"} and [*watchfiles*](https://watchfiles.helpmanual.io/){.external-link target="_blank"}. Their work is the basis of this tool.

## Installation

To install the **FastStream CLI**, you need to run the following command:

```shell
pip install faststream[cli]
```

After installation, you can check which commands are available by executing:

```shell
faststream --help
```
Expand Down
6 changes: 6 additions & 0 deletions docs/docs/en/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ Install using `pip`:

## Basic Usage

!!! note
Before continuing with the next steps, make sure you install *Fastream* CLI.
```shell
pip install "faststream[cli]"
```

To create a basic application, add the following code to a new file (e.g. `serve.py`):

{! includes/getting_started/index/base.md !}
Expand Down
34 changes: 34 additions & 0 deletions docs/docs/en/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,40 @@ hide:
---

# Release Notes
## 0.5.23

### What's Changed

We made last release just a few days ago, but there are some big changes here already!

1. First of all - you can't use `faststream run ...` command without `pip install faststream[cli]` distribution anymore. It was made to minify default (and production) distribution by removing **typer** (**rich** and **click**) dependencies. **CLI** is a development-time feature, so if you don't need - just don't install! Special thanks to @RubenRibGarcia for this change

2. The next big change - **Kafka** publish confirmations by default! Previous **FastStream** version was working in *publish & forgot* style, but the new one blocks your `broker.publish(...)` call until **Kafka** confirmation frame received. To fallback to previous logic just use a new flag `broker.publish(..., no_confirm=True)`

3. Also, we made one more step forward to our **1.0.0** features plan! @KrySeyt implements `get_one` feature. Now you can use any broker subscriber to get messages in imperative style:

```python
subscriber = broker.subscriber("in")
...
msg = await subscriber.get_one(timeout=5.0)
```

4. And the last one: @draincoder continues to develop OTEL support! Now he provides us with an ability to use **OTEL spans** and **baggage** in a comfortable **FastStream**-style. Just take a look at the [new documentation section](https://faststream.airt.ai/latest/getting-started/opentelemetry/#baggage)

Big thanks to all new and old contributors who makes such a great release!

* feat: AsgiFastStream hooks init options by @Lancetnik in https://github.com/airtai/faststream/pull/1768
* fix (#1748): add Kafka publish no_confirm option by @Lancetnik in https://github.com/airtai/faststream/pull/1749
* Fix GeneralExceptionHandler typehint by @sheldygg in https://github.com/airtai/faststream/pull/1773
* Add `broker.subscriber().get_one()` by @KrySeyt in https://github.com/airtai/faststream/pull/1726
* Add OTel baggage support by @draincoder in https://github.com/airtai/faststream/pull/1692
* build(#1430): separate cli faststream to its own distribution by @RubenRibGarcia in https://github.com/airtai/faststream/pull/1769

### New Contributors
* @RubenRibGarcia made their first contribution in https://github.com/airtai/faststream/pull/1769

**Full Changelog**: https://github.com/airtai/faststream/compare/0.5.22...0.5.23

## 0.5.22

### What's Changed
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/navigation_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ search:
- [HTTP Async Frameworks](getting-started/integrations/frameworks/index.md)
- [FastAPI Plugin](getting-started/integrations/fastapi/index.md)
- [Django](getting-started/integrations/django/index.md)
- [CLI commands](getting-started/cli/index.md)
- [CLI](getting-started/cli/index.md)
- [ASGI](getting-started/asgi.md)
- [OpenTelemetry](getting-started/opentelemetry/index.md)
- [Logging](getting-started/logging.md)
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.22"
__version__ = "0.5.23"

SERVICE_NAME = f"faststream-{__version__}"
15 changes: 14 additions & 1 deletion faststream/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@

import warnings

from faststream.cli.main import cli
try:
from faststream.cli.main import cli
except ImportError:
has_typer = False
else:
has_typer = True

if not has_typer:
raise ImportError(
"\n\nYou're trying to use the FastStream CLI, "
"\nbut you haven't installed the required dependencies."
"\nPlease install them using the following command: "
'\npip install "faststream[cli]"'
)

warnings.filterwarnings("default", category=ImportWarning, module="faststream")

Expand Down
21 changes: 11 additions & 10 deletions faststream/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import logging.config
from typing import (
TYPE_CHECKING,
Expand All @@ -14,7 +13,7 @@
)

import anyio
from typing_extensions import ParamSpec
from typing_extensions import Annotated, ParamSpec, deprecated

from faststream._compat import ExceptionGroup
from faststream.asyncapi.proto import AsyncAPIApplication
Expand Down Expand Up @@ -104,7 +103,7 @@ def __init__(
else fake_context
)

self.should_exit = False
self._should_exit = anyio.Event()

# AsyncAPI information
self.title = title
Expand Down Expand Up @@ -163,7 +162,13 @@ async def run(
self,
log_level: int = logging.INFO,
run_extra_options: Optional[Dict[str, "SettingField"]] = None,
sleep_time: float = 0.1,
sleep_time: Annotated[
float,
deprecated(
"Deprecated in **FastStream 0.5.24**. "
"Argument will be removed in **FastStream 0.6.0**."
),
] = 0.1,
) -> None:
"""Run FastStream Application."""
assert self.broker, "You should setup a broker" # nosec B101
Expand All @@ -176,11 +181,7 @@ async def run(
try:
async with anyio.create_task_group() as tg:
tg.start_soon(self._startup, log_level, run_extra_options)

# TODO: mv it to event trigger after nats-py fixing
while not self.should_exit: # noqa: ASYNC110
await anyio.sleep(sleep_time)

await self._should_exit.wait()
await self._shutdown(log_level)
tg.cancel_scope.cancel()
except ExceptionGroup as e:
Expand All @@ -189,7 +190,7 @@ async def run(

def exit(self) -> None:
"""Stop application manually."""
self.should_exit = True
self._should_exit.set()

async def start(
self,
Expand Down
8 changes: 7 additions & 1 deletion faststream/asyncapi/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,26 @@ def _resolve_msg_payloads(
one_of = m.payload.get("oneOf")
if isinstance(one_of, dict):
for p_title, p in one_of.items():
p_title = p_title.replace("/", ".")
payloads.update(p.pop(DEF_KEY, {}))
if p_title not in payloads:
payloads[p_title] = p
one_of_list.append(Reference(**{"$ref": f"#/components/schemas/{p_title}"}))

elif one_of is not None:
# Descriminator case
for p in one_of:
p_title = next(iter(p.values())).split("/")[-1]
p_value = next(iter(p.values()))
p_title = p_value.split("/")[-1]
p_title = p_title.replace("/", ".")
if p_title not in payloads:
payloads[p_title] = p
one_of_list.append(Reference(**{"$ref": f"#/components/schemas/{p_title}"}))

if not one_of_list:
payloads.update(m.payload.pop(DEF_KEY, {}))
p_title = m.payload.get("title", f"{channel_name}Payload")
p_title = p_title.replace("/", ".")
if p_title not in payloads:
payloads[p_title] = m.payload
m.payload = {"$ref": f"#/components/schemas/{p_title}"}
Expand All @@ -178,6 +183,7 @@ def _resolve_msg_payloads(
m.payload["oneOf"] = one_of_list

assert m.title # nosec B101
m.title = m.title.replace("/", ".")
messages[m.title] = m
return Reference(**{"$ref": f"#/components/messages/{m.title}"})

Expand Down
11 changes: 7 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ dynamic = ["version"]

dependencies = [
"anyio>=3.7.1,<5",
"fast-depends>=2.4.0b0,<3.1.0",
"typer>=0.9,!=0.12,<1",
"fast-depends>=2.4.0b0,<3.0.0",
"typing-extensions>=4.8.0",
]

Expand All @@ -75,8 +74,13 @@ redis = ["redis>=5.0.0,<6.0.0"]

otel = ["opentelemetry-sdk>=1.24.0,<2.0.0"]

cli = [
"typer>=0.9,!=0.12,<1",
"watchfiles>=0.15.0,<0.25.0"
]

# dev dependencies
optionals = ["faststream[rabbit,kafka,confluent,nats,redis,otel]"]
optionals = ["faststream[rabbit,kafka,confluent,nats,redis,otel,cli]"]

devdocs = [
"mkdocs-material==9.5.34",
Expand Down Expand Up @@ -130,7 +134,6 @@ testing = [
"pydantic-settings>=2.0.0,<3.0.0",
"httpx==0.27.2",
"PyYAML==6.0.2",
"watchfiles==0.24.0",
"email-validator==2.2.0",
]

Expand Down
Loading

0 comments on commit bec9b32

Please sign in to comment.