Ml build utilities.
- FLAG_MAKE
- FLAG_TEST
- FLAG_TEST_MARKER
- FLAG_RELEASE
- FLAG_VERSION
- FLAG_CHECK
- FLAG_RUN
- FLAG_FORCE
- TEST_MARKER_SLOW
- EXIT_CODE_GENERAL
- EXIT_CODE_INVALID_VERSION
- EXIT_CODE_NO_VERSION_FOUND
- EXIT_CODE_VERSION_IS_REQUIRED
- EXIT_CODE_DEV_VERSION_REQUIRED
- EXIT_CODE_DEV_VERSION_NOT_MATCHES_BRANCH
- EXIT_CODE_INVALID_ARGUMENTS
log(message: str) → None
Log message to stdout.
Args:
message
(str): Message to log.
command_exists(
command: str,
silent: bool = False,
exit_on_error: bool = False
) → bool
Checks whether the command
exists and is marked as executable.
Args:
command
(str): Command to check.silent
(bool): IfTrue
, no message will be logged in case the command does not exist. Default isFalse
.exit_on_error
(bool, optional): Exit process if the command does not exist. Defaults toFalse
.
Returns:
bool
:True
if the commend exist and is executable.
parse_arguments(
input_args: List[str] = None,
argument_parser: ArgumentParser = None
) → dict
Parses all arguments and returns a sanitized & augmented list of arguments.
Sanitized means that, for example, the version is already checked and set depending on our build guidelines. If arguments are not valid, exit the script run.
Args:
input_args
(List[str], optional): List of arguments that are used instead of the arguments passed to the process. Defaults to None.argument_parser
(arparse.ArgumentParser, optional): An argument parser which is passed as a parents parser to the default ArgumentParser to be able to use additional flags besides the default ones.
Returns:
dict
: The parsed default arguments thar are already checked for validity.
create_git_tag(
version: str,
push: bool = False,
force: bool = False,
exit_on_error: bool = False
) → CompletedProcess
Create an annotated git tag in the current HEAD via git tag
and the provided version.
The version will be prefixed with 'v'. If push is set, the tag is pushed to remote but only if the previous git tag
command was successful.
Args:
version
(str): The tag to be created. Will be prefixed with 'v'.push
(bool, optional): If true, push the tag to remote. Defaults to False.force
(bool, optional): If true, force the tag to be created. Defaults to False.exit_on_error
(bool): Exit program if the tag creation fails.
Returns:
subprocess.CompletedProcess
: Returns the CompletedProcess object of either thegit tag
or thegit push tag
command. Ifpush
is set to true, the CompletedProcess ofgit tag
is returned if it failed, otherwise the CompletedProcess object from thegit push tag
command is returned.
build(component_path: str, args: Dict[str, Union[str, bool, List[str]]]) → None
Run the build logic of the specified component, except if the path is a (sub-)path in skipped-paths.
Args:
component_path
(str): The path of the component to be built. The path must contain a build.py file.args
(Dict): The arguments to be passed to the component's build.py file. The default arguments that were used to call this script are passed down to the component.
run(
command: str,
disable_stdout_logging: bool = False,
disable_stderr_logging: bool = False,
exit_on_error: bool = True,
timeout: Optional[int] = None
) → CompletedProcess
Run a specified command.
Args:
command
(str): The shell command that is executed via subprocess.Popen.disable_stdout_logging
(bool): Disable stdout logging when it is too much or handled by the caller.exit_on_error
(bool): Exit program if the exit code of the command is not 0.timeout
(Optional[int]): If the process does not terminate after timeout seconds, raise a TimeoutExpired exception.
Returns:
subprocess.CompletedProcess
: State
exit_process(code: int = 0) → None
Exit the process with exit code.
sys.exit
seems to be a bit unreliable, process just sleeps and does not exit. So we are using os._exit instead and doing some manual cleanup.
replace_in_files(
find: str,
replace: str,
file_paths: List[str],
regex: bool = False,
exit_on_error: bool = True
) → None
Replaces a string or regex occurence in a collection of files.
Args:
find
(str): A string to find and replace in the files.replace
(str): The string to replace it with.file_paths
(List[str]): Collection of file paths.regex
(bool, optional): IfTrue
, apply the find string as a regex notation. Defaults toFalse
.exit_on_error
(bool, optional): IfTrue
, exit process as soon as error occures. Defaults to True.
get_latest_version() → Union[str, NoneType]
Returns the latest version based on Git tags.
duplicate_folder(
src_path: str,
target_path: str,
preserve_target: bool = False,
exit_on_error: bool = True
) → bool
Deprecated. Use build_utils.copy
instead.
copy(
src_path: str,
target_path: str,
preserve_target: bool = False,
exit_on_error: bool = True
) → bool
Copy the files from source to target.
Depending on the mode, it will either completely replace the target path with the source path or it will copy all files of the source directory to the target directory. If preserve_target
is True
, if a file or directory with the same name exists at the target, it will be deleted first. Required directories will be created at the target so that the structure is preserved.
Example:
copy(
source_path="./temp/generated-openapi-client/src/",
target_path="./webapp/src/services/example-client/"
)
Args:
src_path
(str): Source path to duplicate.target_path
(str): Target path to move the source folder. The existing content in the folder will be deleted.preserve_target
(bool, optional): IfTrue
, the files/directories of the source target will be put into the target path instead of replacing the target directory.exit_on_error
(bool, optional): IfTrue
, exit process as soon as error occures. Defaults to True.
Returns:
bool
: ReturnsTrue
if the copy process was successful andFalse
otherwise; ifexit_on_error
is True, the process exists instead of returningFalse
.
This file was automatically generated via docsai.