Skip to content

Commit

Permalink
🎨 editable workflows use .snakemake for conda envs #38
Browse files Browse the repository at this point in the history
  • Loading branch information
Wytamma committed Jan 29, 2024
1 parent a6f7f52 commit 2b1a0e7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
8 changes: 2 additions & 6 deletions snk/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,8 @@ def __init__(self, workflow_dir_path: Path = None) -> None:
self.version = self.workflow.commit
self.options = build_dynamic_cli_options(self.snakemake_config, self.snk_config)
self.snakefile = self._find_snakefile()
self.conda_prefix_dir = workflow_dir_path / ".conda"
if " " in str(workflow_dir_path):
# cannot have spaces!
self.singularity_prefix_dir = None
else:
self.singularity_prefix_dir = workflow_dir_path / ".singularity"
self.conda_prefix_dir = self.workflow.conda_prefix_dir
self.singularity_prefix_dir = self.workflow.singularity_prefix_dir
self.name = self.workflow.name
self.verbose = False
if (
Expand Down
2 changes: 1 addition & 1 deletion snk/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def list(
for workflow in workflows:
if workflow.editable:
print(
f'- {workflow.name} ([bold green]editable[/bold green]) -> "{workflow.path}"'
f'- {workflow.name} ([bold green]editable[/bold green]) -> "{workflow.path.resolve()}"'
)
continue
print(f"- {workflow.name} ([bold green]{workflow.version}[/bold green])")
Expand Down
2 changes: 1 addition & 1 deletion snk/nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def create_executable(self, workflow_path: Path, name: str) -> Path:
from snk import create_cli
if __name__ == "__main__":
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(create_cli("{workflow_path.resolve()}"))
sys.exit(create_cli("{workflow_path}"))
"""
)
Expand Down
24 changes: 23 additions & 1 deletion snk/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self, path: Path) -> None:
self.repo = None
self.name = self.path.name


@property
def tag(self):
"""
Expand All @@ -43,7 +44,6 @@ def tag(self):
str: The tag of the workflow, or None if no tag is found.
"""
try:
# TODO: default to commit
tag = self.repo.git.describe(["--tags", "--exact-match"])
except Exception:
tag = None
Expand Down Expand Up @@ -91,6 +91,28 @@ def executable(self):
if sys.platform.startswith("win"):
name += ".exe"
return workflow_bin_dir / name

@property
def conda_prefix_dir(self):
"""
Gets the conda prefix directory of the workflow.
Returns:
Path: The path to the conda prefix directory.
"""
return Path(".snakemake") / "conda" if self.editable else self.path / ".conda"

@property
def singularity_prefix_dir(self):
"""
Gets the singularity prefix directory of the workflow.
Returns:
Path: The path to the singularity prefix directory.
"""
if " " in str(self.path):
# sigh, snakemake singularity does not support spaces in the path
# https://github.com/snakemake/snakemake/blob/2ecb21ba04088b9e6850447760f713784cf8b775/snakemake/deployment/singularity.py#L130C1-L131C1
return None
return Path(".snakemake") / "singularity" if self.editable else self.path / ".singularity"

@property
def editable(self):
Expand Down

0 comments on commit 2b1a0e7

Please sign in to comment.