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

Fix bug in Q/C pipeline #123

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/ppktstore/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,16 @@ def qc_phenopackets(
)
logger.info('Checking phenopackets')
checker = ppktstore.qc.configure_qc_checker()
outcome = checker.check(phenopacket_store=phenopacket_store)
if len(outcome) == 0:
results = checker.check(phenopacket_store=phenopacket_store)
if results.is_ok():
logger.info('Found no issues')
return 0
else:
logger.info('Phenopacket store Q/C failed')
for checker_name, errors in outcome.items():
logger.info('\'%s\' found %d error(s):', checker_name, len(errors))
for error in errors:

for checker_name, issues in results.iter_results():
logger.info('\'%s\' found %d error(s):', checker_name, len(issues))
for error in issues:
logger.info(' - %s', error)
return 1

Expand Down
4 changes: 2 additions & 2 deletions src/ppktstore/qc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ._api import QcChecker
from ._api import QcChecker, QcResults
from ._config import configure_qc_checker

__all__ = [
'QcChecker',
'QcChecker', 'QcResults',
'configure_qc_checker',
]
40 changes: 30 additions & 10 deletions src/ppktstore/qc/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@
from ppktstore.model import PhenopacketStore


class QcChecker(metaclass=abc.ABCMeta):

@abc.abstractmethod
def check(
self,
phenopacket_store: PhenopacketStore,
) -> typing.Mapping[str, typing.Sequence[str]]:
pass


class QcCheck(metaclass=abc.ABCMeta):

@abc.abstractmethod
Expand All @@ -32,3 +22,33 @@ def apply(
Check `phenopacket_store` and return a sequence of `str`s with errors.
"""
pass


class QcResults:
"""
Results of the Q/C check suite.
"""

def __init__(
self,
results: typing.Mapping[str, typing.Sequence[str]],
):
self._results = results

def iter_results(
self,
) -> typing.Iterator[typing.Tuple[str, typing.Sequence[str]]]:
return self._results.items()

def is_ok(self) -> bool:
return all(len(issues) == 0 for issues in self._results.values())


class QcChecker(metaclass=abc.ABCMeta):

@abc.abstractmethod
def check(
self,
phenopacket_store: PhenopacketStore,
) -> QcResults:
pass
6 changes: 3 additions & 3 deletions src/ppktstore/qc/_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ppktstore.model import PhenopacketStore

from ._api import QcCheck, QcChecker
from ._api import QcCheck, QcChecker, QcResults


class UniqueIdsCheck(QcCheck):
Expand Down Expand Up @@ -48,11 +48,11 @@ def __init__(
def check(
self,
phenopacket_store: PhenopacketStore,
) -> typing.Mapping[str, typing.Sequence[str]]:
) -> QcResults:
results = {}

for check in self._checks:
check_id = check.make_id()
results[check_id] = check.apply(phenopacket_store)

return results
return QcResults(results=results)
Loading