Skip to content

Commit d359609

Browse files
feat: introduce EnvSpecSourceFile as a container data class for paths or uris mentioned in the EnvSpec that shall be cached and resolved by Snakemake's source caching mechanism (#13)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new data class `EnvSpecSourceFile` to enhance environment specification management, providing flexibility for handling source references and an option for caching. - Updated type annotations for improved clarity and functionality. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 07f7b16 commit d359609

File tree

1 file changed

+13
-7
lines changed
  • snakemake_interface_software_deployment_plugins

1 file changed

+13
-7
lines changed

snakemake_interface_software_deployment_plugins/__init__.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from dataclasses import dataclass, field
99
import hashlib
1010
from pathlib import Path
11-
from typing import Any, ClassVar, Dict, Iterable, Optional, Self, Tuple, Type
11+
from typing import Any, ClassVar, Dict, Iterable, Optional, Self, Tuple, Type, Union
1212
import subprocess as sp
1313

1414
from snakemake_interface_software_deployment_plugins.settings import (
@@ -23,8 +23,15 @@ class SoftwareReport:
2323
is_secondary: bool = False
2424

2525

26+
@dataclass
27+
class EnvSpecSourceFile:
28+
path_or_uri: Union[str, Path]
29+
cached: Optional[Path] = field(init=False, repr=False, default=None)
30+
31+
2632
class EnvSpecBase(ABC):
27-
def __init__(self):
33+
def technical_init(self):
34+
"""This has to be called by Snakemake upon initialization"""
2835
self.within: Optional["EnvSpecBase"] = None
2936
self.fallback: Optional["EnvSpecBase"] = None
3037
self.kind: str = self.__class__.__module__.common_settings.provides
@@ -66,11 +73,10 @@ def modify_source_paths(self, modify_func) -> Self:
6673
self_or_copied = copy(self)
6774
else:
6875
return self
69-
for attr in self_or_copied.source_path_attributes():
70-
for attr_name in self_or_copied.source_path_attributes():
71-
current_value = getattr(self_or_copied, attr_name)
72-
if current_value is not None:
73-
setattr(self_or_copied, attr_name, modify_func(current_value))
76+
for attr_name in self_or_copied.source_path_attributes():
77+
current_value = getattr(self_or_copied, attr_name)
78+
if current_value is not None:
79+
setattr(self_or_copied, attr_name, modify_func(current_value))
7480

7581
if self_or_copied.within is not None:
7682
self_or_copied.within = self_or_copied.within.modify_source_paths(

0 commit comments

Comments
 (0)