Skip to content

Commit

Permalink
Add optional portable information to subscription (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
anders-kiaer authored Dec 1, 2019
1 parent ba8bf4b commit 25582b1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
9 changes: 5 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ something like
import webviz_config

@webviz_config.SHARED_SETTINGS_SUBSCRIPTIONS.subscribe("some_key")
def subscribe(some_key, config_folder):
def subscribe(some_key, config_folder, portable):
# The input argument some_key given to this function is equal to
# shared_settings["some_key"] provided by the user from the configuration file.

Expand All @@ -420,10 +420,11 @@ The (optionally transformed) `shared_settings` are accessible to containers thro
the `app` instance (see [callbacks](#callbacks)). E.g., in this case the wanted settings
are found as `app.webviz_settings["shared_settings"]["some_key"]`.

Stating the second input argument `config_folder` in the function signature is not
necessary, however if you do you will get a
Stating the input arguments named `config_folder` and/or `portable` in the function
signature is not necessary, however if you do you will get a
[`pathlib.Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)
instance representing the absolute path to the configuration file that was used.
instance representing the absolute path to the configuration file that was used, and/or
a boolean value stating if the Webviz application running is a portable one.

### Custom ad-hoc containers

Expand Down
16 changes: 10 additions & 6 deletions webviz_config/_shared_settings_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def register(function):

return register

def transformed_settings(self, shared_settings, config_folder):
def transformed_settings(self, shared_settings, config_folder, portable):
"""Called from the app template, which returns the `shared_settings`
after all third-party package subscriptions have done their
(optional) transfomrations.
Expand All @@ -34,11 +34,15 @@ def transformed_settings(self, shared_settings, config_folder):

for subscription in self._subscriptions:
key, function = subscription["key"], subscription["function"]
requires_config_folder = len(inspect.getfullargspec(function).args) > 1
shared_settings[key] = (
function(shared_settings.get(key), pathlib.Path(config_folder))
if requires_config_folder
else function(shared_settings.get(key))
shared_settings[key] = function(
*[
pathlib.Path(config_folder)
if arg == "config_folder"
else portable
if arg == "portable"
else shared_settings.get(arg)
for arg in inspect.getfullargspec(function).args
]
)

return shared_settings
Expand Down
2 changes: 1 addition & 1 deletion webviz_config/templates/copy_data_template.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ app.config.suppress_callback_exceptions = True

app.webviz_settings = {
"shared_settings": webviz_config.SHARED_SETTINGS_SUBSCRIPTIONS.transformed_settings(
{{ shared_settings }}, {{ config_folder }}
{{ shared_settings }}, {{ config_folder }}, False
),
"plotly_layout": {{ plotly_layout }},
}
Expand Down
2 changes: 1 addition & 1 deletion webviz_config/templates/webviz_template.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ app.config.suppress_callback_exceptions = True

app.webviz_settings = {
"shared_settings": webviz_config.SHARED_SETTINGS_SUBSCRIPTIONS.transformed_settings(
{{ shared_settings }}, {{ config_folder }}
{{ shared_settings }}, {{ config_folder }}, {{ portable }}
),
"portable": {{ portable }},
"plotly_layout": {{ plotly_layout }},
Expand Down

0 comments on commit 25582b1

Please sign in to comment.