Skip to content

Commit

Permalink
Address semsimian being optional dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
hrshdhgd committed Mar 6, 2024
1 parent 5952482 commit 6fe1a86
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
57 changes: 35 additions & 22 deletions src/oaklib/implementations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@
OntoPortalImplementationBase,
)
from oaklib.implementations.pronto.pronto_implementation import ProntoImplementation
from oaklib.implementations.semsimian.semsimian_implementation import (
SemSimianImplementation,
)
from oaklib.implementations.simpleobo.simple_obo_implementation import (
SimpleOboImplementation,
)
Expand All @@ -65,6 +62,16 @@
)
from oaklib.interfaces import OntologyInterface

SEMSIMIAN_AVAILABLE = False
try:
from oaklib.implementations.semsimian.semsimian_implementation import (
SemSimianImplementation,
)
SEMSIMIAN_AVAILABLE = True
except ImportError:
pass


__all__ = [
"get_implementation_resolver",
# Concrete classes
Expand Down Expand Up @@ -96,8 +103,7 @@
"UniprotImplementation",
"TranslatorImplementation",
"OakMetaModelImplementation",
"SemSimianImplementation",
]
] + (["SemSimianImplementation"] if SEMSIMIAN_AVAILABLE else [])


@cache
Expand All @@ -122,30 +128,37 @@ def get_implementation_resolver() -> ClassResolver[OntologyInterface]:
:return: A ClassResolver capable of resolving an OntologyInterface implementation
"""
skip_classes = {
OntoPortalImplementationBase,
BaseOlsImplementation,
}

resolver_synonyms = {
"obolibrary": ProntoImplementation,
"prontolib": ProntoImplementation,
"simpleobo": SimpleOboImplementation,
"sqlite": SqlImplementation,
"rdflib": SparqlImplementation,
"oak": OakMetaModelImplementation,
"cx": CXImplementation,
"ndexbio": CXImplementation,
}

if not SEMSIMIAN_AVAILABLE:
skip_classes.add('SemSimianImplementation')
resolver_synonyms['semsimian'] = SemSimianImplementation

implementation_resolver: ClassResolver[OntologyInterface] = ClassResolver.from_subclasses(
OntologyInterface,
suffix="Implementation",
skip={
OntoPortalImplementationBase,
BaseOlsImplementation,
},
skip=skip_classes,
)
# if an implementation uses a shorthand name that is
# different from the class name (minus Implementation), then
# it should be added here
implementation_resolver.synonyms.update(
{
"obolibrary": ProntoImplementation,
"prontolib": ProntoImplementation,
"simpleobo": SimpleOboImplementation,
"sqlite": SqlImplementation,
"rdflib": SparqlImplementation,
"oak": OakMetaModelImplementation,
"cx": CXImplementation,
"ndexbio": CXImplementation,
"semsimian": SemSimianImplementation,
}
)


implementation_resolver.synonyms.update(resolver_synonyms)

# Plugins which want to register an implementation should use
# the entrypoint group "oaklib.plugins". The name of the entry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
from dataclasses import dataclass, field
from typing import ClassVar, Dict, Iterable, Iterator, List, Optional, Tuple, Union

from semsimian import Semsimian
try:
from semsimian import Semsimian
except ImportError:
raise ImportError("The 'semsimian' package is not installed. Please install it to continue.")


from oaklib.datamodels.similarity import (
BestMatch,
Expand Down

0 comments on commit 6fe1a86

Please sign in to comment.