Skip to content

Commit

Permalink
Fix printing & return collected manifests
Browse files Browse the repository at this point in the history
Typer doesn't seem to play nice with `yield`
  • Loading branch information
disrupted committed Oct 26, 2023
1 parent 9054472 commit bab8eb7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docs/docs/user/references/cli-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ $ kpops generate [OPTIONS] PIPELINE_PATH [COMPONENTS_MODULE]
* `--pipeline-base-dir DIRECTORY`: Base directory to the pipelines (default is current working directory) [env var: KPOPS_PIPELINE_BASE_DIR; default: .]
* `--defaults DIRECTORY`: Path to defaults folder [env var: KPOPS_DEFAULT_PATH]
* `--config FILE`: Path to the config.yaml file [env var: KPOPS_CONFIG_PATH; default: config.yaml]
* `--output / --no-output`: Enable output printing [default: output]
* `--verbose / --no-verbose`: Enable verbose printing [default: no-verbose]
* `--help`: Show this message and exit.

Expand All @@ -146,6 +147,7 @@ $ kpops render [OPTIONS] PIPELINE_PATH [COMPONENTS_MODULE]
* `--config FILE`: Path to the config.yaml file [env var: KPOPS_CONFIG_PATH; default: config.yaml]
* `--steps TEXT`: Comma separated list of steps to apply the command on [env var: KPOPS_PIPELINE_STEPS]
* `--filter-type [include|exclude]`: Whether the --steps option should include/exclude the steps [default: include]
* `--output / --no-output`: Enable output printing [default: output]
* `--verbose / --no-verbose`: Enable verbose printing [default: no-verbose]
* `--help`: Show this message and exit.

Expand Down
16 changes: 12 additions & 4 deletions kpops/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class FilterType(str, Enum):
help="Whether the --steps option should include/exclude the steps",
)

OUTPUT_OPTION = typer.Option(True, help="Enable output printing")
VERBOSE_OPTION = typer.Option(False, help="Enable verbose printing")

COMPONENTS_MODULES: str | None = typer.Argument(
Expand Down Expand Up @@ -245,13 +246,15 @@ def generate(
pipeline_base_dir: Path = BASE_DIR_PATH_OPTION,
defaults: Optional[Path] = DEFAULT_PATH_OPTION,
config: Path = CONFIG_PATH_OPTION,
output: bool = OUTPUT_OPTION,
verbose: bool = VERBOSE_OPTION,
) -> Pipeline:
kpops_config = create_kpops_config(config, defaults, verbose)
pipeline = setup_pipeline(
pipeline_base_dir, pipeline_path, components_module, kpops_config
)
print_yaml(str(pipeline))
if output:
print_yaml(str(pipeline))
return pipeline


Expand All @@ -266,21 +269,26 @@ def render(
config: Path = CONFIG_PATH_OPTION,
steps: Optional[str] = PIPELINE_STEPS,
filter_type: FilterType = FILTER_TYPE,
output: bool = OUTPUT_OPTION,
verbose: bool = VERBOSE_OPTION,
) -> Iterator[Mapping]:
) -> list[Mapping]:
pipeline = generate(
pipeline_path=pipeline_path,
components_module=components_module,
pipeline_base_dir=pipeline_base_dir,
defaults=defaults,
config=config,
output=False,
verbose=verbose,
)
steps_to_apply = get_steps_to_apply(pipeline, steps, filter_type)
manifests: list[Mapping] = []
for component in steps_to_apply:
manifest = component.render()
print_yaml(manifest)
yield manifest
manifests.append(manifest)
if output:
print_yaml(manifest)
return manifests


@app.command(
Expand Down
2 changes: 1 addition & 1 deletion kpops/utils/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def print_yaml(data: Mapping | str, substitution: dict | None = None) -> None:
:param substitution: Substitution dictionary, defaults to None
"""
if not isinstance(data, str):
data = yaml.dump(data)
data = yaml.safe_dump(dict(data))
syntax = Syntax(
substitute(data, substitution),
"yaml",
Expand Down

0 comments on commit bab8eb7

Please sign in to comment.