diff --git a/snk/cli/cli.py b/snk/cli/cli.py index 8be59d1..7cea7b4 100644 --- a/snk/cli/cli.py +++ b/snk/cli/cli.py @@ -198,7 +198,7 @@ def copy_resources( self, resources: List[Path], cleanup: bool, - symlink_resources_folder: bool = False + symlink_resources: bool = False ): """ Copy resources to the current working directory. @@ -215,16 +215,15 @@ def copy_resources( """ copied_resources = [] - def copy_resource(src, dst): - if src.is_dir(): + def copy_resource(src, dst, symlink=False): + target_is_directory = src.is_dir() + if symlink: + os.symlink(src, dst, target_is_directory=target_is_directory) + elif target_is_directory: shutil.copytree(src, dst) else: shutil.copy(src, dst) - def symlink_resource(src, dst): - target_is_directory = src.is_dir() - os.symlink(src, dst, target_is_directory=target_is_directory) - def remove_resource(resource: Path): if resource.is_symlink(): resource.unlink() @@ -236,26 +235,33 @@ def remove_resource(resource: Path): try: # resources_folder = self.pipeline.path / 'resources' - destination = Path(".") / 'resources' - if destination.exists(): - typer.secho( - "Resources folder exists! Skipping...\n", - fg=typer.colors.RED, - ) - else: - if resources_folder.exists(): - if symlink_resources_folder: - symlink_resource(resources_folder, destination) - else: - copy_resource(resources_folder, destination) - copied_resources.append(destination) + # destination = Path(".") / 'resources' + # if destination.exists(): + # typer.secho( + # "Resources folder exists! Skipping...\n", + # fg=typer.colors.RED, + # ) + # else: + # if resources_folder.exists(): + # if symlink_resources: + # symlink_resource(resources_folder, destination) + # else: + # copy_resource(resources_folder, destination) + # copied_resources.append(destination) + if resources_folder.exists(): + resources.insert(0, Path('resources')) for resource in resources: abs_path = self.pipeline.path / resource destination = Path(".") / resource.name if not destination.exists(): # make sure you don't delete files that are already there... - copy_resource(abs_path, destination) + copy_resource(abs_path, destination, symlink=symlink_resources) copied_resources.append(destination) + elif destination.exists() and not cleanup: + typer.secho( + f"Resource '{resource.name}' already exists! Skipping...", + fg=typer.colors.RED, + ) else: raise FileExistsError(f"Resource '{resource.name}' already exists!") @@ -432,7 +438,7 @@ def run( with self.copy_resources( self.snk_config.resources, cleanup=not keep_resources, - symlink_resources_folder=self.snk_config.symlink_resources_folder + symlink_resources=self.snk_config.symlink_resources ): try: snakemake.main(args) diff --git a/snk/cli/config.py b/snk/cli/config.py index 2d0ddef..07a09a2 100644 --- a/snk/cli/config.py +++ b/snk/cli/config.py @@ -14,8 +14,8 @@ class SnkConfig: resources: List[Path] = field(default_factory=list) annotations: dict = field(default_factory=dict) - symlink_resources_folder: bool = False - + symlink_resources: bool = False + @classmethod def from_path(cls, snk_config_path: Path): """ diff --git a/tests/data/pipeline/.snk b/tests/data/pipeline/.snk index d10b148..adf7e4a 100644 --- a/tests/data/pipeline/.snk +++ b/tests/data/pipeline/.snk @@ -2,4 +2,4 @@ annotations: text: type: str help: "A string to save to a file" -symlink_resources_folder: true \ No newline at end of file +symlink_resources: true \ No newline at end of file