Пример #1
0
def validate_build_tree(tree, external_deps, start_nodes=None):
    '''
    Check a build tree for dependency compatability.
    '''
    packages = [
        package
        for recipe in build_tree.traverse_build_commands(tree, start_nodes)
        for package in recipe.packages
    ]
    channels = {
        channel
        for recipe in build_tree.traverse_build_commands(tree, start_nodes)
        for channel in recipe.channels
    }
    env_channels = {
        channel
        for node in tree.nodes() for channel in node.channels
    }
    deps = build_tree.get_installable_packages(tree, external_deps,
                                               start_nodes, True)

    pkg_args = " ".join([
        "\"{}\"".format(utils.generalize_version(dep)) for dep in deps
        if not utils.remove_version(dep) in packages
    ])
    channel_args = " ".join({
        "-c \"{}\"".format(channel)
        for channel in channels.union(env_channels)
    })

    cli = "conda create --dry-run -n test_conda_dependencies {} {}".format(
        channel_args, pkg_args)
    ret_code, std_out, std_err = utils.run_command_capture(cli)
    if not ret_code:
        raise OpenCEError(Error.VALIDATE_BUILD_TREE, cli, std_out, std_err)
Пример #2
0
def _execute_git_command(repo_path, git_cmd):
    saved_working_directory = os.getcwd()
    os.chdir(repo_path)
    print("--->{}".format(git_cmd))
    result,std_out,_ = utils.run_command_capture(git_cmd, stderr=subprocess.STDOUT)
    os.chdir(saved_working_directory)
    if not result:
        raise Exception("Git command failed: {}\n{}".format(git_cmd, std_out))
    return std_out
Пример #3
0
    def add_licenses(self, conda_env_file):
        """
        Add all of the license information for every package within a given conda
        environment file.
        """
        # Create a conda environment from the provided file
        time_stamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
        conda_env_path = os.path.join(os.getcwd(), "license_env_file_" + time_stamp)
        cli = "conda env create -p {} -f {}".format(conda_env_path, conda_env_file)
        ret_code, std_out, std_err = utils.run_command_capture(cli)
        if not ret_code:
            raise OpenCEError(Error.GET_LICENSES, cli, std_out, std_err)

        # Get all of the licenses from the file
        self._add_licenses_from_environment(conda_env_path)

        # Delete the generated conda environment
        cli = "conda env remove -p {}".format(conda_env_path)
        ret_code, std_out, std_err = utils.run_command_capture(cli)
        if not ret_code:
            raise OpenCEError(Error.GET_LICENSES, cli, std_out, std_err)
Пример #4
0
    def run(self, conda_env_file):
        """
        Runs the test.

        Creates a temporary bash file, and writes the contents to `get_test_command` into it.
        Runs the generated bash file.
        Removes the temporary bash file.

        Args:
            conda_env_file (str): The name of the original conda environment file.
        """
        log.info("Running: %s", self.name)
        start_time = time.time()
        # Create file containing bash commands
        os.makedirs(self.working_dir, exist_ok=True)
        with tempfile.NamedTemporaryFile(mode='w+t',
                                         dir=self.working_dir,
                                         delete=False) as temp:
            temp.write(self.get_test_command(conda_env_file))
            temp_file_name = temp.name

        # Execute file
        retval, stdout, stderr = utils.run_command_capture(
            "bash {}".format(temp_file_name), cwd=self.working_dir)

        # Remove file containing bash commands
        os.remove(temp_file_name)

        result = TestResult(conda_env_file,
                            retval,
                            name=self.name,
                            category=os.path.basename(self.feedstock_dir) +
                            ":" + os.path.basename(conda_env_file),
                            file=self.test_file,
                            stdout=stdout if not retval else None,
                            stderr=stderr if not retval else None,
                            timestamp=start_time,
                            elapsed_sec=time.time() - start_time)

        if not retval:
            log.error(result.display_failed())

        return result
def validate_build_tree(tree, external_deps, start_nodes=None):
    '''
    Check a build tree for dependency compatability.
    '''
    # Importing BuildTree is intentionally done here because it checks for the
    # existence of conda-build as BuildTree uses conda_build APIs.
    from open_ce import build_tree  # pylint: disable=import-outside-toplevel

    packages = [package for recipe in build_tree.traverse_build_commands(tree, start_nodes)
                            for package in recipe.packages]
    channels = {channel for recipe in build_tree.traverse_build_commands(tree, start_nodes) for channel in recipe.channels}
    env_channels = {channel for node in tree.nodes() for channel in node.channels}
    deps = build_tree.get_installable_packages(tree, external_deps, start_nodes, True)

    pkg_args = " ".join(["\"{}\"".format(utils.generalize_version(dep)) for dep in deps
                                                                    if not utils.remove_version(dep) in packages])
    channel_args = " ".join({"-c \"{}\"".format(channel) for channel in channels.union(env_channels)})

    cli = "conda create --dry-run -n test_conda_dependencies {} {}".format(channel_args, pkg_args)
    ret_code, std_out, std_err = utils.run_command_capture(cli)
    if not ret_code:
        raise OpenCEError(Error.VALIDATE_BUILD_TREE, cli, std_out, std_err)
Пример #6
0
    def run(self, conda_env_file):
        """
        Runs the test.

        Creates a temporary bash file, and writes the contents to `get_test_command` into it.
        Runs the generated bash file.
        Removes the temporary bash file.

        Args:
            conda_env_file (str): The name of the original conda environment file.
        """
        print("Running: " + self.name)
        # Create file containing bash commands
        if not os.path.exists(self.working_dir):
            os.mkdir(self.working_dir)
        with tempfile.NamedTemporaryFile(mode='w+t',
                                         dir=self.working_dir,
                                         delete=False) as temp:
            temp.write("set -e\n")
            temp.write(self.get_test_command(conda_env_file))
            temp_file_name = temp.name

        # Execute file
        retval, output, _ = utils.run_command_capture(
            "bash {}".format(temp_file_name),
            stderr=subprocess.STDOUT,
            cwd=self.working_dir)

        # Remove file containing bash commands
        os.remove(temp_file_name)

        result = TestResult(self.name, retval, output)

        if not retval:
            result.display_failed()

        return result