Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow definition of access pattern for input files #2597

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions snakemake/access_patterns.py
@@ -0,0 +1,23 @@
from dataclasses import dataclass
from typing import Optional
from snakemake.io import flag
from snakemake_interface_common.exceptions import WorkflowError

VALID_PATTERNS = ["head", "tail", "random", "sequential"]


@dataclass
class AccessPattern:
pattern: str
lines: Optional[int] = None
bytes: Optional[int] = None


def access_pattern(
path, pattern: str, lines: Optional[int] = None, bytes: Optional[int] = None
):
if pattern not in VALID_PATTERNS:
raise WorkflowError(
f"Invalid access pattern: {pattern}. Valid patterns are: {', '.join(VALID_PATTERNS)}"
)
return flag(path, "access_pattern", AccessPattern(pattern, lines, bytes))
2 changes: 2 additions & 0 deletions snakemake/workflow.py
Expand Up @@ -84,6 +84,7 @@
IOFile,
sourcecache_entry,
)
from snakemake.access_patterns import access_pattern

from snakemake.persistence import Persistence
from snakemake.utils import update_config
Expand Down Expand Up @@ -205,6 +206,7 @@ def __post_init__(self):
_globals["gitlab"] = sourcecache.GitlabFile
_globals["gitfile"] = sourcecache.LocalGitFile
_globals["storage"] = self._storage_registry
_globals["access_pattern"] = access_pattern

self.vanilla_globals = dict(_globals)
self.modifier_stack = [WorkflowModifier(self, globals=_globals)]
Expand Down