Skip to content

Commit

Permalink
Make sure logger.getLogger() is used instead of logging directly via …
Browse files Browse the repository at this point in the history
…logging.debug() (#91)

Ensures that anywhere that `prymer` logs it is using a non-root logger.
  • Loading branch information
tfenne authored Nov 15, 2024
1 parent 8c39970 commit 1011c7d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions prymer/api/picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from individual left and primers.
"""

from collections.abc import Sequence
from pathlib import Path
from typing import Iterator
Expand Down
8 changes: 5 additions & 3 deletions prymer/api/variant_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
from prymer.api.span import Span
from prymer.api.span import Strand

_logger = logging.getLogger(__name__)


@unique
class VariantType(UppercaseStrEnum):
Expand Down Expand Up @@ -282,7 +284,7 @@ def query(

variants = self._query(refname=refname, start=start, end=end)
if len(variants) == 0:
logging.debug(f"No variants extracted from region of interest: {refname}:{start}-{end}")
_logger.debug(f"No variants extracted from region of interest: {refname}:{start}-{end}")
if maf is None or maf <= 0.0:
return variants
elif include_missing_mafs: # return variants with a MAF above threshold or missing
Expand Down Expand Up @@ -311,7 +313,7 @@ def to_variants(
): # if passing or empty filters
simple_variants = SimpleVariant.build(variant)
if any(v.variant_type == VariantType.OTHER for v in simple_variants):
logging.debug(
_logger.debug(
f"Input VCF file {source_vcf} may contain complex variants: {variant}"
)
simple_vars.extend(simple_variants)
Expand Down Expand Up @@ -372,7 +374,7 @@ def _query(self, refname: str, start: int, end: int) -> list[SimpleVariant]:
simple_variants: list[SimpleVariant] = []
for fh, path in zip(self._readers, self.vcf_paths, strict=True):
if not fh.header.contigs.get(refname):
logging.debug(f"Header in VCF file {path} does not contain chromosome {refname}.")
_logger.debug(f"Header in VCF file {path} does not contain chromosome {refname}.")
continue
# pysam.fetch is 0-based, half-open
variants = [variant for variant in fh.fetch(contig=refname, start=start - 1, end=end)]
Expand Down
2 changes: 1 addition & 1 deletion prymer/primer3/primer3.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def close(self) -> bool:
self._fasta.close()
subprocess_close = super().close()
if not subprocess_close:
logging.debug("Did not successfully close underlying subprocess")
logging.getLogger(__name__).debug("Did not successfully close underlying subprocess")
return subprocess_close

def get_design_sequences(self, region: Span) -> tuple[str, str]:
Expand Down
2 changes: 1 addition & 1 deletion prymer/primer3/primer3_failure_reason.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def parse_failures(
continue
std_reason = Primer3FailureReason.from_reason(reason)
if std_reason is None:
logging.debug(f"Unknown Primer3 failure reason: {reason}")
logging.getLogger(__name__).debug(f"Unknown Primer3 failure reason: {reason}")
by_fail_count[std_reason] += count

return by_fail_count
12 changes: 8 additions & 4 deletions prymer/util/executable_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ def __init__(
)

def __enter__(self) -> Self:
logging.debug(f"Initiating {self._name} with the following params: {self._command}")
logging.getLogger(__name__).debug(
f"Initiating {self._name} with the following params: {self._command}"
)
return self

def __exit__(
Expand Down Expand Up @@ -142,15 +144,17 @@ def close(self) -> bool:
True: if the subprocess was terminated successfully
False: if the subprocess failed to terminate or was not already running
"""
log = logging.getLogger(__name__)

if self.is_alive:
self._subprocess.terminate()
self._subprocess.wait(timeout=10)
if not self.is_alive:
logging.debug("Subprocess terminated successfully.")
log.debug("Subprocess terminated successfully.")
return True
else:
logging.debug("Subprocess failed to terminate.")
log.debug("Subprocess failed to terminate.")
return False
else:
logging.debug("Subprocess is not running.")
log.debug("Subprocess is not running.")
return False

0 comments on commit 1011c7d

Please sign in to comment.