From 8be9cf60776b23ed5601a409bb94863d42fb7ddd Mon Sep 17 00:00:00 2001 From: maximsmol Date: Fri, 21 Jul 2023 17:13:28 -0700 Subject: [PATCH] do not depend on encode_target_jobs_cli_args Signed-off-by: maximsmol --- latch_cli/docker_utils/__init__.py | 2 +- latch_cli/snakemake/workflow.py | 25 ++++++++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/latch_cli/docker_utils/__init__.py b/latch_cli/docker_utils/__init__.py index 549f9e95..7ae90d1a 100644 --- a/latch_cli/docker_utils/__init__.py +++ b/latch_cli/docker_utils/__init__.py @@ -361,7 +361,7 @@ def generate_dockerfile( ) f.write("run pip uninstall --yes latch\n") f.write( - "run echo 71 && pip install" + "run echo 72 && pip install" " 'git+https://github.com/latchbio/latch.git@maximsmol/snakekit-1'\n" ) diff --git a/latch_cli/snakemake/workflow.py b/latch_cli/snakemake/workflow.py index 3a851c15..cf923f60 100644 --- a/latch_cli/snakemake/workflow.py +++ b/latch_cli/snakemake/workflow.py @@ -2,6 +2,7 @@ import json import textwrap import typing +from collections.abc import Generator, Iterable from dataclasses import dataclass from pathlib import Path from typing import Any, Dict, List, Optional, Tuple, Type, TypeVar, Union @@ -35,8 +36,7 @@ from flytekit.models.core.types import BlobType from flytekit.models.literals import Blob, BlobMetadata, Literal, LiteralMap, Scalar from snakemake.dag import DAG -from snakemake.jobs import GroupJob -from snakemake.target_jobs import encode_target_jobs_cli_args +from snakemake.jobs import GroupJob, Job from typing_extensions import TypeAlias, TypedDict import latch.types.metadata as metadata @@ -48,6 +48,17 @@ SnakemakeInputVal: TypeAlias = snakemake.io._IOFile +# old snakemake did not have encode_target_jobs_cli_args +def jobs_cli_args( + jobs: Iterable[Job], +) -> Generator[str, None, None]: + for x in jobs: + wildcards = ",".join( + f"{key}={value}" for key, value in x.wildcards_dict.items() + ) + yield f"{x.rule.name}:{wildcards}" + + T = TypeVar("T") @@ -1035,13 +1046,17 @@ def get_fn_code( 1, ) + jobs = [self.job] + if isinstance(self.job, GroupJob): + jobs = self.job.jobs + snakemake_args = [ "-m", "latch_cli.snakemake.single_task_snakemake", "-s", snakefile_path_in_container, "--target-jobs", - *encode_target_jobs_cli_args(self.job.get_target_spec()), + *jobs_cli_args(jobs), "--allowed-rules", *self.job.rules, "--local-groupid", @@ -1062,10 +1077,6 @@ def get_fn_code( for resource, value in allowed_resources: snakemake_args.append(f"{resource}={value}") - jobs = [self.job] - if isinstance(self.job, GroupJob): - jobs = self.job.jobs - snakemake_data = { "rules": {}, "outputs": self.job.output,