Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for trogon. #870

Open
wants to merge 13 commits into
base: vara-dev
Choose a base branch
from
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ ignore_missing_imports = True
ignore_missing_imports = True
ignore_errors = True

[mypy-trogon.*]
ignore_missing_imports = True

[mypy-varats.gui.views.*]
ignore_errors = True

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ rich>=12.6
scikit-learn>=1.2.2
seaborn>=0.13.0
tabulate>=0.9
trogon>=0.5.0
types-PyYAML
types-requests
types-tabulate
Expand Down
20 changes: 16 additions & 4 deletions tests/tools/test_driver_artefacts.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""Test artefacts config tool."""
import traceback
import importlib
import unittest

from click.testing import CliRunner

import varats.tools.driver_artefacts as driver_artefacts
from tests.helper_utils import run_in_test_environment, UnitTestFixtures
from varats.data.discover_reports import initialize_reports
from varats.paper.paper_config import get_paper_config, load_paper_config
from varats.paper_mgmt.artefacts import Artefact, load_artefacts
from varats.plots.discover_plots import initialize_plots
from varats.tables.discover_tables import initialize_tables
from varats.tools import driver_artefacts
from varats.utils.settings import vara_cfg


Expand All @@ -32,6 +32,7 @@ def test_artefacts_generate(self) -> None:
# setup config
vara_cfg()['paper_config']['current_config'] = "test_artefacts_driver"
load_paper_config()
importlib.reload(driver_artefacts)
artefacts = load_artefacts(get_paper_config()).artefacts
base_output_dir = Artefact.base_output_dir()

Expand Down Expand Up @@ -59,8 +60,9 @@ def test_artefacts_list(self) -> None:
# setup config
vara_cfg()['paper_config']['current_config'] = "test_artefacts_driver"
load_paper_config()
importlib.reload(driver_artefacts)

# vara-art generate
# vara-art list
runner = CliRunner()
result = runner.invoke(driver_artefacts.main, ["list"])
self.assertEqual(0, result.exit_code, result.exception)
Expand All @@ -76,6 +78,16 @@ def test_artefacts_show(self) -> None:
# setup config
vara_cfg()['paper_config']['current_config'] = "test_artefacts_driver"
load_paper_config()
importlib.reload(driver_artefacts)

# vara-art list
runner = CliRunner()
result = runner.invoke(driver_artefacts.main, ["list"])
self.assertEqual(0, result.exit_code, result.exception)
self.assertEqual(
"Paper Config Overview [plot]\nCorrelation Table [table]\n"
"CS Overview (xz) [plot]\nRepo Churn (all) [plot]\n", result.stdout
)

expected = r"""Artefact 'Paper Config Overview':
artefact_type: plot
Expand All @@ -91,7 +103,7 @@ def test_artefacts_show(self) -> None:

"""

# vara-art generate
# vara-art show
runner = CliRunner()
result = runner.invoke(
driver_artefacts.main, ["show", "Paper Config Overview"]
Expand Down
2 changes: 1 addition & 1 deletion tests/tools/test_driver_paper_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_vara_pc_select(self):
vara_cfg()["paper_config"]["current_config"] = "foo"
load_paper_config()
result = runner.invoke(driver_paper_config.main, ["select"], input="1")
assert not result.exception
self.assertFalse(result.exception)
self.assertEqual(
"0. bar\n1. baz\n2. foo *\n"
"Choose a number to select a paper config (default=0): ",
Expand Down
1 change: 1 addition & 0 deletions varats/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"scikit-learn>=1.2.2",
"seaborn>=0.13.0",
"tabulate>=0.9",
"trogon>=0.5.0",
"varats-core>=13.0.5",
"wllvm>=1.3.1",
],
Expand Down
55 changes: 32 additions & 23 deletions varats/varats/tools/driver_artefacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import click
import yaml
from rich.progress import Progress
from trogon import tui

from varats.data.discover_reports import initialize_reports
from varats.paper.paper_config import get_paper_config
Expand All @@ -26,16 +27,25 @@
from varats.projects.discover_projects import initialize_projects
from varats.tables.discover_tables import initialize_tables
from varats.ts_utils.cli_util import initialize_cli_tool
from varats.ts_utils.click_param_types import TypedChoice
from varats.ts_utils.html_util import (
CSS_IMAGE_MATRIX,
CSS_COMMON,
html_page,
CSS_TABLE,
)
from varats.utils.exceptions import ConfigurationLookupError

LOG = logging.getLogger(__name__)

initialize_projects()
initialize_reports()
initialize_tables()
initialize_plots()
initialize_artefact_types()


@tui() # type: ignore
@click.group(
help="Manage artefacts.",
context_settings={"help_option_names": ['-h', '--help']}
Expand All @@ -47,15 +57,10 @@ def main() -> None:
`vara-art`
"""
initialize_cli_tool()
initialize_projects()
initialize_reports()
initialize_tables()
initialize_plots()
initialize_artefact_types()


