Ejemplo n.º 1
0
    def __init__(self, paths: List[str], in_folder, check_existence=True):
        """Initiate NbArtifacts

        :param paths: list of paths
        :param check_existence: check the paths exist
        :param in_folder: The folder that all paths should be in (or subfolder).
        :raises IOError: if check_existence and file does not exist
        """
        self.paths = [Path(p).absolute() for p in paths]
        self.in_folder = Path(in_folder).absolute()
        to_relative_paths(self.paths, self.in_folder, check_existence=check_existence)
Ejemplo n.º 2
0
def copy_assets(record, folder):
    """Copy notebook assets to the folder the notebook will be executed in."""
    asset_files = []
    relative_paths = to_relative_paths(record.assets, Path(record.uri).parent)
    for path, rel_path in zip(record.assets, relative_paths):
        temp_file = Path(folder).joinpath(rel_path)
        temp_file.parent.mkdir(parents=True, exist_ok=True)
        shutil.copyfile(path, temp_file)
        asset_files.append(temp_file)
    return asset_files
Ejemplo n.º 3
0
    def __init__(
        self,
        paths: List[str],
        in_folder,
        check_existence=True,
        skip_patterns=ARTIFACT_SKIP_PATTERNS,
    ):
        """Initiate NbArtifacts

        :param paths: list of paths
        :param check_existence: check the paths exist
        :param in_folder: The folder that all paths should be in (or subfolder).
        :param skip_patterns: Exclude paths that contain one of these patterns
        :raises IOError: if check_existence and file does not exist
        """

        def path_not_in_skip_artifacts(path):
            return all(pattern not in str(path) for pattern in skip_patterns)

        paths = list(filter(path_not_in_skip_artifacts, paths))
        self.paths = [Path(p).absolute() for p in paths]
        self.in_folder = Path(in_folder).absolute()
        to_relative_paths(self.paths, self.in_folder, check_existence=check_existence)
 def relative_paths(self) -> List[Path]:
     """Return the list of paths (relative to the notebook folder)."""
     return to_relative_paths(self.paths, self.in_folder)