snakemake-executor-plugin-finished 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- snakemake_executor_plugin_finished/__init__.py +15 -0
- snakemake_executor_plugin_finished/executor.py +107 -0
- snakemake_executor_plugin_finished-0.1.0.dist-info/METADATA +11 -0
- snakemake_executor_plugin_finished-0.1.0.dist-info/RECORD +6 -0
- snakemake_executor_plugin_finished-0.1.0.dist-info/WHEEL +4 -0
- snakemake_executor_plugin_finished-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from snakemake_interface_executor_plugins.settings import CommonSettings
|
|
2
|
+
|
|
3
|
+
from .executor import Executor
|
|
4
|
+
|
|
5
|
+
common_settings = CommonSettings(
|
|
6
|
+
non_local_exec=False,
|
|
7
|
+
dryrun_exec=False,
|
|
8
|
+
implies_no_shared_fs=False,
|
|
9
|
+
job_deploy_sources=False,
|
|
10
|
+
touch_exec=True,
|
|
11
|
+
pass_envvar_declarations_to_cmd=False,
|
|
12
|
+
auto_deploy_default_storage_provider=False,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
__all__ = ["Executor", "common_settings"]
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Iterable, Set
|
|
6
|
+
|
|
7
|
+
from snakemake_interface_common.exceptions import WorkflowError
|
|
8
|
+
from snakemake_interface_executor_plugins.executors.base import (
|
|
9
|
+
AbstractExecutor,
|
|
10
|
+
SubmittedJobInfo,
|
|
11
|
+
)
|
|
12
|
+
from snakemake_interface_executor_plugins.jobs import JobExecutorInterface
|
|
13
|
+
from snakemake_interface_executor_plugins.logging import LoggerExecutorInterface
|
|
14
|
+
from snakemake_interface_executor_plugins.workflow import WorkflowExecutorInterface
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass
|
|
18
|
+
class FinishedTargets:
|
|
19
|
+
"""Tracks requested targets and which remain unmatched."""
|
|
20
|
+
|
|
21
|
+
requested: Set[str]
|
|
22
|
+
remaining: Set[str]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Executor(AbstractExecutor):
|
|
26
|
+
"""Mark targets as finished without executing jobs."""
|
|
27
|
+
|
|
28
|
+
_targets: FinishedTargets
|
|
29
|
+
|
|
30
|
+
def __init__(
|
|
31
|
+
self, workflow: WorkflowExecutorInterface, logger: LoggerExecutorInterface
|
|
32
|
+
) -> None:
|
|
33
|
+
super().__init__(workflow, logger)
|
|
34
|
+
targets = self._resolve_targets()
|
|
35
|
+
if not targets:
|
|
36
|
+
raise WorkflowError(
|
|
37
|
+
"No targets specified for finished executor. "
|
|
38
|
+
"Provide targets as positional arguments."
|
|
39
|
+
)
|
|
40
|
+
self._targets = FinishedTargets(requested=targets, remaining=set(targets))
|
|
41
|
+
|
|
42
|
+
def _normalize_targets(self, targets: Iterable[str]) -> Set[str]:
|
|
43
|
+
return {str(target) for target in targets}
|
|
44
|
+
|
|
45
|
+
def _resolve_targets(self) -> Set[str]:
|
|
46
|
+
dag = self.workflow.dag
|
|
47
|
+
targets = getattr(dag, "derived_targetfiles", None)
|
|
48
|
+
if targets is None:
|
|
49
|
+
targets = getattr(dag, "targetfiles", None)
|
|
50
|
+
if not targets:
|
|
51
|
+
return set()
|
|
52
|
+
return self._normalize_targets(targets)
|
|
53
|
+
|
|
54
|
+
def _job_target(self, job: JobExecutorInterface) -> str | None:
|
|
55
|
+
target = getattr(job, "targetfile", None)
|
|
56
|
+
if target is None:
|
|
57
|
+
return None
|
|
58
|
+
return str(target)
|
|
59
|
+
|
|
60
|
+
def _job_outputs(self, job: JobExecutorInterface) -> Set[str]:
|
|
61
|
+
return {str(output) for output in job.output}
|
|
62
|
+
|
|
63
|
+
def _touch_target(self, target: str) -> None:
|
|
64
|
+
target_path = Path(target)
|
|
65
|
+
target_path.touch()
|
|
66
|
+
if target_path.is_dir():
|
|
67
|
+
(target_path / ".snakemake_timestamp").touch()
|
|
68
|
+
|
|
69
|
+
def run_job(self, job: JobExecutorInterface) -> None:
|
|
70
|
+
job_info = SubmittedJobInfo(job=job)
|
|
71
|
+
self.report_job_submission(job_info)
|
|
72
|
+
|
|
73
|
+
job_targets = set()
|
|
74
|
+
target = self._job_target(job)
|
|
75
|
+
if target is not None:
|
|
76
|
+
job_targets.add(target)
|
|
77
|
+
job_targets.update(self._job_outputs(job))
|
|
78
|
+
matches = self._targets.remaining.intersection(job_targets)
|
|
79
|
+
if matches:
|
|
80
|
+
missing = sorted(match for match in matches if not Path(match).exists())
|
|
81
|
+
if missing:
|
|
82
|
+
raise WorkflowError("Target files do not exist: " + ", ".join(missing))
|
|
83
|
+
self.workflow.async_run(self.workflow.persistence.finished(job))
|
|
84
|
+
for match in sorted(matches):
|
|
85
|
+
self._touch_target(match)
|
|
86
|
+
self.logger.info(
|
|
87
|
+
f"Job '{job.name}' marked as finished for: {', '.join(sorted(matches))}"
|
|
88
|
+
)
|
|
89
|
+
self._targets.remaining.difference_update(matches)
|
|
90
|
+
|
|
91
|
+
self.report_job_success(job_info)
|
|
92
|
+
|
|
93
|
+
def shutdown(self) -> None:
|
|
94
|
+
if self._targets.remaining:
|
|
95
|
+
missing = sorted(self._targets.remaining)
|
|
96
|
+
raise WorkflowError(
|
|
97
|
+
f"Something went wrong, the following targets were not found: {missing}"
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
def cancel(self) -> None:
|
|
101
|
+
pass
|
|
102
|
+
|
|
103
|
+
def handle_job_success(self, job: JobExecutorInterface) -> None:
|
|
104
|
+
pass
|
|
105
|
+
|
|
106
|
+
def handle_job_error(self, job: JobExecutorInterface) -> None:
|
|
107
|
+
pass
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: snakemake-executor-plugin-finished
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Snakemake executor plugin that marks targets as finished
|
|
5
|
+
Project-URL: Repository, https://github.com/alephreish/snakemake-executor-plugin-finished
|
|
6
|
+
Project-URL: Documentation, https://snakemake.github.io/snakemake-plugin-catalog/plugins/executor/finished.html
|
|
7
|
+
Author-email: Andrey Rozenberg <alephreish@gmail.com>
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Python: <4.0,>=3.11
|
|
10
|
+
Requires-Dist: snakemake-interface-common<2,>=1.23.0
|
|
11
|
+
Requires-Dist: snakemake-interface-executor-plugins<10,>=9.0.0
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
snakemake_executor_plugin_finished/__init__.py,sha256=Eqn49aSkdqvWoxT02J1r-NwCKE446_PG9qDS23DZ2cY,408
|
|
2
|
+
snakemake_executor_plugin_finished/executor.py,sha256=_-sgdpAXK23ROLcoYN5vTntnlYfdcVJqSBaEKYWiwdM,3749
|
|
3
|
+
snakemake_executor_plugin_finished-0.1.0.dist-info/METADATA,sha256=YqqYO0mvHc3OwHiTdxJ2VzykrEl61XeaF5AkZpG0E78,567
|
|
4
|
+
snakemake_executor_plugin_finished-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
5
|
+
snakemake_executor_plugin_finished-0.1.0.dist-info/licenses/LICENSE,sha256=0KHw8Fby7qS29jRRdKIuOCXE3Dkj1hZatJZrDuRIKYM,1073
|
|
6
|
+
snakemake_executor_plugin_finished-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andrey Rozenberg
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|