# function name `list` would shadow built-in `list`
@main.command(
@main.command( # type: ignore
name="list", help="List all artefacts of the current paper config."
)
def list_() -> None:
Expand All @@ -66,49 +71,53 @@ def list_() -> None:
print(f"{artefact.name} [{artefact.ARTEFACT_TYPE}]")


@main.command(help="Show detailed information about artefacts.")
@click.argument("name")
def show(name: str) -> None:
def _create_artefact_choice() -> TypedChoice['Artefact']:
try:
paper_config = get_paper_config()
except ConfigurationLookupError:
empty_art_dict: tp.Dict[str, 'Artefact'] = {}
return TypedChoice(empty_art_dict)
value_dict = {art.name: art for art in load_artefacts(paper_config)}
return TypedChoice(value_dict)


@main.command(help="Show detailed information about artefacts.") # type: ignore
@click.argument("artefact", type=_create_artefact_choice())
def show(artefact: Artefact) -> None:
"""
Show detailed information about artefacts.

Args:
name: the name of the artefact
artefact: the artefact to display
"""
paper_config = get_paper_config()
if (artefact := load_artefacts(paper_config).get_artefact(name)):
print(f"Artefact '{name}':")
print(textwrap.indent(yaml.dump(artefact.get_dict()), ' '))
else:
print(f"There is no artefact with the name {name}.")
print(f"Artefact '{artefact.name}':")
print(textwrap.indent(yaml.dump(artefact.get_dict()), ' '))


@main.command(
@main.command( # type: ignore
help="Generate artefacts. By default, all artefacts are generated."
)
@click.option(
"--only",
type=_create_artefact_choice(),
multiple=True,
help="Only generate artefacts with the given names."
)
def generate(only: tp.Optional[str]) -> None:
def generate(only: tp.List[Artefact]) -> None:
"""
Generate artefacts.

By default, all artefacts are generated.

Args:
only: generate only this artefact
only: generate only these artefacts
"""
if not Artefact.base_output_dir().exists():
Artefact.base_output_dir().mkdir(parents=True)
artefacts: tp.Iterable[Artefact]

if only:
artefacts = [
art for art in load_artefacts(get_paper_config())
if art.name in only
]
artefacts = only
else:
artefacts = load_artefacts(get_paper_config())

Expand Down
12 changes: 7 additions & 5 deletions varats/varats/tools/driver_build_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import click
from plumbum import colors
from trogon import tui

from varats.containers.containers import (
ImageBase,
Expand Down Expand Up @@ -89,13 +90,14 @@ def show_major_release_prompt(
return


@tui() # type: ignore
@click.group(context_settings={"help_option_names": ['-h', '--help']})
def main() -> None:
"""Build VaRA on cli."""
initialize_cli_tool()


@main.command()
@main.command() # type: ignore
def config() -> None:
"""Only create a VaRA-TS config file."""
save_config()
Expand Down Expand Up @@ -123,7 +125,7 @@ def config() -> None:
required=False,
help="Tool install folder."
)
@main.command()
@main.command() # type: ignore
def init(
version: tp.Optional[int], install_prefix: tp.Optional[Path],
source_location: tp.Optional[Path], research_tool: str
Expand All @@ -136,7 +138,7 @@ def init(
@click.argument(
"research_tool", type=click.Choice(get_supported_research_tool_names())
)
@main.command()
@main.command() # type: ignore
def update(research_tool: str) -> None:
"""Update a research tool and all its components."""
tool = get_research_tool(research_tool)
Expand Down Expand Up @@ -170,15 +172,15 @@ def update(research_tool: str) -> None:
@click.option(
"--build-type",
type=EnumChoice(BuildType, case_sensitive=False),
default=BuildType.DEV,
default="DEV",
help="Build type to use for the tool build configuration."
)
@click.option(
"--update-prompt/--no-update-prompt",
default=True,
help="Show a prompt to check for major version updates."
)
@main.command()
@main.command() # type: ignore
def build(
research_tool: str, build_type: BuildType,
build_folder_suffix: tp.Optional[str], source_location: tp.Optional[Path],
Expand Down
Loading
Loading