From a6aa9c99dee8ad883c478950bd53e0907874be0c Mon Sep 17 00:00:00 2001 From: zethson Date: Tue, 5 Nov 2024 11:52:46 +0100 Subject: [PATCH 1/3] :art: Use ValueError instead of AssertionError Signed-off-by: zethson --- bionty/_bionty.py | 2 +- bionty/core/_add_ontology.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bionty/_bionty.py b/bionty/_bionty.py index 1209126..6cb44f3 100644 --- a/bionty/_bionty.py +++ b/bionty/_bionty.py @@ -54,7 +54,7 @@ def create_or_get_organism_record( "uid", }: return None - raise AssertionError( + raise ValueError( f"{registry.__name__} requires to specify a organism name via `organism=` or `bionty.settings.organism=`!" ) diff --git a/bionty/core/_add_ontology.py b/bionty/core/_add_ontology.py index 955adc7..54d88c9 100644 --- a/bionty/core/_add_ontology.py +++ b/bionty/core/_add_ontology.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Iterable, List, Optional, Set, Tuple, Type, Union +from typing import TYPE_CHECKING, Iterable from lamin_utils import logger From ad3d2e87b6a6e0161ad15855db2b5e49045f14bf Mon Sep 17 00:00:00 2001 From: zethson Date: Tue, 5 Nov 2024 14:34:37 +0100 Subject: [PATCH 2/3] :art: Use custom Error Signed-off-by: zethson --- bionty/_bionty.py | 3 ++- bionty/core/exceptions.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 bionty/core/exceptions.py diff --git a/bionty/_bionty.py b/bionty/_bionty.py index 6cb44f3..a80d62c 100644 --- a/bionty/_bionty.py +++ b/bionty/_bionty.py @@ -7,6 +7,7 @@ from lnschema_core.models import Record import bionty.base as bt_base +from bionty.core.exceptions import OrganismNotSet from . import ids @@ -54,7 +55,7 @@ def create_or_get_organism_record( "uid", }: return None - raise ValueError( + raise OrganismNotSet( f"{registry.__name__} requires to specify a organism name via `organism=` or `bionty.settings.organism=`!" ) diff --git a/bionty/core/exceptions.py b/bionty/core/exceptions.py new file mode 100644 index 0000000..c822407 --- /dev/null +++ b/bionty/core/exceptions.py @@ -0,0 +1,9 @@ +# inheriting from SystemExit has the sole purpose of suppressing +# the traceback - this isn't optimal but the current best solution +# https://laminlabs.slack.com/archives/C04A0RMA0SC/p1726856875597489 + + +class OrganismNotSet(SystemExit): + """The `organism` parameter was not passed or is not globally set.""" + + pass From d1fc8c716d44e85b4652b48e983d52d989bfc6ab Mon Sep 17 00:00:00 2001 From: zethson Date: Tue, 5 Nov 2024 14:37:07 +0100 Subject: [PATCH 3/3] :art: Move error Signed-off-by: zethson --- bionty/_bionty.py | 7 ++++++- bionty/core/exceptions.py | 9 --------- 2 files changed, 6 insertions(+), 10 deletions(-) delete mode 100644 bionty/core/exceptions.py diff --git a/bionty/_bionty.py b/bionty/_bionty.py index a80d62c..b6e1322 100644 --- a/bionty/_bionty.py +++ b/bionty/_bionty.py @@ -7,7 +7,6 @@ from lnschema_core.models import Record import bionty.base as bt_base -from bionty.core.exceptions import OrganismNotSet from . import ids @@ -15,6 +14,12 @@ from types import ModuleType +class OrganismNotSet(SystemExit): + """The `organism` parameter was not passed or is not globally set.""" + + pass + + def create_or_get_organism_record( organism: str | Record | None, registry: type[Record], field: str | None = None ) -> Record | None: diff --git a/bionty/core/exceptions.py b/bionty/core/exceptions.py deleted file mode 100644 index c822407..0000000 --- a/bionty/core/exceptions.py +++ /dev/null @@ -1,9 +0,0 @@ -# inheriting from SystemExit has the sole purpose of suppressing -# the traceback - this isn't optimal but the current best solution -# https://laminlabs.slack.com/archives/C04A0RMA0SC/p1726856875597489 - - -class OrganismNotSet(SystemExit): - """The `organism` parameter was not passed or is not globally set.""" - - pass