-
Notifications
You must be signed in to change notification settings - Fork 1
feat: support Snakemake SQLite DB persistence backend #51
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| """Persistence backend abstraction for reading Snakemake metadata. | ||
|
|
||
| Supports both the filesystem-based backend (.snakemake/metadata/ directory) | ||
| and the newer SQLite-based backend (.snakemake/metadata.db). | ||
| """ | ||
|
|
||
| from snakesee.persistence.backend import IncompleteJob | ||
| from snakesee.persistence.backend import PersistenceBackend | ||
| from snakesee.persistence.backend import detect_backend | ||
| from snakesee.persistence.db import DbPersistence | ||
| from snakesee.persistence.fs import FsPersistence | ||
|
|
||
| __all__ = [ | ||
| "DbPersistence", | ||
| "FsPersistence", | ||
| "IncompleteJob", | ||
| "PersistenceBackend", | ||
| "detect_backend", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| """Persistence backend protocol and auto-detection.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Iterator | ||
| from dataclasses import dataclass | ||
| from pathlib import Path | ||
| from typing import TYPE_CHECKING | ||
| from typing import Protocol | ||
|
|
||
| if TYPE_CHECKING: | ||
| from snakesee.types import ProgressCallback | ||
|
|
||
| from snakesee.parser.metadata import MetadataRecord | ||
|
|
||
|
|
||
| class PersistenceBackend(Protocol): | ||
| """Protocol for reading Snakemake workflow metadata. | ||
|
|
||
| Implementations provide access to job metadata, incomplete markers, | ||
| and lock state from either the filesystem or SQLite backends. | ||
| """ | ||
|
|
||
| def iterate_metadata( | ||
| self, | ||
| progress_callback: ProgressCallback | None = None, | ||
| ) -> Iterator[MetadataRecord]: | ||
| """Iterate over all job metadata records. | ||
|
|
||
| Args: | ||
| progress_callback: Optional callback(current, total) for progress. | ||
|
|
||
| Yields: | ||
| MetadataRecord for each completed job. | ||
| """ | ||
| ... | ||
|
|
||
| def has_incomplete_jobs(self) -> bool: | ||
| """Check whether any jobs are currently marked incomplete.""" | ||
| ... | ||
|
|
||
| def iterate_incomplete_jobs( | ||
| self, | ||
| min_start_time: float | None = None, | ||
| ) -> Iterator[IncompleteJob]: | ||
| """Iterate over incomplete (in-progress) job markers. | ||
|
|
||
| Args: | ||
| min_start_time: If set, only yield jobs started at or after this time. | ||
|
|
||
| Yields: | ||
| IncompleteJob for each in-progress job. | ||
| """ | ||
| ... | ||
|
|
||
| def has_locks(self) -> bool: | ||
| """Check whether any workflow locks are held.""" | ||
| ... | ||
|
|
||
|
|
||
| @dataclass(frozen=True, slots=True) | ||
| class IncompleteJob: | ||
| """A job marked as incomplete/in-progress. | ||
|
|
||
| Attributes: | ||
| start_time: Approximate start time (mtime for FS, starttime for DB). | ||
| output_file: Output file path if known. | ||
| rule: Rule name if known (DB backend provides this; FS does not). | ||
| external_jobid: External executor job ID if known. | ||
| """ | ||
|
|
||
| start_time: float | None = None | ||
| output_file: Path | None = None | ||
| rule: str | None = None | ||
| external_jobid: str | None = None | ||
|
|
||
|
|
||
| def detect_backend(workflow_dir: Path) -> PersistenceBackend: | ||
| """Auto-detect and return the appropriate persistence backend. | ||
|
|
||
| Prefers the SQLite DB backend when .snakemake/metadata.db exists. | ||
| Falls back to filesystem backend otherwise. | ||
|
|
||
| Args: | ||
| workflow_dir: Root workflow directory containing .snakemake/. | ||
|
|
||
| Returns: | ||
| A PersistenceBackend implementation. | ||
| """ | ||
| from snakesee.state.paths import WorkflowPaths | ||
|
|
||
| paths = WorkflowPaths(workflow_dir) | ||
|
|
||
| if paths.metadata_db.exists(): | ||
| from snakesee.persistence.db import DbPersistence | ||
|
|
||
| return DbPersistence(paths) | ||
|
|
||
| from snakesee.persistence.fs import FsPersistence | ||
|
|
||
| return FsPersistence(paths) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.