From 902829063b694ed42be0f927d5868f12f709103a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B6hm?= Date: Sun, 24 Sep 2023 17:23:51 +0200 Subject: [PATCH] Resolve import cycle by moving VCommand to a new module --- .../varats/experiment/workload_util.py | 3 +- varats-core/varats/project/project_util.py | 88 ------------------ varats-core/varats/project/varats_command.py | 92 +++++++++++++++++++ varats/varats/projects/c_projects/xz.py | 2 +- 4 files changed, 95 insertions(+), 90 deletions(-) create mode 100644 varats-core/varats/project/varats_command.py diff --git a/varats-core/varats/experiment/workload_util.py b/varats-core/varats/experiment/workload_util.py index abf90b094..38b82720f 100644 --- a/varats-core/varats/experiment/workload_util.py +++ b/varats-core/varats/experiment/workload_util.py @@ -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 diff --git a/varats-core/varats/project/project_util.py b/varats-core/varats/project/project_util.py index 4a836f99d..a4c27d74d 100644 --- a/varats-core/varats/project/project_util.py +++ b/varats-core/varats/project/project_util.py @@ -7,7 +7,6 @@ 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 @@ -15,9 +14,6 @@ from varats.utils.settings import bb_cfg -if tp.TYPE_CHECKING: - from varats.provider.patch.patch_provider import Patch, PatchSet - LOG = logging.getLogger(__name__) @@ -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) - )) diff --git a/varats-core/varats/project/varats_command.py b/varats-core/varats/project/varats_command.py new file mode 100644 index 000000000..314a1ee55 --- /dev/null +++ b/varats-core/varats/project/varats_command.py @@ -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) + )) diff --git a/varats/varats/projects/c_projects/xz.py b/varats/varats/projects/c_projects/xz.py index 3debddd18..3d1a580ed 100644 --- a/varats/varats/projects/c_projects/xz.py +++ b/varats/varats/projects/c_projects/xz.py @@ -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,