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

Add "library_json" setting #128

Merged
merged 1 commit into from
Sep 20, 2024

Conversation

feltech
Copy link
Member

@feltech feltech commented Sep 18, 2024

Closes #51.

Presently, BAL can only be configured using a JSON library file. This causes several problems with the authoring of automated tests within host integrations:

  • It is difficult to single-source inputs and expected values without authoring a JSON file in the test case.
  • It requires additional side-car data files to accompany the tests which may not be desirable.

So add a new setting, "library_json". This allows hosts to query for the current internal BAL library via settings(), and then mutate it and update BAL via a re-initialize().

The JSON must be passed from/to the manager in serialised form, since the settings dictionary must be coerced to/from a (C++) InfoDictionary, which is a simple key-value map, rather than an arbitrarily nested dictionary.

In addition, calculated "variables" (e.g. "bal_library_dir_url") cannot be provided when the library is given as a JSON string, since they are based on the location of the library_path.

If both library_path and library_json are provided, then library_json takes precedence. This allows a JSON library file to be provided initially, then the library mutated during test cases.

Recall that the OpenAssetIO initialize method can accept partial settings updates, meaning the manager retains any previous settings that are not explicitly overridden in the new settings dict. However, this does not apply to the special library_json setting here. This is a bit of an abuse for convenience. E.g. if we re-initialize with an empty settings dict, the initialization process falls back to using the previously-set library_path (if available) and resets the library to match the file.

This compromise is somewhat justified by analogy to current behaviour when BAL is re-initialised after entities have been published. In this case the new entities only exist in memory, and are lost when re-initialising, since the library JSON file is re-read and overwrites any changes. This is similar to how the library_json changes are lost by default when re-initializing.

Copy link

@foundry-markf foundry-markf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok to me!

Closes OpenAssetIO#51.

Presently, BAL can only be configured using a JSON library file. This
causes several problems with the authoring of automated tests within
host integrations:

* It is difficult to single-source inputs and expected values without
  authoring a JSON file in the test case.
* It requires additional side-car data files to accompany the tests
  which may not be desirable.

So add a new setting, `"library_json"`. This allows hosts to query for
the current internal BAL library via `settings()`, and then mutate it
and update BAL via a re-`initialize()`.

The JSON must be passed from/to the manager in serialised form, since
the settings dictionary must be coerced to/from a (C++)
`InfoDictionary`, which is a simple key-value map, rather than an
arbitrarily nested dictionary.

In addition, calculated `"variables"` (e.g. `"bal_library_dir_url"`)
cannot be provided when the library is given as a JSON string, since
they are based on the location of the `library_path`.

If both `library_path` and `library_json` are provided, then
`library_json` takes precedence. This allows a JSON library file to be
provided initially, then the library mutated during test cases.

Recall that the OpenAssetIO `initialize` method can accept partial
settings updates, meaning the manager retains any previous settings that
are not explicitly overridden in the new settings dict. However, this
does not apply to the special `library_json` setting here. This is a bit
of an abuse for convenience. E.g. if we re-initialize with an empty
settings dict, the initialization process falls back to using the
previously-set `library_path` (if available) and resets the library to
match the file.

This compromise is somewhat justified by analogy to current behaviour
when BAL is re-initialised after entities have been published. In this
case the new entities only exist in memory, and are lost when
re-initialising, since the library JSON file is re-read and overwrites
any changes. This is similar to how the `library_json` changes are lost
by default when re-initializing.

Signed-off-by: David Feltell <david.feltell@foundry.com>
@feltech feltech force-pushed the work/51-libraryFromJSONString branch from a16849b to cf87d46 Compare September 20, 2024 16:25
@feltech feltech merged commit 46ab725 into OpenAssetIO:main Sep 20, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Python config/library API
2 participants