Skip to content

Commit

Permalink
🐛 check for mamba when creating envs
Browse files Browse the repository at this point in the history
  • Loading branch information
Wytamma committed Feb 5, 2024
1 parent d64ec37 commit 4260726
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
4 changes: 4 additions & 0 deletions snk/cli/snakemake_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
common,
)
from snakemake.persistence import Persistence
from snk.cli.utils import check_command_available
import os

@dataclass
Expand Down Expand Up @@ -101,6 +102,9 @@ def create_snakemake_workflow(
os.makedirs(workdir)
workdir = os.path.abspath(workdir)
os.chdir(workdir)

if check_command_available("mamba"):
conda_frontend = "mamba"

workflow = Workflow(
snakefile=snakefile,
Expand Down
16 changes: 1 addition & 15 deletions snk/cli/subcommands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from snk.cli.utils import (
parse_config_args,
dag_filetype_callback,
check_command_available
)

from snk.cli.config.config import (
Expand Down Expand Up @@ -409,21 +410,6 @@ def remove_resource(resource: Path):
remove_resource(copied_resource)


def check_command_available(command: str):
"""
Check if a command is available.
Args:
command (str): The command to check.
Returns:
bool: True if the command is available, False otherwise.
Examples:
>>> CLI.check_command_available('ls')
"""
import shutil

return shutil.which(command) is not None


def parse_config_monkeypatch(args):
"""Monkeypatch the parse_config function from snakemake."""
import yaml
Expand Down
15 changes: 15 additions & 0 deletions snk/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
from snk.cli.options import Option


def check_command_available(command: str):
"""
Check if a command is available.
Args:
command (str): The command to check.
Returns:
bool: True if the command is available, False otherwise.
Examples:
>>> CLI.check_command_available('ls')
"""
from shutil import which

return which(command) is not None


def flatten(d, parent_key="", sep=":"):
"""
Flattens a nested dictionary.
Expand Down

0 comments on commit 4260726

Please sign in to comment.