Skip to content

Commit

Permalink
Resolve import cycle by moving VCommand to a new module
Browse files Browse the repository at this point in the history
  • Loading branch information
boehmseb committed Sep 24, 2023
1 parent 75fee71 commit 9028290
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 90 deletions.
3 changes: 2 additions & 1 deletion varats-core/varats/experiment/workload_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
get_extra_config_options,
get_config_patches,
)
from varats.project.project_util import ProjectBinaryWrapper, VCommand
from varats.project.project_util import ProjectBinaryWrapper
from varats.project.varats_command import VCommand
from varats.project.varats_project import VProject
from varats.report.report import KeyedReportAggregate, ReportTy
from varats.utils.exceptions import auto_unwrap
Expand Down
88 changes: 0 additions & 88 deletions varats-core/varats/project/project_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@

import benchbuild as bb
import pygit2
from benchbuild.command import Command
from benchbuild.source import Git
from benchbuild.utils.cmd import git
from plumbum import local
from plumbum.commands.base import BoundCommand

from varats.utils.settings import bb_cfg

if tp.TYPE_CHECKING:
from varats.provider.patch.patch_provider import Patch, PatchSet

LOG = logging.getLogger(__name__)


Expand Down Expand Up @@ -386,87 +382,3 @@ 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 VCommand(Command): # type: ignore [misc]
"""
Wrapper around benchbuild's Command class.
Attributes:
requires_any_args: any of these command line args must be available for
successful execution.
requires_all_args: all of these command line args must be available for
successful execution.
requires_any_patch: any of these patch feature-tags must be available for
successful execution.
requires_all_patch: all of these patch feature-tags must be available for
successful execution.
"""

_requires: tp.Set[str]

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

super().__init__(*args, **kwargs)
self._requires_any_args = requires_any_args or set()
self._requires_all_args = requires_all_args or set()
self._requires_any_patch = requires_any_patch or set()
self._requires_all_patch = requires_all_patch or set()

@property
def requires_any_args(self) -> tp.Set[str]:
return self._requires_any_args

@property
def requires_all_args(self) -> tp.Set[str]:
return self._requires_all_args

@property
def requires_any_patch(self) -> tp.Set[str]:
return self._requires_any_patch

@property
def requires_all_patch(self) -> tp.Set[str]:
return self._requires_all_patch

def can_be_executed_by(
self, extra_args: tp.Set[str], applied_patches: 'PatchSet'
) -> bool:
"""
Checks whether this command can be executed with the give configuration.
Args:
extra_args: additional command line arguments that will be passed to
the command
applied_patches: patches that were applied to create the executable
Returns:
whether this command can be executed
"""
all_args = set(self._args).union(extra_args)
all_patch_tags: tp.Set[str] = set()
for patch in applied_patches:
if patch.feature_tags:
all_patch_tags.update(patch.feature_tags)

return bool((
not self.requires_any_args or
all_args.intersection(self.requires_any_args)
) and (
not self.requires_all_args or
self.requires_all_args.issubset(all_args)
) and (
not self.requires_any_patch or
all_patch_tags.intersection(self.requires_any_patch)
) and (
not self.requires_all_patch or
self.requires_all_patch.issubset(all_patch_tags)
))
92 changes: 92 additions & 0 deletions varats-core/varats/project/varats_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"""Custom version of benchbuild's Command for use with the VaRA-Tool-Suite."""
import typing as tp

from benchbuild.command import Command

if tp.TYPE_CHECKING:
import varats.provider.patch.patch_provider as patch_provider


class VCommand(Command): # type: ignore [misc]
"""
Wrapper around benchbuild's Command class.
Attributes:
requires_any_args: any of these command line args must be available for
successful execution.
requires_all_args: all of these command line args must be available for
successful execution.
requires_any_patch: any of these patch feature-tags must be available for
successful execution.
requires_all_patch: all of these patch feature-tags must be available for
successful execution.
"""

_requires: tp.Set[str]

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

super().__init__(*args, **kwargs)
self._requires_any_args = requires_any_args or set()
self._requires_all_args = requires_all_args or set()
self._requires_any_patch = requires_any_patch or set()
self._requires_all_patch = requires_all_patch or set()

@property
def requires_any_args(self) -> tp.Set[str]:
return self._requires_any_args

@property
def requires_all_args(self) -> tp.Set[str]:
return self._requires_all_args

@property
def requires_any_patch(self) -> tp.Set[str]:
return self._requires_any_patch

@property
def requires_all_patch(self) -> tp.Set[str]:
return self._requires_all_patch

def can_be_executed_by(
self, extra_args: tp.Set[str],
applied_patches: 'patch_provider.PatchSet'
) -> bool:
"""
Checks whether this command can be executed with the give configuration.
Args:
extra_args: additional command line arguments that will be passed to
the command
applied_patches: patches that were applied to create the executable
Returns:
whether this command can be executed
"""
all_args = set(self._args).union(extra_args)
all_patch_tags: tp.Set[str] = set()
for patch in applied_patches:
if patch.feature_tags:
all_patch_tags.update(patch.feature_tags)

return bool((
not self.requires_any_args or
all_args.intersection(self.requires_any_args)
) and (
not self.requires_all_args or
self.requires_all_args.issubset(all_args)
) and (
not self.requires_any_patch or
all_patch_tags.intersection(self.requires_any_patch)
) and (
not self.requires_all_patch or
self.requires_all_patch.issubset(all_patch_tags)
))
2 changes: 1 addition & 1 deletion varats/varats/projects/c_projects/xz.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
from varats.paper.paper_config import PaperConfigSpecificGit
from varats.project.project_domain import ProjectDomains
from varats.project.project_util import (
VCommand,
ProjectBinaryWrapper,
get_local_project_git_path,
BinaryType,
verify_binaries,
)
from varats.project.sources import FeatureSource
from varats.project.varats_command import VCommand
from varats.project.varats_project import VProject
from varats.utils.git_util import (
ShortCommitHash,
Expand Down

0 comments on commit 9028290

Please sign in to comment.