Skip to content

Commit

Permalink
🩹 CLI fixed result outformat accepting none supported formats
Browse files Browse the repository at this point in the history
  • Loading branch information
s-weigand committed Aug 13, 2021
1 parent 76489c9 commit f4e607c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
3 changes: 1 addition & 2 deletions glotaran/cli/commands/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from glotaran.analysis.optimize import optimize
from glotaran.cli.commands import util
from glotaran.plugin_system.data_io_registration import known_data_formats
from glotaran.plugin_system.project_io_registration import known_project_formats
from glotaran.plugin_system.project_io_registration import save_result
from glotaran.project.scheme import Scheme

Expand Down Expand Up @@ -37,7 +36,7 @@
"--outformat",
"-ofmt",
default="folder",
type=click.Choice(known_project_formats()),
type=click.Choice(util.project_io_list_supporting_plugins("save_result", ("yml_str"))),
help="The format of the output.",
show_default=True,
)
Expand Down
10 changes: 10 additions & 0 deletions glotaran/cli/commands/test/test_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from glotaran.cli.commands.util import project_io_list_supporting_plugins


def test_project_io_list_supporting_plugins_save_result():
"""Same as used in ``--outformat`` CLI option."""
result = project_io_list_supporting_plugins("save_result", ("yml_str"))

assert "csv" not in result
assert "yml_str" not in result
assert "folder" in result
32 changes: 32 additions & 0 deletions glotaran/cli/commands/util.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
from __future__ import annotations

import sys
from typing import Iterable

import click
from click import echo
from click import prompt

from glotaran.io import ProjectIoInterface
from glotaran.io import load_dataset
from glotaran.io import load_model
from glotaran.io import load_parameters
from glotaran.io import load_scheme
from glotaran.plugin_system.base_registry import methods_differ_from_baseclass_table
from glotaran.plugin_system.project_io_registration import get_project_io
from glotaran.plugin_system.project_io_registration import known_project_formats


def signature_analysis(cmd):
Expand Down Expand Up @@ -121,6 +128,31 @@ def write_data(data, out):
df.to_csv(out)


def project_io_list_supporting_plugins(
method_name: str, block_list: Iterable[str] | None = None
) -> Iterable[str]:
"""List all project-io plugin that implement ``method_name``.
Parameters
----------
method_name: str
Name of the method which should be supported.
block_list: Iterable[str]
Iterable of plugin names which should be omitted.
"""
if block_list is None:
block_list = []
support_table = methods_differ_from_baseclass_table(
method_names=method_name,
plugin_registry_keys=known_project_formats(full_names=False),
get_plugin_function=get_project_io,
base_class=ProjectIoInterface,
)
support_table = filter(lambda entry: entry[1], support_table)
supporting_list: Iterable[str] = (entry[0].replace("`", "") for entry in support_table)
return list(filter(lambda entry: entry not in block_list, supporting_list))


class ValOrRangeOrList(click.ParamType):
name = "number or range or list"

Expand Down

0 comments on commit f4e607c

Please sign in to comment.