def as_dict(self) -> Dict[str, Any]: """Convert the dependency to a dictionary.""" obj = { "name": self.task_name, } add_if_exists(obj, "variant", self.build_variant) return obj
def as_dict(self) -> Dict[str, Any]: """Get a dictionary representing the command.""" obj = { "command": self.command, } add_if_exists(obj, "params", self.params) if self.command_type: obj["type"] = self.command_type.value return obj
def timeout_update( exec_timeout_secs: Optional[TimeoutType] = None, timeout_secs: Optional[TimeoutType] = None) -> BuiltInCommand: """ Create an Evergreen command to set the times of a task from within the task. :param exec_timeout_secs: Maximum amount of time a task may run. :param timeout_secs: Maximum amount of time a task may run without any output to stdout. """ params: Dict[str, Any] = {} add_if_exists(params, "exec_timeout_secs", exec_timeout_secs) add_if_exists(params, "timeout_secs", timeout_secs) return BuiltInCommand("timeout.update", params)
def expansions_write(file: str, redacted: Optional[bool] = None) -> BuiltInCommand: """ Create an Evergreen command to write the task's expansions to a file. :param file: Filename to write expansions to. :param redacted: include redacted project variables. """ params = { "file": file, } add_if_exists(params, "redacted", redacted) return BuiltInCommand("expansions.write", params)
def attach_artifacts(files: Sequence[str], prefix: Optional[str]) -> BuiltInCommand: """ Evergreen command to allow user to add artifacts to the running task. :param files: List of gitignore file globs to include. :param prefix: Path to start processing the files relative to the working directory. :return: Evergreen Command. """ params = { "files": files, } add_if_exists(params, "prefix", prefix) return BuiltInCommand("attach.artifacts", params)
def task_spec(self, distros: Optional[Sequence[str]] = None) -> Dict[str, Any]: """ Create a task spec for this task. A task spec describes how the task should be added to a build variant. :param distros: What distros the task should run on. :return: Dictionary representing task spec. """ obj: Dict[str, Any] = { "name": self.name, } add_if_exists(obj, "distros", distros) return obj
def as_dict(self) -> Dict[str, Any]: """Get a dictionary representing this command.""" obj = { "func": self.name, } return add_if_exists(obj, "vars", self.parameters)
def archive_tarfz_extract(path: str, destination: str, exclude_files: Optional[str]) -> BuiltInCommand: """ Create an Evergreen command to extract files from a gzipped tarball. :param path: The path to the tarball. :param destination: The target directory. :param exclude_files: A list of filename blobs to exclude. :return: Evergreen command. """ params = { "path": path, "destination": destination, } add_if_exists(params, "exclude_files", exclude_files) return BuiltInCommand("archive.targz_extract", params)
def as_dict(self) -> Dict[str, Any]: """ Convert this project configuration to a dictionary. :return: Dictionary of project configuration. """ obj = { "buildvariants": [bv.as_dict() for bv in self.build_variants], "tasks": sorted([task.as_dict() for task in self.all_tasks()], key=lambda t: t["name"]), } add_if_exists( obj, "task_groups", sorted([tg.as_dict() for tg in self.all_task_groups()], key=lambda tg: tg["name"]), ) return obj
def expansions_update( file: str, updates: Optional[Dict[str, str]] = None, ignore_missing_file: Optional[bool] = None) -> BuiltInCommand: """ Create an Evergreen command to Update the task's expansions at runtime. :param file: filename for a yaml file containing expansion updates. :param updates: Key values to add to expansions. :param ignore_missing_file: Do not error if the file is missing. """ params = { "file": file, } add_if_exists(params, "updates", updates) add_if_exists(params, "ignore_missing_file", ignore_missing_file) return BuiltInCommand("expansions.update", params)
def git_get_project( directory: str, token: Optional[str] = None, revisions: Optional[Dict[str, str]] = None) -> BuiltInCommand: """ Create an Evergreen command to clones the tracked project and check current revision. Also, applies patches if the task was created by a patch build. :param directory: Directory to clone into. :param token: Use a token to clone instead of ssh key. :param revisions: Map of revisions to use for modules. """ params = { "directory": directory, } add_if_exists(params, "token", token) add_if_exists(params, "revisions", revisions) return BuiltInCommand("git.get_project", params)
def archive_tarfz_pack( target: str, source_dir: str, include: Sequence[str], exclude_files: Optional[Sequence[str]]) -> BuiltInCommand: """ Create an Evergreen command to create a gzipped tarball. :param target: The tgz file that will be created. :param source_dir: The directory to compress. :param include: A list of blobs to include. :param exclude_files: A list of filename blobs to exclude. :return: Evergreen command. """ params = { "target": target, "source_dir": source_dir, "include": include, } add_if_exists(params, "exclude_files", exclude_files) return BuiltInCommand("archive.targz_pack", params)
def test_value_does_not_exit(self): obj = {} under_test.add_if_exists(obj, "key", None) assert obj == {}
def test_false_values_should_be_added(self): obj = {} under_test.add_if_exists(obj, "key", False) assert obj == {"key": False}
def test_value_does_exist(self): obj = {} under_test.add_if_exists(obj, "key", "value") assert obj == {"key": "value"}