Skip to content

Commit

Permalink
Refactor HMMER daemon and update dependencies 🚀
Browse files Browse the repository at this point in the history
- Refactored `hmmer.py` to replace `SchedContext` with `h3daemon` for spawning
and managing the daemon.
- Updated the method for shutdown to leverage `h3daemon`.
- Renamed test functions in `test_hmmer.py` and `test_press.py`.
- Updated `h3daemon` dependency version in `pyproject.toml`.

This refactor improves the codebase by utilizing the latest `h3daemon` API, which simplifies the HMMER daemon's spawn and shutdown processes, leading to cleaner and more maintainable code. Also, renaming test functions aligns with the simplified process, enhancing readability. 📊✨
  • Loading branch information
horta committed Dec 5, 2024
1 parent 899b345 commit 249e6ee
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
23 changes: 9 additions & 14 deletions worker/deciphon_worker/hmmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Any

from deciphon_schema import HMMFile
from h3daemon.sched import SchedContext
import h3daemon
from loguru import logger

from deciphon_worker.thread import launch_thread
Expand All @@ -12,22 +12,17 @@

class HMMER:
def __init__(self, hmmfile: HMMFile, stdout: Any, stderr: Any):
info("starting hmmer daemon")
h3file = HMMFile(path=hmmfile.path)
stdout = stdout
stderr = stderr
self._sched_ctx = SchedContext(h3file, stdout=stdout, stderr=stderr)
self._sched = self._sched_ctx.__enter__()

def shutdown(self):
info("stopping hmmer daemon")
if self._sched_ctx is not None:
self._sched_ctx.__exit__()
self._sched_ctx = None
pidfile = h3daemon.spawn(
hmmfile, stdout=stdout, stderr=stderr, detach=False, force=True
)
self._manager = h3daemon.possess(pidfile)

def shutdown(self, force=False):
self._manager.shutdown(force=force)

@property
def port(self):
return self._sched.get_cport()
return self._manager.port()


def launch_hmmer(hmmfile: HMMFile, stdout: Any = None, stderr: Any = None):
Expand Down
4 changes: 2 additions & 2 deletions worker/deciphon_worker/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def __init__(
stdout: Any = None,
stderr: Any = None,
):
h3file = HMMFile(path=dbfile.hmmpath.path)
self._hmmer: HMMER = launch_hmmer(h3file, stdout, stderr).result()
hmmfile = HMMFile(path=dbfile.hmmpath.path)
self._hmmer: HMMER = launch_hmmer(hmmfile, stdout, stderr).result()
info("starting scan daemon")
self._scan = Scan(
dbfile,
Expand Down
2 changes: 1 addition & 1 deletion worker/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readme = "README.md"

[tool.poetry.dependencies]
python = "^3.9"
h3daemon = "^0.14.9"
h3daemon = "^0.15.0"
deciphon-core = "^1.0.7"
loguru = "^0.7.2"
tenacity = "^9.0.0"
Expand Down
2 changes: 1 addition & 1 deletion worker/tests/test_hmmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from deciphon_worker import launch_hmmer, shutting


def test_hmmer_worker(tmp_path, files_path: Path):
def test_hmmer(tmp_path, files_path: Path):
os.chdir(tmp_path)
shutil.copy(files_path / "minifam.hmm", Path("minifam.hmm"))
hmmfile = HMMFile(path=Path("minifam.hmm"))
Expand Down
2 changes: 1 addition & 1 deletion worker/tests/test_press.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from deciphon_worker import press


def test_press_worker(tmp_path, files_path: Path):
def test_press(tmp_path, files_path: Path):
os.chdir(tmp_path)
shutil.copy(files_path / "minifam.hmm", Path("minifam.hmm"))
hmmfile = HMMFile(path=Path("minifam.hmm"))
Expand Down

0 comments on commit 249e6ee

Please sign in to comment.