Skip to content

Commit

Permalink
Merge branch 'command_requires' into jan-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
danjujan committed Aug 4, 2023
2 parents 6e1b2e2 + 2b16e2d commit 9f20df4
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
25 changes: 25 additions & 0 deletions tests/experiment/test_workload_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test VaRA workload utilities."""
import unittest
from pathlib import Path
from unittest.mock import patch

from benchbuild.command import Command, PathToken, RootRenderer
from benchbuild.source.base import Revision, Variant
Expand Down Expand Up @@ -52,6 +53,30 @@ def test_workload_commands_tags_selected(self) -> None:
)
self.assertEqual(len(commands), 1)

def test_workload_commands_requires(self) -> None:
revision = Revision(Xz, Variant(Xz.SOURCE[0], "c5c7ceb08a"))
project = Xz(revision=revision)
binary = Xz.binaries_for_revision(ShortCommitHash("c5c7ceb08a"))[0]

commands = next(
wu.filter_workload_index(
wu.WorkloadSet(wu.WorkloadCategory.EXAMPLE), project.workloads
)
)
commands[0]._requires = {"--compress"}
commands = wu.workload_commands(
project, binary, [wu.WorkloadCategory.EXAMPLE]
)
self.assertEqual(len(commands), 0)
with patch(
"varats.experiment.workload_util.get_extra_config_options",
return_value=["--compress"]
):
commands = wu.workload_commands(
project, binary, [wu.WorkloadCategory.EXAMPLE]
)
self.assertEqual(len(commands), 1)


class TestWorkloadFilenames(unittest.TestCase):

Expand Down
15 changes: 14 additions & 1 deletion varats-core/varats/experiment/workload_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Command,
)

from varats.experiment.experiment_util import get_extra_config_options
from varats.project.project_util import ProjectBinaryWrapper
from varats.project.varats_project import VProject
from varats.report.report import KeyedReportAggregate, ReportTy
Expand Down Expand Up @@ -94,8 +95,20 @@ def workload_commands(
)
]

# Filter commands that have required args set.
options = set(get_extra_config_options(project))

def requires_filter(prj_cmd: ProjectCommand) -> bool:
if hasattr(prj_cmd.command, "requires") and prj_cmd.command.requires:
return bool(options.intersection(prj_cmd.command.requires))
return True

available_cmds = filter(requires_filter, project_cmds)

return list(
filter(lambda prj_cmd: prj_cmd.path.name == binary.name, project_cmds)
filter(
lambda prj_cmd: prj_cmd.path.name == binary.name, available_cmds
)
)


Expand Down
26 changes: 26 additions & 0 deletions varats-core/varats/project/project_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import benchbuild as bb
import pygit2
from benchbuild.command import Command as _Command
from benchbuild.source import Git
from benchbuild.utils.cmd import git
from plumbum import local
Expand Down Expand Up @@ -382,3 +383,28 @@ def copy_renamed_git_to_dest(src_dir: Path, dest_dir: Path) -> None:
for name in dirs:
if name == ".gitted":
os.rename(os.path.join(root, name), os.path.join(root, ".git"))


class Command(_Command):

Check failure on line 388 in varats-core/varats/project/project_util.py

View workflow job for this annotation

GitHub Actions / mypy

[mypy] varats-core/varats/project/project_util.py#L388

error: Class cannot subclass "_Command" (has type "Any") [misc]
Raw output
varats-core/varats/project/project_util.py:388:15: error: Class cannot subclass "_Command" (has type "Any")  [misc]
"""
Wrapper around benchbuild's Command class.
Additional functionality: requires attribute: specify required
args that must be added before execution.
"""

_requires: tp.Set[str]

def __init__(
self,
*args: tp.Any,
requires: tp.Optional[tp.Set[str]] = None,
**kwargs: tp.Union[str, tp.List[str]],
) -> None:

super().__init__(*args, **kwargs)
self._requires = requires if requires else set()

@property
def requires(self) -> tp.Set[str]:
return self._requires
21 changes: 19 additions & 2 deletions varats/varats/projects/c_projects/xz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import typing as tp

import benchbuild as bb
from benchbuild.command import Command, SourceRoot, WorkloadSet
from benchbuild.command import SourceRoot, WorkloadSet
from benchbuild.source import HTTPMultiple
from benchbuild.utils.cmd import autoreconf, make
from benchbuild.utils.revision_ranges import (
Expand All @@ -19,6 +19,7 @@
from varats.project.project_domain import ProjectDomains
from varats.project.project_util import (
BinaryType,
Command,
ProjectBinaryWrapper,
get_local_project_git_path,
verify_binaries,
Expand Down Expand Up @@ -87,11 +88,27 @@ class Xz(VProject):
Command(
SourceRoot("xz") / RSBinary("xz"),
"-k",
"geo-maps/countries-land-1km.geo.json",
output_param=["{output}"],
output=SourceRoot("geo-maps/countries-land-250m.geo.json"),
label="countries-land-1km",
creates=["geo-maps/countries-land-1km.geo.json.xz"]
)
],
WorkloadSet(WorkloadCategory.MEDIUM): [
Command(
SourceRoot("xz") / RSBinary("xz"),
"-k",
"-9e",
"--compress",
"--threads=1",
"--format=xz",
"-vv",
output_param=["{output}"],
output=SourceRoot("geo-maps/countries-land-250m.geo.json"),
label="countries-land-250m",
creates=["geo-maps/countries-land-250m.geo.json.xz"]
)
],
WorkloadSet(WorkloadCategory.JAN): [
Command(
SourceRoot("xz") / RSBinary("xz"),
Expand Down

0 comments on commit 9f20df4

Please sign in to comment.