Skip to content

Commit

Permalink
add toggle for using conda and container envs
Browse files Browse the repository at this point in the history
  • Loading branch information
rahuldesai1 committed Jan 19, 2024
1 parent aed275e commit 208aa4b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
40 changes: 40 additions & 0 deletions latch/types/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,16 +523,56 @@ def _parameter_str(t: Tuple[str, LatchParameter]):

@dataclass
class DockerMetadata:
"""Class describing credentials for private docker repositories"""

username: str
"""
The account username for the private repository
"""
secret_name: str
"""
The name of the Latch Secret that contains the password for the private repository
"""


@dataclass
class EnvironmentConfig:
"""Class describing environment for spawning Snakemake tasks"""

use_conda: bool = True
"""
Use Snakemake `conda` directive to spawn tasks in conda environments
"""
use_containers: bool = True
"""
Use Snakemake `container` directive to spawn tasks in Docker containers
"""


@dataclass
class SnakemakeMetadata(LatchMetadata):
"""Class for organizing Snakemake workflow metadata"""

output_dir: Optional[LatchDir] = None
"""
Directory for snakemake workflow outputs
"""
name: Optional[str] = None
"""
Name of the workflow
"""
docker_metadata: Optional[DockerMetadata] = None
"""
Credentials configuration for private docker repositories
"""
env_config: Optional[EnvironmentConfig] = None
"""
Environment configuration for spawning Snakemake tasks
"""
parameters: Dict[str, SnakemakeParameter] = field(default_factory=dict)
"""
A dictionary mapping parameter names (strings) to `SnakemakeParameter` objects
"""

def __post_init__(self):
if self.name is None:
Expand Down
14 changes: 10 additions & 4 deletions latch_cli/snakemake/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,14 @@ def __init__(
self._dag = dag
self._cache_tasks = cache_tasks
self._docker_metadata = metadata._snakemake_metadata.docker_metadata
self._use_conda = (
metadata._snakemake_metadata.env_config is not None
and metadata._snakemake_metadata.env_config.use_conda
)
self._use_containers = (
metadata._snakemake_metadata.env_config is not None
and metadata._snakemake_metadata.env_config.use_containers
)
self.snakemake_tasks: List[SnakemakeJobTask] = []

workflow_metadata = WorkflowMetadata(
Expand Down Expand Up @@ -1311,8 +1319,6 @@ def get_fn_code(
if isinstance(self.job, GroupJob):
jobs = self.job.jobs

need_conda = any(x.conda_env is not None for x in jobs)

if non_blob_parameters is not None:
for param, val in non_blob_parameters.items():
self.job.rule.workflow.globals["config"][param] = val
Expand All @@ -1322,8 +1328,8 @@ def get_fn_code(
"latch_cli.snakemake.single_task_snakemake",
"-s",
snakefile_path_in_container,
*(["--use-conda"] if need_conda else []),
"--use-singularity",
*(["--use-conda"] if self.wf._use_conda else []),
*(["--use-singularity"] if self.wf._use_containers else []),
"--target-jobs",
*jobs_cli_args(jobs),
"--allowed-rules",
Expand Down

0 comments on commit 208aa4b

Please sign in to comment.