def copy_artifacts()

in model-archiver/model_archiver/model_packaging_utils.py [0:0]


    def copy_artifacts(model_name, **kwargs):
        """
        copy model artifacts in a common model directory for archiving
        :param model_name: name of model being archived
        :param kwargs: key value pair of files to be copied in archive
        :return:
        """
        model_path = os.path.join(tempfile.gettempdir(), model_name)
        if os.path.exists(model_path):
            shutil.rmtree(model_path)
        ModelExportUtils.make_dir(model_path)
        for file_type, path in kwargs.items():
            if path:
                if file_type == "handler":
                    if path in model_handlers.keys():
                        continue

                    if '.py' not in path:
                        path = (path.split(':')[0] if ':' in path else path) + '.py'

                if file_type == "extra_files":
                    for file in path.split(","):
                        if os.path.isfile(file):
                            shutil.copy2(file, model_path)
                        elif os.path.isdir(file) and file != model_path:
                            for item in os.listdir(file):
                                src = os.path.join(file, item)
                                dst = os.path.join(model_path, item)
                                if os.path.isfile(src):
                                    shutil.copy2(src, dst)
                                elif os.path.isdir(src):
                                    shutil.copytree(src, dst, False, None)
                        else:
                            raise ValueError(f"Invalid extra file given {file}")
                else:
                    shutil.copy(path, model_path)

        return model_path