Skip to content

Commit

Permalink
fix: fixed bug in handling of resource overrides for remote job submi…
Browse files Browse the repository at this point in the history
…ssion
  • Loading branch information
johanneskoester committed Feb 5, 2024
1 parent 5a3ff9e commit 5c06dd6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
11 changes: 7 additions & 4 deletions snakemake/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
ResourceScopesException,
print_exception,
)
from snakemake.io import flag
from snakemake.resources import (
DefaultResources,
ResourceScopes,
Expand Down Expand Up @@ -81,18 +82,20 @@ def parse_set_resources(args):
assignments = defaultdict(dict)
if args is not None:
for entry in args:
key, value = parse_key_value_arg(entry, errmsg=errmsg, strip_quotes=False)
key, orig_value = parse_key_value_arg(
entry, errmsg=errmsg, strip_quotes=False
)
key = key.split(":")
if len(key) != 2:
raise ValueError(errmsg)
rule, resource = key
try:
value = int(value)
value = int(orig_value)
except ValueError:
value = eval_resource_expression(value)
value = eval_resource_expression(orig_value)
if isinstance(value, int) and value < 0:
raise ValueError(errmsg)
assignments[rule][resource] = value
assignments[rule][resource] = flag(value, "orig_arg", orig_value)
return assignments


Expand Down
4 changes: 2 additions & 2 deletions snakemake/settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC
from dataclasses import dataclass, field
from pathlib import Path
from typing import Optional
from typing import Any, Optional
from typing import Mapping, Sequence, Set

import immutables
Expand Down Expand Up @@ -281,7 +281,7 @@ class ResourceSettings(SettingsBase):
overwrite_threads: Mapping[str, int] = immutables.Map()
overwrite_scatter: Mapping[str, int] = immutables.Map()
overwrite_resource_scopes: Mapping[str, str] = immutables.Map()
overwrite_resources: Mapping[str, Mapping[str, int]] = immutables.Map()
overwrite_resources: Mapping[str, Mapping[str, Any]] = immutables.Map()
default_resources: Optional[DefaultResources] = None

def __post_init__(self):
Expand Down
9 changes: 8 additions & 1 deletion snakemake/spawn_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from snakemake_interface_storage_plugins.registry import StoragePluginRegistry

from snakemake import common
from snakemake.io import get_flag_value, is_flagged
from snakemake.settings import SharedFSUsage

if TYPE_CHECKING:
Expand Down Expand Up @@ -82,10 +83,16 @@ def get_storage_provider_envvars(self):
}

def get_set_resources_args(self):
def get_orig_arg(value):
if is_flagged(value, "orig_arg"):
return get_flag_value(value, "orig_arg")
else:
return value

return format_cli_arg(
"--set-resources",
[
f"{rule}:{name}={value}"
f"{rule}:{name}={get_orig_arg(value)}"
for rule, res in self.workflow.resource_settings.overwrite_resources.items()
for name, value in res.items()
],
Expand Down

0 comments on commit 5c06dd6

Please sign in to comment.