Utility and helper modules¶
Utilities overview¶
Module: cli_util¶
Command line utilities.
- varats.ts_utils.cli_util.cli_yn_choice(question, default='y')[source]¶
Ask the user to make a y/n decision on the cli.
- Return type:
bool
- varats.ts_utils.cli_util.cli_list_choice(question, choices, choice_to_str, on_choice_callback, start_label=0, default=0, repeat=False)[source]¶
Ask the user to select an item from a list on the cli.
- Parameters:
question (
str) – the question to ask the userchoices (
List[TypeVar(ListTy)]) – the choices the user haschoice_to_str (
Callable[[TypeVar(ListTy)],str]) – a function converting a choice to a stringon_choice_callback (
Callable[[TypeVar(ListTy)],None]) – action to perform when a choice has been madestart_label (
int) – the number label of the first choicedefault (
int) – the default choice that is taken if no input is givenrepeat (
bool) – whether to ask for another choice afteron_choice_callbackhas finished
- Return type:
None
- varats.ts_utils.cli_util.initialize_cli_tool()[source]¶
Initializes all relevant context and tools for varats cli tools.
- Return type:
None
- varats.ts_utils.cli_util.initialize_logger_config()[source]¶
Initializes the logging framework with a basic config, allowing the user to pass the warning level via an environment variable
LOG_LEVEL.- Return type:
None
- varats.ts_utils.cli_util.make_cli_option(*param_decls, **attrs)[source]¶
Create an object that represents a click command line option, i.e., the decorator object that is created by
click.option().- Parameters:
*param_decls (
str) – parameter declarations, i.e., how this option can be used**attrs (
Any) – attributes used to construct the option
- Return type:
Callable[[Union[Callable[...,Any],Command]],Union[Callable[...,Any],Command]]- Returns:
a click CLI option that can be wrapped around a function
- varats.ts_utils.cli_util.add_cli_options(command, *options)[source]¶
Adds click CLI options to a click command.
- Parameters:
command (
Union[Callable[...,Any],Command]) – the command*options (
Callable[[Union[Callable[...,Any],Command]],Union[Callable[...,Any],Command]]) – the options to add
- Return type:
Union[Callable[...,Any],Command]- Returns:
the command with the added options
- class varats.ts_utils.cli_util.CLIOptionConverter[source]¶
Bases:
ABC,Generic[ConversionTy_co]Converter for CLI option declarations.
Converters are required for CLI options that are converted to complex types by click so that they can still be properly stored in an artefact file. In general, a converter should implement a mapping from the complex type to a string value as it would be provided on the command line.
A converter can be attached to a CLI option using the function/decorator
convert_value().
- class varats.ts_utils.cli_util.CLIOptionWithConverter(name, converter, cli_decl)[source]¶
Bases:
Generic[ConversionTy_co]Wrapper class that associates a converter with a CLI option declaration.
- property name: str¶
- property converter: Type[CLIOptionConverter[ConversionTy_co]]¶
- varats.ts_utils.cli_util.convert_value(name, converter)[source]¶
Decorator for calls to
make_cli_option()that attaches a converter.Converters are required for CLI options that are converted to complex types by click so that they can still be properly stored in an artefact file. In general, a converter should implement a mapping from the complex type to a string value as it would be provided on the command line.
- Parameters:
name (
str) – name for the CLI option. This must be the same as the name for the click option that it wraps but with ‘-’ replaced by ‘_’.converter (
Type[CLIOptionConverter[TypeVar(ConversionTy_co, bound=Any, covariant=True)]]) – the converter that is attached to the option
- Return type:
Callable[...,Callable[[Union[Callable[...,Any],Command]],Union[Callable[...,Any],Command]]]- Returns:
a CLI option declaration that can be used as if it was created by
make_cli_option()
- class varats.ts_utils.cli_util.ConfigOption(name, help_str, default, view_default=None, value=None)[source]¶
Bases:
Generic[OptionTy]Class representing a plot/table config option.
Values can be retrieved via the call operator.
- Parameters:
name (
str) – name of the optionhelp_str (
str) – help string for this optiondefault (
TypeVar(OptionTy)) – global default value for the optionview_default (
Optional[TypeVar(OptionTy)]) – global default value when in view mode; do not pass if same value is required in both modesvalue (
Optional[TypeVar(OptionTy)]) – user-provided value of the option; do not pass if not set by user
- property name: str¶
- property default: OptionTy¶
- property view_default: OptionTy | None¶
- property value: OptionTy | None¶
- with_value(value)[source]¶
Create a copy of this option with the given value.
- Parameters:
value (
TypeVar(OptionTy)) – the value for the copied option- Return type:
ConfigOption[TypeVar(OptionTy)]- Returns:
a copy of the option with the given value
- to_cli_option()[source]¶
Create a CLI option from this option.
- Return type:
Callable[[Union[Callable[...,Any],Command]],Union[Callable[...,Any],Command]]- Returns:
a CLI option for this option
- value_or_default(view, default=None, view_default=None)[source]¶
Retrieve the value for this option.
The precedence for values is user provided value > plot-specific default > global default.
This function can also be called via the call operator.
- Parameters:
view (
bool) – whether view-mode is enableddefault (
Optional[TypeVar(OptionTy)]) – plot-specific default valueview_default (
Optional[TypeVar(OptionTy)]) – plot-specific default value when in view-mode
- Return type:
TypeVar(OptionTy)- Returns:
the value for this option
- class varats.ts_utils.cli_util.COGetter(*args, **kwargs)[source]¶
Bases:
Protocol[OptionTy]Getter type for options with no view default.
- class varats.ts_utils.cli_util.COGetterV(*args, **kwargs)[source]¶
Bases:
Protocol[OptionTy]Getter type for options with view default.
- varats.ts_utils.cli_util.tee(process, buffered=True)[source]¶
Adapted from plumbum’s TEE implementation.
Plumbum’s TEE does not allow access to the underlying popen object, which we need to properly handle keyboard interrupts. Therefore, we just copy the relevant portion of plumbum’s implementation and create the popen object by ourself.
- Return type:
Tuple[int,str,str]
Module: html_util¶
Utility module for generating html files.
- varats.ts_utils.html_util.html_page(title, content, styles)[source]¶
Generate a simple HTML page.
- Parameters:
title (
str) – the title of the pagecontent (
str) – the content of the pagestyles (
List[str]) – a list of CSS style declarations
- Return type:
str- Returns:
the HTML page as a string
Module: exceptions¶
This module contains custom exceptions.
- exception varats.utils.exceptions.UnsupportedOperation[source]¶
Bases:
ExceptionRaised if a function is not supported by a type.
- exception varats.utils.exceptions.ProcessTerminatedError[source]¶
Bases:
ExceptionRaised if a process was terminated.
- exception varats.utils.exceptions.ConfigurationLookupError[source]¶
Bases:
ExceptionRaised if a paper config could not be found.
- exception varats.utils.exceptions.ConfigurationMapConfigIDMissmatch[source]¶
Bases:
ExceptionRaised if the config ID parsed from a file did not match the actual created ID, this happens when IDs are missing in the file.
- exception varats.utils.exceptions.EmptyOptional[source]¶
Bases:
ExceptionRaised if an optional was converted to a value without having one.
- varats.utils.exceptions.unwrap(maybe_t, conversion_reason)[source]¶
Unwrap an optional T to the underlying type, thowring an exception should a conversion not be possible.
- Parameters:
maybe_t (
Optional[TypeVar(T)]) – the optional that should always be a valueconversion_reason (
str) – why maybe_t should contain a value and unwrapping should be safe
- Return type:
TypeVar(T)
Returns: the ‘contained’ value inside the optional
- varats.utils.exceptions.auto_unwrap(conversion_reason)[source]¶
Wraps a function with an automatic unwrap call, so a function that normally returns an optional is declared to always return a concrete value. Should no value be returned, an exception is raised mentioning the reason/assumtion why it was thought that the function always returns a value.
- Parameters:
conversion_reason (
str) – why maybe_t should contain a value and unwrapping should be save- Return type:
Callable[[Callable[...,Optional[TypeVar(T)]]],Callable[...,TypeVar(T)]]
Module: git_util¶
Utility module for handling git repos.
- class varats.utils.git_util.CommitHash(short_commit_hash)[source]¶
Bases:
ABCBase class for commit hash abstractions.
- property hash: str¶
- class varats.utils.git_util.ShortCommitHash(short_commit_hash)[source]¶
Bases:
CommitHashShortened commit hash.
- class varats.utils.git_util.FullCommitHash(short_commit_hash)[source]¶
Bases:
CommitHashFull-length commit hash.
- property short_hash: str¶
Abbreviated commit hash.
- varats.utils.git_util.ShortCH¶
alias of
ShortCommitHash
- varats.utils.git_util.FullCH¶
alias of
FullCommitHash
- varats.utils.git_util.commit_hashes_sorted_lexicographically(commit_hashes)[source]¶
- Return type:
Iterable[TypeVar(CommitHashTy, bound=CommitHash)]
- varats.utils.git_util.short_commit_hashes_sorted_by_time_id(commit_hashes, commit_map)[source]¶
- Return type:
Iterable[ShortCommitHash]
- varats.utils.git_util.full_commit_hashes_sorted_by_time_id(commit_hashes, commit_map)[source]¶
- Return type:
Iterable[FullCommitHash]
- class varats.utils.git_util.RepositoryHandle(worktree_path)[source]¶
Bases:
objectWrapper class providing access to a git repository using either pygit2 or commandline-git.
- property repo_name: str¶
Name of the repository, i.e., name of the worktree folder.
- property worktree_path: Path¶
Path to the main worktree of the repository, typically the parent of the .git folder.
- property repo_path: Path¶
Path to the git repository, i.e., the .git folder.
- property pygit_repo: Repository¶
A pygit2 repository instance for the repository.
- varats.utils.git_util.is_commit_hash(value)[source]¶
Checks if a string is a valid git (sha1) hash.
- Parameters:
value (
str) – to check- Return type:
bool
- varats.utils.git_util.get_current_branch(repo)[source]¶
Get the current branch of a repository, e.g., HEAD.
- Parameters:
repo (
RepositoryHandle) – git repository handle- Return type:
str
Returns: branch name
- varats.utils.git_util.get_head_commit(repo)[source]¶
Get the current HEAD commit.
- Parameters:
repo (
RepositoryHandle) – git repository handle- Return type:
Returns: head commit hash
- varats.utils.git_util.get_initial_commit(repo)[source]¶
Get the initial commit of a repository, i.e., the first commit made.
- Parameters:
repo (
RepositoryHandle) – git repository handle- Return type:
Returns: initial commit hash
- varats.utils.git_util.get_submodule_commits(repo, c_head='HEAD')[source]¶
Get the revisions of all submodules of a repo at a given commit.
- Parameters:
repo (
RepositoryHandle) – repository to get the submodules forc_head (
str) – the commit to look at
- Return type:
Dict[str,FullCommitHash]- Returns:
a mapping from submodule name to commit
- varats.utils.git_util.get_all_revisions_between(repo, c_start, c_end, hash_type)[source]¶
Returns a list of all revisions between two commits c_start and c_end (both inclusive), where c_start comes before c_end.
It is assumed that the current working directory is the git repository.
- Parameters:
repo (
RepositoryHandle) – git repository handlec_start (
str) – first commit of the rangec_end (
str) – last commit of the rangehash_type (
Type[TypeVar(CommitHashTy, bound=CommitHash)]) – type of the commit hash to return
- Return type:
List[TypeVar(CommitHashTy, bound=CommitHash)]
- varats.utils.git_util.typed_revision_range(repo, rev_range, hash_type)[source]¶
Typed iterator for revision ranges.
- Parameters:
repo (
RepositoryHandle) – git repository handlerev_range (
AbstractRevisionRange) – the revision range to iteratehash_type (
Type[TypeVar(CommitHashTy, bound=CommitHash)]) – the commit type to use for iteration
- Return type:
Iterator[TypeVar(CommitHashTy, bound=CommitHash)]- Returns:
an iterator over the typed commits in the range
- varats.utils.git_util.get_commits_before_timestamp(repo, timestamp)[source]¶
Get all commits before a specific timestamp (given as a git date format).
Note: for imprecise timestamps (e.g., only 2020), the day and month will default to today.
- Parameters:
repo (
RepositoryHandle) – git repository handletimestamp (
str) – before which commits should be collected
- Return type:
List[FullCommitHash]
Returns: list[last_commit_before_timestamp, …, initial_commits]
- varats.utils.git_util.get_commits_after_timestamp(repo, timestamp)[source]¶
Get all commits after a specific timestamp (given as a git date format).
Note: for imprecise timestamps (e.g., only 2020), the day and month will default to today.
- Args:
repo: git repository handle timestamp: after which commits should be collected
Returns: list[newest_commit, …, last_commit_after_timestamp]
- Return type:
List[FullCommitHash]
- varats.utils.git_util.contains_source_code(repo, commit, churn_config=None)[source]¶
Check if a commit contains source code of any language specified with the churn config.
- Parameters:
repo (
RepositoryHandle) – git repository handlecommit (
ShortCommitHash) – to checkchurn_config (
Optional[ChurnConfig]) – to specify the files that should be considered
- Return type:
bool
- Returns: True, if source code of a language, specified in the churn
config, was found in the commit
- varats.utils.git_util.num_commits(repo, c_start='HEAD')[source]¶
Count the commits in a git repo starting from the given commit back to the initial commit.
- Parameters:
repo (
RepositoryHandle) – git repository handlec_start (
str) – commit to start counting at
- Return type:
int- Returns:
the number of commits
- varats.utils.git_util.num_authors(repo, c_start='HEAD')[source]¶
Count the authors in a git repo starting from the given commit back to the initial commit.
- Parameters:
repo (
RepositoryHandle) – git repository handlec_start (
str) – commit to start counting at
- Return type:
int- Returns:
the number of authors
- varats.utils.git_util.get_authors(repo, c_start='HEAD')[source]¶
Get the authors in a git repo starting from the given commit back to the initial commit.
- Parameters:
repo (
RepositoryHandle) – git repository handlec_start (
str) – commit to start counting at
- Return type:
Set[str]- Returns:
the number of authors
- class varats.utils.git_util.ChurnConfig[source]¶
Bases:
objectThe churn config allows the user to change how code churn is calculated.
Churn is by default calulcated considering all files in a repository. Users can select a specific set of file extensions to only be considered in the code churn, e.g., by selecting h and c only C related files will be used to compute the code churn.
- class Language(*values)[source]¶
Bases:
EnumEnum for different languages that can be used to filter code churn.
- value: Set[str]¶
- C = {'c', 'h'}¶
- CPP = {'cc', 'cpp', 'cxx', 'h', 'hpp', 'hxx'}¶
- static create_default_config()[source]¶
Create a default configuration that includes all files in the code churn, e.g., enabling all languages/file extensions.
- Return type:
- static create_c_language_config()[source]¶
Create a config that only allows C related files, e.g., headers and source files.
- Return type:
- static create_c_style_languages_config()[source]¶
Create a config that allows all files related to C-style languages, i.e., C/CPP.
- Return type:
- static init_as_default_if_none(config)[source]¶
Returns a default initialized config or the passed one.
- Parameters:
config (
Optional[ChurnConfig]) – possibly initialized config- Return type:
- Returns:
passed config or a default initialized one
- property include_everything: bool¶
Checks if all files should be considered in the code churn.
- Returns:
True, if no specific language is enabled
- is_enabled(file_extension)[source]¶
Checks if a file_extension is enabled.
- Parameters:
file_extension (
str) – extension of a file, e.g., h for foo.h- Return type:
bool- Returns:
True, if the extension is currently enabled in the config
- is_language_enabled(language)[source]¶
Checks if a language is enabled.
- Parameters:
language (
Language) – language to check- Return type:
bool- Returns:
True, if the language was enabled
- get_extensions_repr(prefix='', suffix='')[source]¶
Returns a list that contains all file extensions from all enabled languages extended with the passed pre-/suffix.
- Parameters:
prefix (
str) – prefix adding to the strings headsuffix (
str) – suffix adding to the strings tail
- Return type:
List[str]- Returns:
list of modified string file extensions
- class varats.utils.git_util.CommitRepoPair(commit_hash, repo_name)[source]¶
Bases:
objectPair of a commit hash and the name of the repository it is based in.
- property commit_hash: FullCommitHash¶
- property repository_name: str¶
- varats.utils.git_util.get_submodule_head(repo, submodule, commit)[source]¶
Retrieve the checked out commit for a submodule of a project.
- Parameters:
repo (
RepositoryHandle) – main project repository handlesubmodule (
RepositoryHandle) – submodule repository handlecommit (
FullCommitHash) – commit of the project’s main repo
- Return type:
- Returns:
checked out commit of the submodule
- varats.utils.git_util.map_commits(func, cr_pair_list, commit_lookup)[source]¶
Maps a function over a range of commits.
- Return type:
Sequence[TypeVar(MappedCommitResultType)]
- varats.utils.git_util.calc_code_churn_range(repo, churn_config=None, start_range=None, end_range=None)[source]¶
Calculates all churn values for the commits in the specified range.
[start..end]. If no range is supplied, the churn values of all commits are calculated.
- Parameters:
repo (
RepositoryHandle) – git repository handlechurn_config (
Optional[ChurnConfig]) – churn config to customize churn generation
- Return type:
Dict[FullCommitHash,Tuple[int,int,int]]- Returns:
dict of churn triples, where the commit hash points to (files changed, insertions, deletions)
- varats.utils.git_util.calc_commit_code_churn(repo, commit_hash, churn_config=None)[source]¶
Calculates churn of a specific commit.
- Parameters:
repo (
RepositoryHandle) – git repository handlecommit_hash (
FullCommitHash) – commit hash to get churn forchurn_config (
Optional[ChurnConfig]) – churn config to customize churn generation
- Return type:
Tuple[int,int,int]- Returns:
dict of churn triples, where the commit hash points to (files changed, insertions, deletions)
- varats.utils.git_util.calc_code_churn(repo, commit_a, commit_b, churn_config=None)[source]¶
Calculates churn between two commits.
- Parameters:
repo (
RepositoryHandle) – git repository handlecommit_a (
FullCommitHash) – base commit for diff calculationcommit_b (
FullCommitHash) – target commit for diff calculationchurn_config (
Optional[ChurnConfig]) – churn config to customize churn generation
- Return type:
Tuple[int,int,int]- Returns:
dict of churn triples, where the commit hash points to (files changed, insertions, deletions)
- varats.utils.git_util.calc_repo_code_churn(repo, churn_config=None)[source]¶
Calculates code churn for a repository.
- Parameters:
repo (
RepositoryHandle) – git repository handlechurn_config (
Optional[ChurnConfig]) – churn config to customize churn generation
- Return type:
Dict[FullCommitHash,Tuple[int,int,int]]- Returns:
dict of churn triples, where the commit hash points to (files changed, insertions, deletions)
- varats.utils.git_util.calc_repo_loc(repo, rev_range)[source]¶
Calculate the LOC for a repository.
- Parameters:
repo (
RepositoryHandle) – handle for the repository to calculate the LOC forrev_range (
str) – the revision range to use for LOC calculation
- Return type:
int- Returns:
the number of lines in source-code files
- varats.utils.git_util.has_branch(repo, branch_name)[source]¶
Checks if a branch exists in the local repository.
- Return type:
bool
- varats.utils.git_util.has_remote_branch(repo, branch_name, remote)[source]¶
Checks if a remote branch of a repository exists.
- Return type:
bool
- varats.utils.git_util.branch_has_upstream(repo, branch_name, upstream='origin')[source]¶
Check if a branch has an upstream remote.
- Return type:
bool
- class varats.utils.git_util.RepositoryAtCommit(repo, revision)[source]¶
Bases:
objectContext manager to work with a repository at a specific revision, without duplicating the repository.
Module: github_util¶
Utility module for working with the pygithub API.
- varats.utils.github_util.get_github_instance()[source]¶
Creates a Github instance using a github access token if configured.
- Return type:
Github- Returns:
a Github instance
- varats.utils.github_util.get_cached_github_object(cached_object_key, load_function)[source]¶
Transparently caches a GithubObj loaded by the given function.
- Parameters:
cached_object_key (
str) – unique name to identify the GithubObjload_function (
Callable[[Github],TypeVar(PyGithubObj, bound=GithubObject)]) – function that loads a GithubObj
- Return type:
TypeVar(PyGithubObj, bound=GithubObject)- Returns:
the fetched or cached GithubObj
- varats.utils.github_util.get_cached_github_object_list(cached_object_key, load_function)[source]¶
Transparently caches a PaginatedList of GithubObjs loaded by the given function.
- Parameters:
cached_object_key (
str) – unique name to identify the GithubObj listload_function (
Callable[[Github],PaginatedList[TypeVar(PyGithubObj, bound=GithubObject)]]) – function that loads a PaginatedList of PygithubObjs
- Return type:
List[TypeVar(PyGithubObj, bound=GithubObject)]- Returns:
the fetched or cached list of GithubObjs
- varats.utils.github_util.get_github_repo_name_for_project(project)[source]¶
Finds the github repo name corresponding to a given github project.
- Parameters:
project (
Type[Project]) – class of said project- Return type:
Optional[str]- Returns:
the github repo name for the project or
Noneif the given project is not a github project
Module: experiment_util¶
Utility module for BenchBuild experiments.
- varats.experiment.experiment_util.get_varats_result_folder(project)[source]¶
Get the project specific path to the varats result folder.
- Parameters:
project (
Project) – to lookup the result folder for- Return type:
Path- Returns:
path to the project specific result folder
- class varats.experiment.experiment_util.PEErrorHandler(result_folder, error_file_name, timeout_duration=None, delete_files=None)[source]¶
Bases:
objectError handler for process execution errors.
- class varats.experiment.experiment_util.FunctionPEErrorWrapper(func, handler)[source]¶
Bases:
objectWrap a function call with an exception handler.
- Parameters:
func (
Callable[...,Any]) – function to be executedhandler (
PEErrorHandler) – function to handle exception
- varats.experiment.experiment_util.exec_func_with_pe_error_handler(func, handler)[source]¶
Execute a function call with an exception handler.
- Parameters:
func (
Callable[...,Any]) – function to be executedhandler (
PEErrorHandler) – function to handle exception
- Return type:
None
- varats.experiment.experiment_util.get_default_compile_error_wrapped(experiment_handle, project, report_type)[source]¶
Setup the default project compile function with an error handler.
- Parameters:
experiment_handle (
ExperimentHandle) – handle to the current experimentproject (
Project) – that will be compiledreport_type (
Type[BaseReport]) – that should be generated
- Return type:
- Returns:
project compilation function, wrapped with automatic error handling
- varats.experiment.experiment_util.create_default_compiler_error_handler(experiment_handle, project, report_type, binary=None)[source]¶
Create a default PEErrorHandler for compile errors, based on the project, report_type.
- Parameters:
experiment_handle (
ExperimentHandle) – handle to the current experimentproject (
Project) – currently under analysisreport_type (
Type[BaseReport]) – that should be generatedbinary (
Optional[ProjectBinaryWrapper]) – if only a specific binary is handled
- Return type:
Retruns: a initialized PEErrorHandler
- varats.experiment.experiment_util.create_default_analysis_failure_handler(experiment_handle, project, report_type, binary=None, timeout_duration=None)[source]¶
Create a default PEErrorHandler for analysis failures, based on the project, report_type.
- Parameters:
experiment_handle (
ExperimentHandle) – handle to the current experimentproject (
Project) – currently under analysisreport_type (
Type[BaseReport]) – that should be generatedbinary (
Optional[ProjectBinaryWrapper]) – if only a specific binary is handledtimeout_duration (
Optional[str]) – set timeout
- Return type:
Retruns: a initialized PEErrorHandler
- varats.experiment.experiment_util.create_default_error_handler(experiment_handle, project, report_type, error_type, binary=None, timeout_duration=None)[source]¶
Create a default PEErrorHandler based on the project, report_type.
- Parameters:
experiment_handle (
ExperimentHandle) – handle to the current experimentproject (
Project) – currently under analysisreport_type (
Type[BaseReport]) – that should be generatederror_type (
FileStatusExtension) – a FSE describing the problem typetimeout_duration (
Optional[str]) – set timeoutbinary (
Optional[ProjectBinaryWrapper]) – if only a specific binary is handled
- Return type:
Retruns: a initialized PEErrorHandler
- varats.experiment.experiment_util.wrap_unlimit_stack_size(cmd)[source]¶
Wraps a command with prlimit to be executed with max stack size, i.e., setting the soft limit to the hard limit.
- Parameters:
cmd (
Callable[...,Any]) – command that should be executed with max stack size- Return type:
Any
Returns: wrapped command
- class varats.experiment.experiment_util.WithUnlimitedStackSize(*extensions, **kwargs)[source]¶
Bases:
ExtensionSets the stack size of the wrapped command to unlimited (16GB).
- class varats.experiment.experiment_util.ExperimentHandle(experiment)[source]¶
Bases:
objectHandle to an experiment that provides helper interfaces for analysis steps to utilize experiment specific data.
- get_file_name(report_shorthand, project_name, binary_name, project_revision, project_uuid, extension_type, config_id=None)[source]¶
Generates a filename for a report file that is generated by the experiment.
- Parameters:
report_shorthand (
str) – unique shorthand for the reportproject_name (
str) – name of the project for which the report was generatedbinary_name (
str) – name of the binary for which the report was generatedproject_revision (
ShortCommitHash) – revision (commit hash)of the analyzed projectproject_uuid (
str) – benchbuild uuid for the experiment runextension_type (
FileStatusExtension) – to specify the status of the generated report
- Return type:
- Returns:
name for the report file that can later be uniquly identified
- class varats.experiment.experiment_util.VersionExperiment(name=NOTHING, projects=NOTHING, id=NOTHING, schema=NOTHING, container=NOTHING)[source]¶
Bases:
ExperimentBase class for experiments that want to analyze different project revisions.
- REPORT_SPEC: ReportSpecification¶
- SHORTHAND: str¶
- classmethod file_belongs_to_experiment(file_name)[source]¶
Checks if the file belongs to this experiment.
- Parameters:
file_name (
str) – name of the file to check- Return type:
bool- Returns:
True, if the file belongs to this experiment type
- class varats.experiment.experiment_util.ZippedReportFolder(result_report_path)[source]¶
Bases:
TemporaryDirectory[str]Context manager for creating a folder report, i.e., a report file which is actually a folder containing multiple files and other folders.
Example usage: An experiment step can, with this context manager, simply create a folder into which all kinds of data is dropped into. After the completion of the step (leaving the context manager), all files dropped into the folder will be compressed and stored as a single report.
- exception varats.experiment.experiment_util.WrongStepCall[source]¶
Bases:
ExceptionThrow if the common step method was called.
- class varats.experiment.experiment_util.OutputFolderStep(project)[source]¶
Bases:
ProjectStepSpecial step class that needs an output folder to write to.
- class varats.experiment.experiment_util.ZippedExperimentSteps(output_filepath, actions)[source]¶
Bases:
MultiStep[ZippedStepTy]Runs multiple actions, providing them a shared tmp folder that afterwards is zipped into an archive.
- NAME: ClassVar[str] = 'ZippedSteps'¶
- DESCRIPTION: ClassVar[str] = 'Run multiple actions with a shared tmp folder'¶
- varats.experiment.experiment_util.create_new_success_result_filepath(exp_handle, report_type, project, binary, config_id=None)[source]¶
Create a result filepath for a successfull report of the executed experiment/project combination.
- Parameters:
exp_handle (
ExperimentHandle) – handle to the current experimentreport_type (
Type[BaseReport]) – type of the reportproject (
VProject) – current projectbinary (
ProjectBinaryWrapper) – current binaryconfig_id (
Optional[int]) – optional id to specify the used configuration
- Return type:
Returns: formatted success filepath
- varats.experiment.experiment_util.create_new_failed_result_filepath(exp_handle, report_type, project, binary, config_id=None)[source]¶
Create a result filepath for a failed report of the executed experiment/project combination.
- Parameters:
exp_handle (
ExperimentHandle) – handle to the current experimentreport_type (
Type[BaseReport]) – type of the reportproject (
VProject) – current projectbinary (
ProjectBinaryWrapper) – current binaryconfig_id (
Optional[int]) – optional id to specify the used configuration
- Return type:
Returns: formatted fail filepath
- varats.experiment.experiment_util.get_config_patch_steps(project)[source]¶
Get a list of actions that apply all configuration patches to the project.
- Parameters:
project (
VProject) – the project to be configured- Return type:
MutableSequence[Step]- Returns:
the actions that configure the project
Module: project_util¶
Utility module for BenchBuild project handling.
- exception varats.project.project_util.CompilationError[source]¶
Bases:
ExceptionException raised if an error during the compilation was discovered.
- varats.project.project_util.get_project_cls_by_name(project_name)[source]¶
Look up a BenchBuild project by its name.
- Return type:
Type[Project]
- varats.project.project_util.get_loaded_vara_projects()[source]¶
Get all loaded vara projects.
- Return type:
Generator[Type[Project],None,None]
- varats.project.project_util.get_primary_project_source(project_name)[source]¶
- Return type:
FetchableSource
- varats.project.project_util.get_local_project_repo(project_name, git_name=None)[source]¶
- Return type:
- varats.project.project_util.get_local_project_repos(project_name)[source]¶
Get the all git repositories for a given benchbuild project.
- Parameters:
project_name (
str) – name of the given benchbuild project- Return type:
Dict[str,RepositoryHandle]- Returns:
dict with the repository handles for the project’s git sources
- varats.project.project_util.get_extended_commit_lookup_source(project_name, git_name)[source]¶
Get benchbuild FetchableSource specified by the git_name or raise a LookupError if no match was found within the given benchbuild project.
- Parameters:
project_name (
str) – name of the given benchbuild projectgit_name (
str) – name of the git repository
- Return type:
FetchableSource- Returns:
benchbuild FetchableSource of the searched git repository
- varats.project.project_util.create_project_commit_lookup_helper(project_name)[source]¶
Creates a commit lookup function for project repositories.
- Parameters:
project_name (
str) – name of the given benchbuild project- Return type:
Callable[[CommitRepoPair],Commit]- Returns:
a Callable that maps a commit hash and repository name to the corresponding commit.
- varats.project.project_util.get_tagged_commits(project_name)[source]¶
Get a list of all tagged commits along with their respective tags.
- Return type:
List[Tuple[str,str]]
- varats.project.project_util.num_project_commits(project_name, revision)[source]¶
Calculate the number of commits of a project including submodules.
- Parameters:
project_name (
str) – name of the project to calculate commits forrevision (
FullCommitHash) – revision to calculate commits at
- Return type:
int- Returns:
the number of commits in the project
- varats.project.project_util.num_project_authors(project_name, revision)[source]¶
Calculate the number of authors of a project including submodules.
- Parameters:
project_name (
str) – name of the project to calculate authors forrevision (
FullCommitHash) – revision to authors commits at
- Return type:
int- Returns:
the number of authors in the project
- varats.project.project_util.calc_project_loc(project_name, revision)[source]¶
Calculate the LOC for a project including submodules at the given revision.
- Parameters:
project_name (
str) – name of the project to calculate LOC forrevision (
FullCommitHash) – revision to calculate LOC at
- Return type:
int- Returns:
the LOC in the project
- varats.project.project_util.is_git_source(source)[source]¶
Checks if given base source is a git source.
- Parameters:
source (
FetchableSource) – base source to check- Return type:
bool- Returns:
true if the base source is a git source, false ow.
- class varats.project.project_util.BinaryType(*values)[source]¶
Bases:
EnumEnum for different binary types.
- value: int¶
- EXECUTABLE = 1¶
- SHARED_LIBRARY = 2¶
- STATIC_LIBRARY = 3¶
- property is_library: bool¶
- class varats.project.project_util.ProjectBinaryWrapper(binary_name, path_to_binary, binary_type, entry_point=None, valid_exit_codes=None)[source]¶
Bases:
objectWraps project binaries which get generated during compilation.
>>> ProjectBinaryWrapper("binary_name", "path/to/binary", BinaryType.EXECUTABLE) (binary_name: path/to/binary | executable)
- property name: str¶
Name of the binary.
- property path: Path¶
Path to the binary location.
- property type: BinaryType¶
Specifies the type, e.g., executable, shared, or static library, of the binary.
- property entry_point: Path | None¶
Entry point to an executable “thing” that executes the wrapped binary, if possible.
- property valid_exit_codes: List[int]¶
Specifies which exit codes indicate a successful execution of the binary.
- exception varats.project.project_util.BinaryNotFound[source]¶
Bases:
CompilationErrorException raised if a binary that should exist was not found.
- static create_error_for_binary(binary)[source]¶
Creates a BinaryNotFound error for a specific binary.
- Parameters:
binary (
ProjectBinaryWrapper) – project binary that was not found- Return type:
- Returns:
initialzied BinaryNotFound error
- varats.project.project_util.verify_binaries(project)[source]¶
Verifies that all binaries for a given project exist.
- Return type:
None
- class varats.project.project_util.RevisionBinaryMap(repo)[source]¶
Bases:
Container[str]A special map that specifies for which revision ranges a binaries is valid.
- specify_binary(location, binary_type, **kwargs)[source]¶
Add a binary to the map.
- Parameters:
location (
str) – where the binary can be found, relative to the project-source rootbinary_type (
BinaryType) – the type of binary that is producedoverride_binary_name – overrides the used binary name
override_entry_point – overrides the executable entry point
only_valid_in – additionally specifies a validity range that specifies in which revision range this binary is produced
- Return type:
- Returns:
self for builder-style usage
- varats.project.project_util.copy_renamed_git_to_dest(src_dir, dest_dir)[source]¶
Renames git files that were made git_storable (e.g., .gitted) back to their original git name and stores the renamed copy at the destination path. The original files stay untouched. Renaming and copying will be skipped if the dest_dir already exists.
- Parameters:
src_dir (
Path) – path to the source directorydest_dir (
Path) – path to the destination directory
- Return type:
None
Module: filesystem_util¶
Utility functions for handling filesystem related tasks.
- exception varats.utils.filesystem_util.FolderAlreadyPresentError(folder)[source]¶
Bases:
ExceptionException raised if an operation could not be performed because a folder was already present, e.g., when creating folders with a script.
- varats.utils.filesystem_util.lock_file(lock_path, lock_mode=2)[source]¶
- Return type:
Generator[None,None,None]
Module: cmake_util¶
CMake utilities.
- varats.tools.research_tools.cmake_util.is_cmake_var_set(var_name)[source]¶
Check if a specific cmake variable is set to ON.
- Parameters:
var_name (
str) – of the cmake variable- Return type:
bool
Returns: true, if the cmake variable is set
- varats.tools.research_tools.cmake_util.set_cmake_var(var_name, value, post_out=<function <lambda>>)[source]¶
Sets a cmake variable in the current cmake config.
- Parameters:
var_name (
str) – of the cmake variablevalue (
str) – to setpost_out (
Callable[[str],None]) – callback to write console output to
- Return type:
None
Logger usage¶
By default, the tool suite logger shows only severity levels from WARNING up to CRITICAL on the console.
The log severity level can be configured by setting the environment variable LOG_LEVEL.
So, for example, to get more information we can set the severity level to info by:
LOG_LEVEL=info vara-buildsetup vara -i
How to add logging to a module¶
For the tool suite, we do module-level logging to make it easier to trace where log output comes from. Hence, every module that logs something needs to set the logger to the current module name like this:
LOG = logging.getLogger(__name__)
What should be logged and how?¶
In general, the tool suite uses print for normal output that should always go to the user. Logging is used to add additional information or highlight warning or error cases. For logging categories, we follow the default python logging HOWTO.
Module: logger_util¶
Utility function for logging.
- varats.utils.logger_util.log_without_linesep(log_func)[source]¶
Wraps the logger function and strips away all trailing whitespace and newline characters, making logs more reable, e.g., for bash and command line tool output.
- Return type:
Callable[[str],None]
Module: tool_util¶
Utilities for tool handling.
- varats.tools.tool_util.get_research_tool_type(name)[source]¶
Look up the type of a research tool by name.
- Parameters:
name (
str) – of the research tool- Return type:
Union[Type[VaRA],Type[Phasar],Type[SZZUnleashed]]
Returns: the research tool type corresponding to
name
- varats.tools.tool_util.get_research_tool(name, source_location=None)[source]¶
Look up a research tool by name.
- Parameters:
name (
str) – of the research toolsource_location (
Optional[Path]) – of the research tool, ifNoneis provided the location saved in the config will be used
- Return type:
ResearchTool[Any]- Returns:
the research tool with the specified
name, otherwise, raises LookupError