예제 #1
0
    def test_release_with_invalid_version_in_main_branch(self):
        with pytest.raises(SystemExit) as pytest_wrapped_e:
            build_utils.parse_arguments([
                f"--{build_utils.FLAG_RELEASE}",
                f"--{build_utils.FLAG_TEST}",
                f"--{build_utils.FLAG_MAKE}",
                f"--{build_utils.FLAG_VERSION}=foo",
            ])

        assert pytest_wrapped_e.type == SystemExit
        assert pytest_wrapped_e.value.code == build_utils.EXIT_CODE_INVALID_VERSION
예제 #2
0
    def test_release_with_already_existing_version(self):
        with pytest.raises(SystemExit) as pytest_wrapped_e:
            build_utils.parse_arguments([
                f"--{build_utils.FLAG_RELEASE}",
                f"--{build_utils.FLAG_TEST}",
                f"--{build_utils.FLAG_MAKE}",
                f"--{build_utils.FLAG_VERSION}=1.0.0",
            ])

        assert pytest_wrapped_e.type == SystemExit
        assert pytest_wrapped_e.value.code == build_utils.EXIT_CODE_INVALID_VERSION
예제 #3
0
def parse_arguments(
    input_args: List[str] = None, argument_parser: argparse.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.
    """
    if argument_parser is None:
        argument_parser = argparse.ArgumentParser()

    argument_parser.add_argument(
        "--" + FLAG_DOCKER_IMAGE_PREFIX.replace("_", "-"),
        help="Provide a prefix for a Docker image, e.g. 'mltooling/' or even a repository path. When leaving blank, the default Dockerhub Repository is used.",
        required=False,
        default="",
    )

    return build_utils.parse_arguments(
        input_args=input_args, argument_parser=argument_parser
    )
예제 #4
0
 def test_build_with_force_with_version(self):
     sanitized_args = build_utils.parse_arguments([
         f"--{build_utils.FLAG_MAKE}",
         f"--{build_utils.FLAG_FORCE}",
         "--version=1.1.0",
     ])
     assert sanitized_args[build_utils.FLAG_VERSION] == "1.1.0"
예제 #5
0
def parse_arguments(input_args: List[str] = None,
                    argument_parser: argparse.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.
    """
    if argument_parser is None:
        argument_parser = argparse.ArgumentParser()

    argument_parser.add_argument(
        "--" + FLAG_PYPI_TOKEN.replace("_", "-"),
        help="Personal access token for PyPI account.",
        required=False,
        default="",
    )
    argument_parser.add_argument(
        "--" + FLAG_PYPI_REPOSITORY.replace("_", "-"),
        help="PyPI repository for publishing artifacts.",
        required=False,
        default="",
    )

    return build_utils.parse_arguments(input_args=input_args,
                                       argument_parser=argument_parser)
예제 #6
0
 def test_release(self):
     sanitized_arguments = build_utils.parse_arguments([
         f"--{build_utils.FLAG_RELEASE}",
         f"--{build_utils.FLAG_TEST}",
         f"--{build_utils.FLAG_MAKE}",
         f"--{build_utils.FLAG_VERSION}={valid_patch_version}",
     ])
     assert isinstance(sanitized_arguments[build_utils.FLAG_VERSION], str)
     assert sanitized_arguments[
         build_utils.FLAG_VERSION] == valid_patch_version
예제 #7
0
from universal_build import build_utils
from universal_build.helpers import build_docker

REMOTE_IMAGE_PREFIX = "mltooling/"
FLAG_FLAVOR = "flavor"
IMAGE_NAME = "ml-workspace"

parser = argparse.ArgumentParser(add_help=False)
parser.add_argument(
    "--" + FLAG_FLAVOR,
    help="Flavor (gpu-11.3) used for docker container",
    default="all",
)

args = build_utils.parse_arguments(argument_parser=parser)

VERSION = str(args.get(build_utils.FLAG_VERSION))
docker_image_prefix = args.get(build_docker.FLAG_DOCKER_IMAGE_PREFIX)

if not docker_image_prefix:
    docker_image_prefix = REMOTE_IMAGE_PREFIX

if not args.get(FLAG_FLAVOR):
    args[FLAG_FLAVOR] = "all"

flavor = str(args[FLAG_FLAVOR]).lower().strip()

if flavor == "all":
    args[FLAG_FLAVOR] = "gpu-11.3"
    build_utils.build(".", args)
예제 #8
0
from universal_build import build_utils
from universal_build.helpers import build_docker

COMPONENT_NAME = "simple-demo-job"

args = build_utils.parse_arguments()
if args[build_utils.FLAG_MAKE]:
    completed_process = build_docker.build_docker_image(
        COMPONENT_NAME, args[build_utils.FLAG_VERSION])
    if completed_process.returncode > 0:
        build_utils.exit_process(completed_process.returncode)

if args[build_utils.FLAG_RELEASE]:
    completed_process = build_docker.release_docker_image(
        COMPONENT_NAME, args[build_utils.FLAG_VERSION],
        args[build_docker.FLAG_DOCKER_IMAGE_PREFIX])
예제 #9
0
    def test_release_without_version(self):
        with pytest.raises(SystemExit) as pytest_wrapped_e:
            build_utils.parse_arguments([f"--{build_utils.FLAG_RELEASE}"])

        assert pytest_wrapped_e.type == SystemExit
        assert pytest_wrapped_e.value.code == build_utils.EXIT_CODE_INVALID_ARGUMENTS