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

Implement URI mapping service #773

Merged
merged 2 commits into from
Mar 16, 2023
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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ install_requires =
click
more_click>=0.1.2
pydantic
curies
curies>=0.5.0

zip_safe = false
include_package_data = True
Expand Down
4 changes: 4 additions & 0 deletions src/bioregistry/app/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from textwrap import dedent
from typing import TYPE_CHECKING, Any, Mapping, Optional, Union

from curies.mapping_service import get_flask_mapping_blueprint
from flasgger import Swagger
from flask import Flask
from flask_bootstrap import Bootstrap4
Expand Down Expand Up @@ -169,6 +170,9 @@ def get_app(
app.register_blueprint(api_blueprint)
app.register_blueprint(ui_blueprint)

sparql_blueprint = get_flask_mapping_blueprint(app.manager.converter)
app.register_blueprint(sparql_blueprint)

# Make manager available in all jinja templates
app.jinja_env.globals.update(manager=app.manager, curie_to_str=curie_to_str)
return app
3 changes: 1 addition & 2 deletions src/bioregistry/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,6 @@ def get_converter(**kwargs) -> curies.Converter:
return manager.get_converter(**kwargs)


@lru_cache(1)
def get_default_converter() -> curies.Converter:
"""Get a converter from this manager."""
return manager.get_converter()
return manager.converter
9 changes: 9 additions & 0 deletions src/bioregistry/resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ def __init__(
self.provided_by = dict(provided_by)
self.has_parts = dict(has_parts)

self._converter = None

@property
def converter(self) -> curies.Converter:
"""Get the default converter."""
if self._converter is None:
self._converter = curies.Converter(records=self.get_curies_records())
return self._converter

def write_registry(self):
"""Write the registry."""
write_registry(self.registry)
Expand Down