Skip to content

Commit

Permalink
[Core] Allow overriding of identifier
Browse files Browse the repository at this point in the history
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 <david.feltell@foundry.com>
  • Loading branch information
feltech committed Jul 16, 2024
1 parent 79765b8 commit 0d2cfaf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
8 changes: 8 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -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
---------------

Expand Down
5 changes: 4 additions & 1 deletion plugin/openassetio_manager_bal/BasicAssetLibraryInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion plugin/openassetio_manager_bal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand All @@ -51,6 +52,8 @@
# PythonPluginSystemManagerPlugin's implementation.
from openassetio.pluginSystem import PythonPluginSystemManagerPlugin

from .BasicAssetLibraryInterface import ENV_VAR_IDENTIFIER_OVERRIDE, DEFAULT_IDENTIFIER


class BasicAssetLibraryPlugin(PythonPluginSystemManagerPlugin):
"""
Expand All @@ -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):
Expand Down
19 changes: 19 additions & 0 deletions tests/test_bal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 0d2cfaf

Please sign in to comment.