From ac2a718560326a2ecd0fcb0eda5c84a4feaa51a7 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt Date: Tue, 6 Dec 2022 23:31:35 +0100 Subject: [PATCH] Improve checking if first party deployment --- src/bioregistry/app/cli.py | 4 ++++ src/bioregistry/app/impl.py | 17 ++++++++--------- src/bioregistry/constants.py | 5 ++++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/bioregistry/app/cli.py b/src/bioregistry/app/cli.py index d5ea5868a..eb53543af 100644 --- a/src/bioregistry/app/cli.py +++ b/src/bioregistry/app/cli.py @@ -71,6 +71,10 @@ def web( app = get_app( manager=manager, config=config, + first_party=registry is None + and metaregistry is None + and collections is None + and contexts is None, ) run_app( app=app, diff --git a/src/bioregistry/app/impl.py b/src/bioregistry/app/impl.py index 0889d3847..11b7e625a 100644 --- a/src/bioregistry/app/impl.py +++ b/src/bioregistry/app/impl.py @@ -87,12 +87,15 @@ def get_app( - manager: Optional[Manager] = None, config: Union[None, str, Path, Mapping[str, Any]] = None + manager: Optional[Manager] = None, + config: Union[None, str, Path, Mapping[str, Any]] = None, + first_party: bool = True, ) -> Flask: """Prepare the flask application. :param manager: A pre-configured manager. If none given, uses the default manager. :param config: Additional configuration to be passed to the flask application. See below. + :param first_party: Set to true if deploying the "canonical" bioregistry instance :returns: An instantiated flask application :raises ValueError: if there's an issue with the configuration's integrity """ @@ -109,13 +112,9 @@ def get_app( app.config.setdefault("METAREGISTRY_VERSION", version.get_version()) app.config.setdefault("METAREGISTRY_EXAMPLE_PREFIX", "chebi") app.config.setdefault("METAREGISTRY_EXAMPLE_IDENTIFIER", "138488") + app.config.setdefault("METAREGISTRY_FIRST_PARTY", first_party) - if manager is None: - manager = resource_manager.manager - app.config.setdefault("METAREGISTRY_FIRST_PARTY", True) - else: - app.config.setdefault("METAREGISTRY_FIRST_PARTY", False) - app.manager = manager + app.manager = manager or resource_manager.manager example_prefix = app.config["METAREGISTRY_EXAMPLE_PREFIX"] resource = app.manager.registry.get(example_prefix) @@ -143,12 +142,12 @@ def get_app( "url": "https://github.com/biopragmatics/bioregistry/blob/main/LICENSE", }, }, - "host": manager.base_url, + "host": app.manager.base_url, "tags": [ { "name": "collections", "externalDocs": { - "url": f"{manager.base_url}/collection/", + "url": f"{app.manager.base_url}/collection/", }, }, ], diff --git a/src/bioregistry/constants.py b/src/bioregistry/constants.py index f9746bdd0..342920fb8 100644 --- a/src/bioregistry/constants.py +++ b/src/bioregistry/constants.py @@ -97,8 +97,11 @@ CURIE_VALIDATION_DATA_PATH = CURIE_VALIDATION.joinpath("data.tsv") CURIE_VALIDATION_SVG_PATH = CURIE_VALIDATION.joinpath("results.svg") +BIOREGISTRY_DEFAULT_BASE_URL = "https://bioregistry.io" #: The URL of the remote Bioregistry site -BIOREGISTRY_REMOTE_URL = pystow.get_config("bioregistry", "url") or "https://bioregistry.io" +BIOREGISTRY_REMOTE_URL = pystow.get_config( + "bioregistry", "url", default=BIOREGISTRY_DEFAULT_BASE_URL +) #: Resolution is broken on identifiers.org for the following IDOT_BROKEN = {