示例#1
0
def test_build_with_docker_failures(mocker):
    '''
    Failure cases for build_with_docker
    '''
    output_folder = "condabuild"
    arg_strings = ["path/to/my_script.py", "--docker_build", "my-env.yaml"]

    mocker.patch('os.system', return_value=1)

    with pytest.raises(OpenCEError) as exc:
        docker_build.build_with_docker(output_folder, arg_strings)
    assert "Failure building image" in str(exc.value)
示例#2
0
def test_build_with_docker(mocker):
    '''
    Simple test for build_with_docker
    '''
    image_name = "my_image"
    output_folder = "condabuild"
    arg_strings = ["path/to/my_script.py", "--docker_build", "my-env.yaml"]

    mocker.patch('docker_build._build_image', return_value=(0, image_name))

    mocker.patch('docker_build.build_in_container', return_value=0)

    docker_build.build_with_docker(output_folder, arg_strings)
示例#3
0
def build_env(arg_strings=None):
    '''
    Entry function.
    '''
    parser = make_parser()
    args = parser.parse_args(arg_strings)

    if args.docker_build:
        return docker_build.build_with_docker(args.output_folder, sys.argv)

    result = 0

    common_package_build_args = []
    common_package_build_args += [
        "--output_folder",
        os.path.abspath(args.output_folder)
    ]
    common_package_build_args += [
        "--channel", os.path.abspath(args.output_folder)
    ]
    common_package_build_args += [
        "--conda_build_config",
        os.path.abspath(args.conda_build_config)
    ]

    for channel in args.channels_list:
        common_package_build_args += ["--channels", channel]

    # If repository_folder doesn't exist, create it
    if args.repository_folder and not os.path.exists(args.repository_folder):
        os.mkdir(args.repository_folder)

    # Create the build tree
    try:
        build_tree = BuildTree(
            env_config_files=args.env_config_file,
            python_versions=utils.parse_arg_list(args.python_versions),
            build_types=utils.parse_arg_list(args.build_types),
            repository_folder=args.repository_folder,
            git_location=args.git_location,
            git_tag_for_env=args.git_tag_for_env,
            conda_build_config=args.conda_build_config)
    except OpenCEError as err:
        print(err.msg)
        return 1

    # Build each package in the packages list
    for build_command in build_tree:
        build_args = common_package_build_args + build_command.feedstock_args()
        result = build_feedstock.build_feedstock(build_args)
        if result != 0:
            print("Unable to build recipe: " + build_command.repository)
            return result

    return result
示例#4
0
def test_build_with_docker_failures(mocker, capsys):
    '''
    Failure cases for build_with_docker
    '''
    image_name = "my_image"
    output_folder = "condabuild"
    arg_strings = ["path/to/my_script.py", "--docker_build", "my-env.yaml"]

    mocker.patch('docker_build.build_image', return_value=(1, image_name))

    assert docker_build.build_with_docker(output_folder, arg_strings) == 1
    captured = capsys.readouterr()
    assert "Failure building image" in captured.out
示例#5
0
def build_env(arg_strings=None):
    '''
    Entry function.
    '''
    parser = make_parser()
    args = parser.parse_args(arg_strings)

    if args.docker_build:
        return docker_build.build_with_docker(args.output_folder, sys.argv)

    # Checking conda-build existence if --docker_build is not specified
    utils.check_if_conda_build_exists()

    # Here, importing BuildTree is intentionally done after checking
    # existence of conda-build as BuildTree uses conda_build APIs.
    from build_tree import BuildTree  # pylint: disable=import-outside-toplevel

    result = 0

    common_package_build_args = []
    common_package_build_args += [
        "--output_folder",
        os.path.abspath(args.output_folder)
    ]
    common_package_build_args += [
        "--channel", os.path.abspath(args.output_folder)
    ]
    common_package_build_args += [
        "--conda_build_config",
        os.path.abspath(args.conda_build_config)
    ]

    for channel in args.channels_list:
        common_package_build_args += ["--channels", channel]

    # If repository_folder doesn't exist, create it
    if args.repository_folder and not os.path.exists(args.repository_folder):
        os.mkdir(args.repository_folder)

    # Create the build tree
    try:
        build_tree = BuildTree(
            env_config_files=args.env_config_file,
            python_versions=utils.parse_arg_list(args.python_versions),
            build_types=utils.parse_arg_list(args.build_types),
            repository_folder=args.repository_folder,
            git_location=args.git_location,
            git_tag_for_env=args.git_tag_for_env,
            conda_build_config=args.conda_build_config)
    except OpenCEError as err:
        print(err.msg)
        return 1

    # Build each package in the packages list
    for build_command in build_tree:
        build_args = common_package_build_args + build_command.feedstock_args()
        result = build_feedstock.build_feedstock(build_args)
        if result != 0:
            print("Unable to build recipe: " + build_command.repository)
            return result

    return result
