Skip to content

Commit 9e90443

Browse files
committed
refactor: replace ScicrunchResourcesService with SCICRUNCH_SERVICE_APPKEY for improved service integration
1 parent 17ba3af commit 9e90443

File tree

7 files changed

+25
-17
lines changed

7 files changed

+25
-17
lines changed

services/web/server/src/simcore_service_webserver/exporter/_formatter/_sds.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from ...projects._projects_service import get_project_for_user
1212
from ...projects.exceptions import BaseProjectError
1313
from ...projects.models import ProjectDict
14-
from ...scicrunch.scicrunch_service import ScicrunchResourcesService
14+
from ...scicrunch.scicrunch_service import SCICRUNCH_SERVICE_APPKEY
1515
from ..exceptions import SDSException
1616
from .template_json import write_template_json
1717
from .xlsx.code_description import (
@@ -70,7 +70,7 @@ async def _add_rrid_entries(
7070
) -> None:
7171
rrid_entires: deque[RRIDEntry] = deque()
7272

73-
service = ScicrunchResourcesService(app)
73+
service = app[SCICRUNCH_SERVICE_APPKEY]
7474
classifiers = project_data["classifiers"]
7575
for classifier in classifiers:
7676
scicrunch_resource = await service.get_resource_atdb(rrid=classifier)

services/web/server/src/simcore_service_webserver/exporter/plugin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22

33
from aiohttp import web
4+
from simcore_service_webserver.scicrunch.plugin import setup_scicrunch
45

56
from ..application_setup import ModuleCategory, app_setup_func
67
from . import _handlers
@@ -19,4 +20,6 @@ def setup_exporter(app: web.Application) -> bool:
1920
# Rest-API routes: maps handlers with routes tags with "viewer" based on OAS operation_id
2021
app.router.add_routes(_handlers.routes)
2122

23+
setup_scicrunch(app)
24+
2225
return True

services/web/server/src/simcore_service_webserver/groups/_classifiers_service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
)
2525

2626
from ..scicrunch.errors import ScicrunchError
27-
from ..scicrunch.scicrunch_service import ScicrunchResourcesService
27+
from ..scicrunch.scicrunch_service import SCICRUNCH_SERVICE_APPKEY
2828
from ._classifiers_repository import GroupClassifierRepository
2929

3030
_logger = logging.getLogger(__name__)
@@ -119,7 +119,7 @@ async def _build_rrids_tree_view(
119119
msg = "Currently only 'std' option for the classifiers tree view is implemented"
120120
raise NotImplementedError(msg)
121121

122-
service = ScicrunchResourcesService(self.app)
122+
service = self.app[SCICRUNCH_SERVICE_APPKEY]
123123

124124
flat_tree_view: dict[TreePath, ClassifierItem] = {}
125125
for resource in await service.list_research_resources():

services/web/server/src/simcore_service_webserver/scicrunch/_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from common_library.logging.logging_errors import create_troubleshooting_log_kwargs
88
from pydantic import HttpUrl, ValidationError
99

10+
from ._client import SciCrunch
1011
from ._repository import ScicrunchResourcesRepository
1112
from .models import ResearchResource, ResearchResourceAtdB, ResourceHit
12-
from .service_client import SciCrunch
1313

1414
_logger = logging.getLogger(__name__)
1515

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
"""
2-
Notice that this is used as a submodule of groups'a app module
3-
"""
4-
51
import logging
62

73
from aiohttp import web
8-
from conftest import app
4+
from simcore_service_webserver.db.plugin import setup_db
95
from simcore_service_webserver.scicrunch._repository import ScicrunchResourcesRepository
106

117
from ..application_setup import ModuleCategory, app_setup_func
8+
from ._client import SciCrunch
129
from ._service import ScicrunchResourcesService
1310
from .scicrunch_service import SCICRUNCH_SERVICE_APPKEY
14-
from .service_client import SciCrunch
1511
from .settings import get_plugin_settings
1612

1713
_logger = logging.getLogger(__name__)
@@ -20,14 +16,21 @@
2016
async def _on_startup(app: web.Application):
2117
settings = get_plugin_settings(app)
2218

19+
# 1. scicrunch http client
2320
client = SciCrunch.acquire_instance(app, settings)
2421
assert client == SciCrunch.get_instance(app) # nosec
2522

23+
# 2. scicrunch repository (uses app[ENGINE_DB_CLIENT_APPKEY])
24+
repo = ScicrunchResourcesRepository.create_from_app(app)
25+
assert repo # nosec
26+
27+
# 3. scicrunch resources service
2628
service = ScicrunchResourcesService(
27-
repo=ScicrunchResourcesRepository.create_from_app(app),
28-
client=SciCrunch.get_instance(app),
29+
repo=repo,
30+
client=client,
2931
)
3032

33+
# store service in app
3134
app[SCICRUNCH_SERVICE_APPKEY] = service
3235

3336

@@ -40,4 +43,6 @@ async def _on_startup(app: web.Application):
4043
def setup_scicrunch(app: web.Application):
4144
assert get_plugin_settings(app) # nosec
4245

46+
setup_db(app) # needs engine
47+
4348
app.on_startup.append(_on_startup)

services/web/server/tests/unit/isolated/scicrunch/test_scicrunch_service_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
from servicelib.aiohttp.application import create_safe_application
2020
from servicelib.aiohttp.client_session import get_client_session
2121
from simcore_service_webserver.application_settings import setup_settings
22-
from simcore_service_webserver.scicrunch.plugin import (
23-
setup_scicrunch,
24-
)
25-
from simcore_service_webserver.scicrunch.service_client import (
22+
from simcore_service_webserver.scicrunch._client import (
2623
ResearchResource,
2724
SciCrunch,
2825
)
26+
from simcore_service_webserver.scicrunch.plugin import (
27+
setup_scicrunch,
28+
)
2929

3030

3131
@pytest.fixture

0 commit comments

Comments
 (0)