def as_dict(self) -> Dict[str, Any]: """Get the dictionary representation of this build variant.""" obj: Dict[str, Any] = { "name": self.name, "tasks": self.__get_task_specs(frozenset(self.tasks)) + self.__get_task_specs(frozenset(self.task_groups)) + self.__get_task_specs(frozenset(self.existing_tasks)), } if self.display_tasks: obj["display_tasks"] = sorted( [dt.as_dict() for dt in self.display_tasks], key=lambda d: d["name"]) add_existing_from_dict( obj, { "expansions": self.expansions, "run_on": self.run_on, "modules": self.modules, "display_name": self.display_name, "batch_time": self.batch_time, }, ) return obj
def test_add_a_mix_of_items(self): obj = {} under_test.add_existing_from_dict( obj, { "item 1": "an item", "item 2": None, "item 3": [], "item 4": "another item" }) assert obj == {"item 1": "an item", "item 4": "another item"}
def shell_exec( script: str, working_dir: Optional[str] = None, background: Optional[bool] = None, silent: Optional[bool] = None, continue_on_err: Optional[bool] = None, system_log: Optional[bool] = None, shell: Optional[str] = None, ignore_stdout: Optional[bool] = None, ignore_stderr: Optional[bool] = None, redirect_stderr_to_stdout: Optional[bool] = None, ) -> BuiltInCommand: """ Create an Evergreen command to parse go test results. :param script: the scripts to run. :param working_dir: the directory to execute the shell script in. :param background: If set to true does not wait for script to exit before running the next command. :param silent: If set to true does not log any shell output during execution. :param continue_on_err: if set to true causes command to exit with success regardless of the script's exit code. :param system_log: If set to true the script's output will be written to the task's system logs. :param shell: Shell to use, defaults to sh. :param ignore_stdout: If true discard output sent to stdout. :param ignore_stderr: If true discard output sent to stderr. :param redirect_stderr_to_stdout: If true sends stderr to stdout. """ params = { "script": script, } add_existing_from_dict( params, { "working_dir": working_dir, "background": background, "silent": silent, "continue_on_err": continue_on_err, "system_log": system_log, "shell": shell, "ignore_standard_out": ignore_stdout, "ignore_standard_error": ignore_stderr, "redirect_standard_error_to_output": redirect_stderr_to_stdout, }, ) return BuiltInCommand("shell.exec", params)
def as_dict(self) -> Dict[str, Any]: """Get a dictionary representation of this task group.""" obj = { "name": self.name, "tasks": sorted([task.name for task in self.tasks]) } add_existing_from_dict( obj, { "max_hosts": self.max_hosts, "setup_group": self.__cmd_list_as_dict(self.setup_group), "setup_task": self.__cmd_list_as_dict(self.setup_task), "teardown_group": self.__cmd_list_as_dict(self.teardown_group), "teardown_task": self.__cmd_list_as_dict(self.teardown_task), "setup_group_can_fail_task": self.setup_group_can_fail_task, "setup_group_timeout_secs": self.setup_group_timeout_secs, }, ) return obj
def s3_get( aws_key: str, aws_secret: str, remote_file: str, bucket: str, local_file: Optional[str] = None, extract_to: Optional[str] = None, build_variants: Optional[Sequence[str]] = None, ) -> BuiltInCommand: """ Create an Evergreen command to download a file from Amazon s3. :param aws_key: AWS key (use expansion to keep this a secret). :param aws_secret: AWS secret (use expansion to keep this a secret). :param local_file: The local file to save, do not use with extract_to. :param extract_to: The local directory to extract to, do not use with local_file. :param remote_file: The S3 path to get the file from. :param bucket: The S3 bucket to use. :param build_variants: List of build variants to run command for. """ if bool(local_file) == bool(extract_to): raise TypeError( "Either 'local_file' or 'extract_to' must be used, but not both.") params = { "aws_key": aws_key, "aws_secret": aws_secret, "remote_file": remote_file, "bucket": bucket, } add_existing_from_dict( params, { "local_file": local_file, "extract_to": extract_to, "build_variants": build_variants }, ) return BuiltInCommand("s3.get", params)
def as_dict(self) -> Dict[str, Dict[str, str]]: """Get a dictionary representing this command.""" obj = { "source": { "bucket": self.source_bucket, "path": self.source_path }, "destination": { "bucket": self.destination_bucket, "path": self.destination_path }, } add_existing_from_dict( obj, { "display_name": self.display_name, "optional": self.optional, "build_variants": self.build_variants, }, ) return obj
def subprocess_scripting( harness: ScriptingHarness, command: Optional[str] = None, args: Optional[Sequence[str]] = None, cache_duration_secs: Optional[int] = None, cleanup_harness: Optional[bool] = None, lock_file: Optional[str] = None, packages: Optional[Sequence[str]] = None, harness_path: Optional[str] = None, silent: Optional[bool] = None, system_log: Optional[bool] = None, working_dir: Optional[str] = None, ignore_stdout: Optional[bool] = None, ignore_stderr: Optional[bool] = None, redirect_stderr_to_stdout: Optional[bool] = None, continue_on_err: Optional[bool] = None, add_expansions_to_env: Optional[bool] = None, include_expansions_in_env: Optional[Sequence[str]] = None, add_to_path: Optional[Sequence[str]] = None, ) -> BuiltInCommand: """ Create an Evergreen command to run a command inside of a script environment. :param harness: Type of scripting harness to use. :param command: Command line arguments. :param args: List of strings to run as a command in the environment. :param cache_duration_secs: The duration to cache the configuration. :param cleanup_harness: If True cleanup harness after command exits. :param lock_file: Specifies dependencies in a lock file. :param packages: List of packages that will be installed in the environment. :param harness_path: Path within working directory where harness will be located. :param silent: Do not log output of command. :param continue_on_err: if set to true causes command to exit with success regardless of the script's exit code. :param system_log: If set to true the script's output will be written to the task's system logs. :param working_dir: Working directory to start shell in. :param ignore_stdout: If true discard output sent to stdout. :param ignore_stderr: If true discard output sent to stderr. :param redirect_stderr_to_stdout: If True sends stderr to stdout. :param add_expansions_to_env: If True add all expansions to the command's environment. :param include_expansions_in_env: Specify expansions to add to the command's environment. :param add_to_path: Paths to prepend to the PATH environment variable. """ params = { "harness": harness.value, } add_existing_from_dict( params, { "command": command, "args": args, "cache_duration_secs": cache_duration_secs, "cleanup_harness": cleanup_harness, "lock_file": lock_file, "packages": packages, "harness_path": harness_path, "working_dir": working_dir, "silent": silent, "continue_on_err": continue_on_err, "system_log": system_log, "ignore_standard_out": ignore_stdout, "ignore_standard_error": ignore_stderr, "redirect_standard_error_to_output": redirect_stderr_to_stdout, "add_expansions_to_env": add_expansions_to_env, "include_expansions_in_env": include_expansions_in_env, "add_to_path": add_to_path, }, ) return BuiltInCommand("subprocess.scripting", params)
def subprocess_exec( binary: Optional[str] = None, args: Optional[Sequence[str]] = None, env: Optional[Dict[str, str]] = None, command: Optional[str] = None, background: Optional[bool] = None, silent: Optional[bool] = None, system_log: Optional[bool] = None, working_dir: Optional[str] = None, ignore_stdout: Optional[bool] = None, ignore_stderr: Optional[bool] = None, redirect_stderr_to_stdout: Optional[bool] = None, continue_on_err: Optional[bool] = None, add_expansions_to_env: Optional[bool] = None, include_expansions_in_env: Optional[Sequence[str]] = None, add_to_path: Optional[Sequence[str]] = None, ) -> BuiltInCommand: """ Create an Evergreen command to run a shell command. :param binary: A binary to run. :param args: List of arguments to the binary. :param env: Map of environment variables and their values. :param command: A command string (cannot use with `binary` or `args`). :param background: If True immediately return to caller. :param silent: Do not log output of command. :param continue_on_err: if set to true causes command to exit with success regardless of the script's exit code. :param system_log: If set to true the script's output will be written to the task's system logs. :param working_dir: Working directory to start shell in. :param ignore_stdout: If true discard output sent to stdout. :param ignore_stderr: If true discard output sent to stderr. :param redirect_stderr_to_stdout: If True sends stderr to stdout. :param add_expansions_to_env: If True add all expansions to the command's environment. :param include_expansions_in_env: Specify expansions to add to the command's environment. :param add_to_path: Paths to prepend to the PATH environment variable. """ if bool(binary) == bool(command): raise TypeError( "Either 'binary' or 'command' must be specified but not both.") if args and command: raise TypeError("'args' cannot be specified with 'command'.") params: Dict[str, Any] = {} add_existing_from_dict( params, { "binary": binary, "args": args, "env": env, "command": command, "working_dir": working_dir, "background": background, "silent": silent, "continue_on_err": continue_on_err, "system_log": system_log, "ignore_standard_out": ignore_stdout, "ignore_standard_error": ignore_stderr, "redirect_standard_error_to_output": redirect_stderr_to_stdout, "add_expansions_to_env": add_expansions_to_env, "include_expansions_in_env": include_expansions_in_env, "add_to_path": add_to_path, }, ) return BuiltInCommand("subprocess.exec", params)
def s3_put( aws_key: str, aws_secret: str, remote_file: str, bucket: str, permissions: str, content_type: str, local_file: Optional[str] = None, optional: Optional[bool] = None, display_name: Optional[str] = None, local_files_include_filter: Optional[Sequence[str]] = None, local_files_include_filter_prefix: Optional[str] = None, visibility: Optional[S3Visibility] = None, ) -> BuiltInCommand: """ Upload a file to Amazon S3. :param aws_key: AWS key (use expansion to keep this a secret). :param aws_secret: AWS secret (use expansion to keep this a secret). :param local_file: The local file to save, do not use with extract_to. :param remote_file: The S3 path to get the file from. :param bucket: The S3 bucket to use. :param permissions: The permissions string to upload with. :param content_type: The MIME type of the file. :param optional: Indicates if failure to fine of upload will result in task failure. :param display_name: The display string for the file in Evergreen. :param local_files_include_filter: An array of globs to include in the put. :param local_files_include_filter_prefix: An optional start path for local_files_include_filter. :param visibility: Visibility of the uploaded files. """ if local_files_include_filter: if local_file is not None: raise TypeError( "'local_file' cannot be used with 'local_files_include_filter'" ) if optional is not None: raise TypeError( "'optional' cannot be used with 'local_files_include_filter'") else: if local_file is None: raise TypeError( "Either 'local_file' or 'local_files_include_filter' must be used" ) if local_files_include_filter_prefix is not None: raise TypeError( "'local_file_include_filter_prefix' cannot be used with 'local_file'" ) params = { "aws_key": aws_key, "aws_secret": aws_secret, "remote_file": remote_file, "bucket": bucket, "content_type": content_type, "permissions": permissions, } add_existing_from_dict( params, { "local_file": local_file, "optional": optional, "display_name": display_name, "local_files_include_filter": local_files_include_filter, "local_files_include_filter_prefix": local_files_include_filter_prefix, "visibility": visibility, }, ) return BuiltInCommand("s3.put", params)