Skip to content

Latest commit

 

History

History
321 lines (189 loc) · 9.96 KB

universal_build.build_utils.md

File metadata and controls

321 lines (189 loc) · 9.96 KB

module universal_build.build_utils

Universal build utilities.

Global Variables

  • 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

function log

log(message: str) → None

Log message to stdout.

Args:

  • message (str): Message to log.

function command_exists

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): If True, no message will be logged in case the command does not exist. Default is False.
  • exit_on_error (bool, optional): Exit process if the command does not exist. Defaults to False.

Returns:

  • bool: True if the commend exist and is executable.

function parse_arguments

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.

function create_git_tag

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 the git tag or the git push tag command. If push is set to true, the CompletedProcess of git tag is returned if it failed, otherwise the CompletedProcess object from the git push tag command is returned.

function build

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.

function run

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

function exit_process

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.


function replace_in_files

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): If True, apply the find string as a regex notation. Defaults to False.
  • exit_on_error (bool, optional): If True, exit process as soon as error occures. Defaults to True.

function get_latest_version

get_latest_version() → Union[str, NoneType]

Returns the latest version based on Git tags.


function duplicate_folder

duplicate_folder(
    src_path: str,
    target_path: str,
    preserve_target: bool = False,
    exit_on_error: bool = True
) → bool

Deprecated. Use build_utils.copy instead.


function copy

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): If True, 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): If True, exit process as soon as error occures. Defaults to True.

Returns:

  • bool: Returns True if the copy process was successful and False otherwise; if exit_on_error is True, the process exists instead of returning False.

This file was automatically generated via lazydocs.