示例#6
0
def build_env(arg_strings=None):
    '''
    Entry function.
    '''
    parser = make_parser()
    args = parser.parse_args(arg_strings)

    if args.docker_build:
        docker_build.build_with_docker(args.output_folder, sys.argv)
        return

    # Checking conda-build existence if --docker_build is not specified
    utils.check_if_conda_build_exists()

    # Here, importing BuildTree is intentionally done after checking
    # existence of conda-build as BuildTree uses conda_build APIs.
    from build_tree import BuildTree  # pylint: disable=import-outside-toplevel

    common_package_build_args = []
    common_package_build_args += [
        "--output_folder",
        os.path.abspath(args.output_folder)
    ]
    common_package_build_args += [
        "--channel", os.path.abspath(args.output_folder)
    ]
    common_package_build_args += [
        "--conda_build_config",
        os.path.abspath(args.conda_build_config)
    ]

    for channel in args.channels_list:
        common_package_build_args += ["--channels", channel]

    # If repository_folder doesn't exist, create it
    if args.repository_folder and not os.path.exists(args.repository_folder):
        os.mkdir(args.repository_folder)

    # Create the build tree
    build_tree = BuildTree(env_config_files=args.env_config_file,
                           python_versions=utils.parse_arg_list(
                               args.python_versions),
                           build_types=utils.parse_arg_list(args.build_types),
                           mpi_types=utils.parse_arg_list(args.mpi_types),
                           repository_folder=args.repository_folder,
                           git_location=args.git_location,
                           git_tag_for_env=args.git_tag_for_env,
                           conda_build_config=args.conda_build_config)

    conda_env_data = CondaEnvFileGenerator(
        python_versions=args.python_versions,
        build_types=args.build_types,
        mpi_types=args.mpi_types,
        channels=args.channels_list,
        output_folder=os.path.abspath(args.output_folder),
    )

    # Build each package in the packages list
    for build_command in build_tree:
        build_args = common_package_build_args + build_command.feedstock_args()
        try:
            build_feedstock.build_feedstock(build_args)
        except OpenCEError as exc:
            raise OpenCEError(Error.BUILD_RECIPE, build_command.repository,
                              exc.msg) from exc

        conda_env_data.update_conda_env_file_content(build_command, build_tree)

    conda_env_files = conda_env_data.write_conda_env_files()
    print(
        "Generated conda environment files from the selected build arguments:",
        conda_env_files)
    print("INFO: One can use these environment files to create a conda" \
          " environment using \"conda env create -f <conda_env_file_name>.\"")
示例#7
0
def build_env(args):
    '''Entry Function'''
    if args.docker_build:
        if len(args.cuda_versions.split(',')) > 1:
            raise OpenCEError(Error.TOO_MANY_CUDA)
        docker_build.build_with_docker(os.path.abspath(args.output_folder),
                                       args.build_types, args.cuda_versions,
                                       sys.argv)
        for conda_env_file in glob.glob(
                os.path.join(args.output_folder, "*.yaml")):
            utils.replace_conda_env_channels(
                conda_env_file,
                os.path.abspath(
                    os.path.join(docker_build.HOME_PATH,
                                 utils.DEFAULT_OUTPUT_FOLDER)),
                os.path.abspath(args.output_folder))
        return

    # Checking conda-build existence if --docker_build is not specified
    utils.check_if_conda_build_exists()

    # Here, importing BuildTree is intentionally done after checking
    # existence of conda-build as BuildTree uses conda_build APIs.
    from build_tree import BuildTree  # pylint: disable=import-outside-toplevel

    # If repository_folder doesn't exist, create it
    if args.repository_folder and not os.path.exists(args.repository_folder):
        os.mkdir(args.repository_folder)

    variants = utils.make_variants(args.python_versions, args.build_types,
                                   args.mpi_types, args.cuda_versions)
    validate_config.validate_env_config(args.conda_build_config,
                                        args.env_config_file, variants,
                                        args.repository_folder)

    # Create the build tree
    build_tree = BuildTree(
        env_config_files=args.env_config_file,
        python_versions=inputs.parse_arg_list(args.python_versions),
        build_types=inputs.parse_arg_list(args.build_types),
        mpi_types=inputs.parse_arg_list(args.mpi_types),
        cuda_versions=inputs.parse_arg_list(args.cuda_versions),
        repository_folder=args.repository_folder,
        git_location=args.git_location,
        git_tag_for_env=args.git_tag_for_env,
        conda_build_config=args.conda_build_config,
        test_labels=inputs.parse_arg_list(args.test_labels))

    # Generate conda environment files
    conda_env_files = build_tree.write_conda_env_files(
        channels=args.channels_list,
        output_folder=os.path.abspath(args.output_folder),
        path=os.path.abspath(args.output_folder))
    print(
        "Generated conda environment files from the selected build arguments:",
        conda_env_files.values())
    print("INFO: One can use these environment files to create a conda" \
          " environment using \"conda env create -f <conda_env_file_name>.\"")

    if not args.skip_build_packages:
        # Build each package in the packages list
        for build_command in build_tree:
            if not _all_outputs_exist(args.output_folder,
                                      build_command.output_files):
                try:
                    print("Building " + build_command.recipe)
                    build_feedstock.build_feedstock_from_command(
                        build_command,
                        output_folder=os.path.abspath(args.output_folder),
                        extra_channels=[os.path.abspath(args.output_folder)] +
                        args.channels_list,
                        conda_build_config=os.path.abspath(
                            args.conda_build_config))
                except OpenCEError as exc:
                    raise OpenCEError(Error.BUILD_RECIPE,
                                      build_command.repository,
                                      exc.msg) from exc
            else:
                print("Skipping build of " + build_command.recipe +
                      " because it already exists")

    if args.run_tests:
        _run_tests(build_tree, conda_env_files)