forked from road-core/service
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OLS-1229: GradioUI environment variables
Signed-off-by: Pavel Tisnovsky <[email protected]>
- Loading branch information
Showing
3 changed files
with
39 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""Environment variables handling.""" | ||
|
||
import os | ||
import tempfile | ||
|
||
|
||
def configure_gradio_ui_envs() -> None: | ||
"""Configure GradioUI framework environment variables.""" | ||
# disable Gradio analytics, which calls home to https://api.gradio.app | ||
os.environ["GRADIO_ANALYTICS_ENABLED"] = "false" | ||
|
||
# Setup config directory for Matplotlib. It will be used to store info | ||
# about fonts (usually one JSON file) and it really is just temporary | ||
# storage that can be deleted at any time and recreated later. | ||
# Fixes: https://issues.redhat.com/browse/OLS-301 | ||
tempdir = os.path.join(tempfile.gettempdir(), "matplotlib") | ||
os.environ["MPLCONFIGDIR"] = tempdir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"""Unit tests for functions defined in environments.py.""" | ||
|
||
import os | ||
from unittest.mock import patch | ||
|
||
from ols.utils.environments import configure_gradio_ui_envs | ||
|
||
|
||
@patch.dict(os.environ, {"GRADIO_ANALYTICS_ENABLED": "", "MPLCONFIGDIR": ""}) | ||
def test_configure_gradio_ui_envs(): | ||
"""Test the function configure_gradio_ui_envs.""" | ||
# setup before tested function is called | ||
assert os.environ.get("GRADIO_ANALYTICS_ENABLED", None) == "" | ||
assert os.environ.get("MPLCONFIGDIR", None) == "" | ||
|
||
# call the tested function | ||
configure_gradio_ui_envs() | ||
|
||
# expected environment variables | ||
assert os.environ.get("GRADIO_ANALYTICS_ENABLED", None) == "false" | ||
assert os.environ.get("MPLCONFIGDIR", None) != "" |