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 libs/executors/garf_executors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ def setup_executor(
'ApiExecutionContext',
]

__version__ = '0.1.6'
__version__ = '0.1.7'
1 change: 0 additions & 1 deletion libs/executors/garf_executors/api_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

from __future__ import annotations

import asyncio
import logging

from garf_core import report_fetcher
Expand Down
15 changes: 10 additions & 5 deletions libs/executors/garf_executors/entrypoints/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,23 @@ def main():
batch = {query: reader_client.read(query) for query in args.query}
query_executor.execute_batch(batch, context, args.parallel_threshold)
else:
extra_parameters = utils.ParamsParser(
['source', args.output, 'macro', 'template']
).parse(kwargs)
param_types = ['source', 'macro', 'template']
outputs = args.output.split(',')
extra_parameters = utils.ParamsParser([*param_types, *outputs]).parse(
kwargs
)
source_parameters = extra_parameters.get('source', {})
writer_parameters = {}
for output in outputs:
writer_parameters.update(extra_parameters.get(output))

context = garf_executors.api_executor.ApiExecutionContext(
query_parameters={
'macro': extra_parameters.get('macro'),
'template': extra_parameters.get('template'),
},
writer=args.output,
writer_parameters=extra_parameters.get(args.output),
writer=outputs,
writer_parameters=writer_parameters,
fetcher_parameters=source_parameters,
)
query_executor = garf_executors.setup_executor(
Expand Down
14 changes: 8 additions & 6 deletions libs/executors/garf_executors/execution_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ def writer_client(self) -> abs_writer.AbsWriter:
writer_type = self.writer[0]
else:
writer_type = self.writer

writer_params = self.writer_parameters or {}

if not writer_type:
raise ValueError('No writer specified')

writer_client = writer.create_writer(writer_type, **writer_params)
if writer_type == 'bq':
_ = writer_client.create_or_get_dataset()
Expand All @@ -98,11 +98,13 @@ def writer_clients(self) -> list[abs_writer.AbsWriter]:
"""Returns list of writer clients."""
if not self.writer:
return []

# Convert single writer to list for uniform processing
writers_to_use = self.writer if isinstance(self.writer, list) else [self.writer]
writers_to_use = (
self.writer if isinstance(self.writer, list) else [self.writer]
)
writer_params = self.writer_parameters or {}

clients = []
for writer_type in writers_to_use:
writer_client = writer.create_writer(writer_type, **writer_params)
Expand Down
12 changes: 8 additions & 4 deletions libs/executors/tests/unit/test_api_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ def test_from_fetcher_alias_returns_initialized_executor(self, tmp_path):
)
assert isinstance(executor.fetcher, fake_fetcher.FakeApiReportFetcher)

def test_execute_with_multiple_writers_saves_to_both(self, executor, tmp_path, capsys):
def test_execute_with_multiple_writers_saves_to_both(
self, executor, tmp_path, capsys
):
"""Test that multiple writers (console and json) both execute."""
context = api_executor.ApiExecutionContext(
writer=['console', 'json'],
Expand All @@ -98,12 +100,14 @@ def test_execute_with_multiple_writers_saves_to_both(self, executor, tmp_path, c
context=context,
)
# Verify JSON file was created
json_file = pathlib.Path(context.writer_clients[1].destination_folder) / 'test.json'
json_file = (
pathlib.Path(context.writer_clients[1].destination_folder) / 'test.json'
)
assert json_file.exists()
with pathlib.Path.open(json_file, 'r', encoding='utf-8') as f:
result = json.load(f)
assert result == _TEST_DATA

# Verify console output was generated
output = capsys.readouterr().out
assert 'showing results' in output and 'test' in output
assert 'showing results' in output and 'test' in output
5 changes: 2 additions & 3 deletions libs/executors/tests/unit/test_execution_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import yaml
import pytest
import yaml
from garf_core import query_editor
from garf_executors.execution_context import ExecutionContext

Expand Down Expand Up @@ -115,7 +115,6 @@ def test_backward_compatibility_single_writer_still_works(self, tmp_path):
assert len(writer_clients) == 1
assert writer_clients[0].__class__.__name__ == 'JsonWriter'


def test_from_file_with_multiple_writers(self, tmp_path):
tmp_config = tmp_path / 'config.yaml'
data = {
Expand All @@ -128,4 +127,4 @@ def test_from_file_with_multiple_writers(self, tmp_path):
yaml.dump(data, f, encoding='utf-8')
context = ExecutionContext.from_file(tmp_config)
assert context.writer == ['console', 'json']
assert len(context.writer_clients) == 2
assert len(context.writer_clients) == 2