From 0d2cfaf89493173006d8d0bae8679221d5354c55 Mon Sep 17 00:00:00 2001 From: David Feltell Date: Thu, 11 Jul 2024 18:42:59 +0100 Subject: [PATCH] [Core] Allow overriding of identifier Needed for e2e testing of OpenAssetIO/OpenAssetIO#1202. The upcoming hybrid plugin system will work by locating multiple plugins that all advertise the same unique identifier and combining them. In preparation for e2e testing of this, make BAL's plugin identifier configurable by an environment variable, so that it can be set to the same identifier as another plugin on the system. We cannot use other types of settings such as the JSON database, since the plugin identifier is queried before the settings are provided. Signed-off-by: David Feltell --- RELEASE_NOTES.md | 8 ++++++++ .../BasicAssetLibraryInterface.py | 5 ++++- plugin/openassetio_manager_bal/__init__.py | 5 ++++- tests/test_bal.py | 19 +++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index dcb3e7d..039be0f 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,6 +1,14 @@ Release Notes ============= +v1.0.0-alpha.x +--------------- + +### New features + +- Added support for `OPENASSETIO_BAL_IDENTIFIER` environment variable, + for overriding the identifier advertised by the BAL plugin/manager. + v1.0.0-alpha.16 --------------- diff --git a/plugin/openassetio_manager_bal/BasicAssetLibraryInterface.py b/plugin/openassetio_manager_bal/BasicAssetLibraryInterface.py index 7ceda15..3d7fe4d 100644 --- a/plugin/openassetio_manager_bal/BasicAssetLibraryInterface.py +++ b/plugin/openassetio_manager_bal/BasicAssetLibraryInterface.py @@ -53,6 +53,9 @@ "BasicAssetLibraryInterface", ] + +DEFAULT_IDENTIFIER = "org.openassetio.examples.manager.bal" +ENV_VAR_IDENTIFIER_OVERRIDE = "OPENASSETIO_BAL_IDENTIFIER" SETTINGS_KEY_LIBRARY_PATH = "library_path" SETTINGS_KEY_SIMULATED_QUERY_LATENCY = "simulated_query_latency_ms" SETTINGS_KEY_ENTITY_REFERENCE_URL_SCHEME = "entity_reference_url_scheme" @@ -105,7 +108,7 @@ def __init__(self): self.__library = {} def identifier(self): - return "org.openassetio.examples.manager.bal" + return os.environ.get(ENV_VAR_IDENTIFIER_OVERRIDE, DEFAULT_IDENTIFIER) def displayName(self): # Deliberately includes unicode chars to test string handling diff --git a/plugin/openassetio_manager_bal/__init__.py b/plugin/openassetio_manager_bal/__init__.py index a9912c9..dd63944 100644 --- a/plugin/openassetio_manager_bal/__init__.py +++ b/plugin/openassetio_manager_bal/__init__.py @@ -42,6 +42,7 @@ need to be on `$PYTHONPATH` directly, the plugin system takes care of extending Python's runtime paths accordingly. """ +import os # pylint: disable=import-outside-toplevel, invalid-name # @@ -51,6 +52,8 @@ # PythonPluginSystemManagerPlugin's implementation. from openassetio.pluginSystem import PythonPluginSystemManagerPlugin +from .BasicAssetLibraryInterface import ENV_VAR_IDENTIFIER_OVERRIDE, DEFAULT_IDENTIFIER + class BasicAssetLibraryPlugin(PythonPluginSystemManagerPlugin): """ @@ -61,7 +64,7 @@ class BasicAssetLibraryPlugin(PythonPluginSystemManagerPlugin): @staticmethod def identifier(): - return "org.openassetio.examples.manager.bal" + return os.getenv(ENV_VAR_IDENTIFIER_OVERRIDE, DEFAULT_IDENTIFIER) @classmethod def interface(cls): diff --git a/tests/test_bal.py b/tests/test_bal.py index f31993c..67a745f 100644 --- a/tests/test_bal.py +++ b/tests/test_bal.py @@ -74,6 +74,25 @@ def test_exposes_plugin_attribute_with_correct_type(self): assert issubclass(openassetio_manager_bal.plugin, PythonPluginSystemManagerPlugin) + def test_when_not_overridden_by_env_var_then_identifier_matches_default(self): + import openassetio_manager_bal # pylint: disable=import-outside-toplevel + + assert ( + openassetio_manager_bal.plugin.identifier() == "org.openassetio.examples.manager.bal" + ) + assert ( + openassetio_manager_bal.plugin.interface().identifier() + == "org.openassetio.examples.manager.bal" + ) + + def test_when_overridden_by_env_var_then_identifier_matches_env_var(self, monkeypatch): + import openassetio_manager_bal # pylint: disable=import-outside-toplevel + + monkeypatch.setenv("OPENASSETIO_BAL_IDENTIFIER", "foo") + + assert openassetio_manager_bal.plugin.identifier() == "foo" + assert openassetio_manager_bal.plugin.interface().identifier() == "foo" + @pytest.fixture def bal_business_logic_suite(bal_base_dir):