Skip to content
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 .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
if: contains(github.event.pull_request.changed_files, 'libs/${{ matrix.library }}/**')
run: |
uv pip install -e libs/core/.[all]
uv pip install -e libs/io/.[all]
uv pip install -e libs/io/.[test,all]
uv pip install -e libs/executors/.[all]
cd libs/${{ matrix.library }}
pytest tests/unit
Expand Down
6 changes: 5 additions & 1 deletion docs/usage/writers.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ concrete_writer = writer.create_writer('YOUR_WRITER')
concrete_writer.write(sample_report, 'query')
```
///

!!!note
You can use `awrite` method to write report asynchronously.
```python
await concrete_writer.awrite(sample_report, 'query')
```

### Console

Expand Down
2 changes: 1 addition & 1 deletion libs/io/garf_io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# limitations under the License.
"""Write GarfReport to anywhere."""

__version__ = '0.1.0'
__version__ = '0.1.1'
8 changes: 8 additions & 0 deletions libs/io/garf_io/writers/abs_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from __future__ import annotations

import abc
import asyncio
import logging
from typing import Literal

Expand All @@ -39,6 +40,13 @@ def __init__(
"""Initializes AbsWriter."""
self.array_handling = array_handling
self.array_separator = array_separator
self.kwargs = kwargs

async def awrite(self, report: GarfReport, destination: str) -> str | None:
"""Writes report to destination."""
return await asyncio.to_thread(
self.write, report=report, destination=destination
)

@abc.abstractmethod
def write(self, report: GarfReport, destination: str) -> str | None:
Expand Down
5 changes: 2 additions & 3 deletions libs/io/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ dynamic=["version"]
[tool.setuptools.dynamic]
version = {attr = "garf_io.__version__"}

[options.extras_require]
[project.optional-dependencies]
test = [
"pytest",
"pytest-cov",
"pytest-asyncio",
"pandas"
]

[project.optional-dependencies]
bq=[
"google-cloud-bigquery",
"pandas",
Expand Down
20 changes: 19 additions & 1 deletion libs/io/tests/unit/writers/test_json_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,25 @@ def test_write_single_column_report_returns_correct_data(

assert data == expected

def test_write_single_column_report_returns_correct_data(
@pytest.mark.asyncio
async def test_awrite_single_column_report_returns_correct_data(
self, json_writer, single_column_data, output_folder
):
output = output_folder / _TMP_FILENAME
expected = [
{'column_1': 1},
{'column_1': 2},
{'column_1': 3},
]

await json_writer.awrite(single_column_data, _TMP_FILENAME)

with open(output, 'r') as f:
data = json.load(f)

assert data == expected

def test_write_single_column_report_returns_correct_jsonl_data(
self, single_column_data, output_folder
):
writer = json_writer.JsonWriter(output_folder, format='jsonl')
Expand Down