Skip to content

Commit ffb3e36

Browse files
committed
Prefix all environment variables needed by integration with MWI_
Update README.md with new names for environment variables
1 parent 445bbaa commit ffb3e36

File tree

9 files changed

+40
-35
lines changed

9 files changed

+40
-35
lines changed

Development_Customization_Info.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ source .venv/bin/activate
2626
# Install the Python package (and dependencies) in development mode (skip this if already done)
2727
pip install -e .[dev]
2828
# Start the development server
29-
DEV=true adev runserver jupyter_matlab_proxy/app.py
29+
MWI_DEV=true adev runserver jupyter_matlab_proxy/app.py
3030
```
3131

3232
If you make any changes to either the JavaScript code or the Python code, then these apps will reload immediately showing the results. Bear in mind that this kind of live-reloading can have an impact on application state (on the serverside particularly). This occurs independently for the JavaScript and Python applications. So if you are working only on the frontend, the backend state will never be affected by changes to the frontend and vice-versa.

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,22 @@ If you want to use this integration with JupyterHub®, then you must install the
9090

9191
### Environment Variables
9292

93-
To control the behavior of the MATLAB integration for Jupyter, you can optionally specify the environment variables described in this section. You must specify these variables before starting your Jupyter environment. For example, specify the variable `APP_PORT` to be equal to 8888 when you start the Jupyter notebook using the command below:
93+
To control the behavior of the MATLAB integration for Jupyter, you can optionally specify the environment variables described in this section. You must specify these variables before starting your Jupyter environment. For example, specify the variable `MWI_APP_PORT` to be equal to 8888 when you start the Jupyter notebook using the command below:
9494

9595
```bash
96-
env APP_PORT=8888 jupyter notebook
96+
env MWI_APP_PORT=8888 jupyter notebook
9797
```
9898
**MARKDOWN TABLE**
9999

100100
These values are preset for you when you access the integration from the Jupyter console.
101101
| Name | Type | Example Value | Description |
102102
| ---- | ---- | ------------- | ----------- |
103103
| **MLM_LICENSE_FILE** | string | `"[email protected]"` | When you want to use either a license file or a network license manager to license MATLAB, specify this variable.</br> For example, specify the location of the network license manager to be `123@hostname`|
104-
| **LOG_LEVEL** | string | `"CRITICAL"` | Specify the Python log level to be one of the following `NOTSET`, `DEBUG`, `INFO`, `WARN`, `ERROR`, or `CRITICAL`. For more information on Python log levels, see [Logging Levels](https://docs.python.org/3/library/logging.html#logging-levels) .<br />The default value is `INFO`. |
105-
| **LOG_FILE** | string | `"/tmp/logs.txt"` | Specify the full path to the file where you want the logs to be written. |
106-
| **BASE_URL** | string | `"/matlab"` | Set to control the base URL of the app. BASE_URL should start with `/` or be `empty`. |
107-
| **APP_PORT** | integer | `8080` | Specify the port for the HTTP server to listen on. |
108-
| **CUSTOM_HTTP_HEADERS** | string |`'{"Content-Security-Policy": "frame-ancestors *.example.com:*"}'`<br /> OR <br />`"/path/to/your/custom/http-headers.json"` |Specify valid HTTP headers as JSON data in a string format<br />OR <br /> Specify the full path to the JSON file containing (valid) HTTP headers. These headers would be injected into the HTTP response sent to the browser. </br> For more information, see the CUSTOM_HTTP_HEADERS sub-section in the Advanced Usage section. |
104+
| **MWI_LOG_LEVEL** | string | `"CRITICAL"` | Specify the Python log level to be one of the following `NOTSET`, `DEBUG`, `INFO`, `WARN`, `ERROR`, or `CRITICAL`. For more information on Python log levels, see [Logging Levels](https://docs.python.org/3/library/logging.html#logging-levels) .<br />The default value is `INFO`. |
105+
| **MWI_LOG_FILE** | string | `"/tmp/logs.txt"` | Specify the full path to the file where you want the logs to be written. |
106+
| **MWI_BASE_URL** | string | `"/matlab"` | Set to control the base URL of the app. MWI_BASE_URL should start with `/` or be `empty`. |
107+
| **MWI_APP_PORT** | integer | `8080` | Specify the port for the HTTP server to listen on. |
108+
| **MWI_CUSTOM_HTTP_HEADERS** | string |`'{"Content-Security-Policy": "frame-ancestors *.example.com:*"}'`<br /> OR <br />`"/path/to/your/custom/http-headers.json"` |Specify valid HTTP headers as JSON data in a string format<br />OR <br /> Specify the full path to the JSON file containing (valid) HTTP headers. These headers would be injected into the HTTP response sent to the browser. </br> For more information, see the MWI_CUSTOM_HTTP_HEADERS sub-section in the Advanced Usage section. |
109109

110110

111111
## Feedback
@@ -115,7 +115,7 @@ We encourage you to try this repository with your environment and provide feedba
115115

116116
## Advanced Usage
117117

118-
#### CUSTOM_HTTP_HEADERS:
118+
#### MWI_CUSTOM_HTTP_HEADERS:
119119
If the browser renders the MATLAB Integration for Jupyter with some other content, then web browsers could block the integration because of mismatch of `Content-Security-Policy` header in the response headers from the integration.
120120

121121
To avoid this, providing custom HTTP headers allow browsers to load the content.
@@ -131,7 +131,7 @@ If this integration is rendered along with some other content on the domain `www
131131
or if you are passing the custom http headers as a string in the environment variable. In bash shell, it could look like :
132132

133133
```bash
134-
export CUSTOM_HTTP_HEADERS='{"Content-Security-Policy": "frame-ancestors *.example.com:* https://www.example.com:*;"}'
134+
export MWI_CUSTOM_HTTP_HEADERS='{"Content-Security-Policy": "frame-ancestors *.example.com:* https://www.example.com:*;"}'
135135
```
136136

137137
If you add the `frame-ancestors` directive, the browser does not block the content of this integration hosted on the domain `www.example.com`

jupyter_matlab_proxy/mw_environment_variables.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@ def get_env_name_network_license_manager():
99
return "MLM_LICENSE_FILE"
1010

1111

12+
def get_env_name_mhlm_context():
13+
"""Specifies the context from which MHLM was initiated. Used by DDUX in MATLAB."""
14+
return "MHLM_CONTEXT"
15+
16+
1217
def get_env_name_logging_level():
1318
"""Specifies the logging level used by app's loggers"""
14-
return "LOG_LEVEL"
19+
return "MWI_LOG_LEVEL"
1520

1621

1722
def get_env_name_log_file():
1823
"""Specifies a file into which logging content is directed"""
19-
return "LOG_FILE"
24+
return "MWI_LOG_FILE"
2025

2126

2227
def get_env_name_base_url():
@@ -26,7 +31,7 @@ def get_env_name_base_url():
2631
Note: The website runs on a URL of the form:
2732
www.<SERVER ADDRESS>:<PORT NUMBER>/<BASE_URL>/index.html
2833
"""
29-
return "BASE_URL"
34+
return "MWI_BASE_URL"
3035

3136

3237
def get_env_name_app_port():
@@ -36,32 +41,27 @@ def get_env_name_app_port():
3641
Note: The website runs on a URL of the form:
3742
www.<SERVER ADDRESS>:<PORT NUMBER>/<BASE_URL>/index.html
3843
"""
39-
return "APP_PORT"
44+
return "MWI_APP_PORT"
4045

4146

4247
def get_env_name_custom_http_headers():
4348
"""Specifies HTTP headers as JSON content, to be injected into responses sent to the browser"""
44-
return "CUSTOM_HTTP_HEADERS"
49+
return "MWI_CUSTOM_HTTP_HEADERS"
4550

4651

4752
def get_env_name_app_host():
4853
"""Specifies the host on which the TCP site (aiohttp server) is being run."""
49-
return "APP_HOST"
50-
51-
52-
def get_env_name_mhlm_context():
53-
"""Specifies the context from which MHLM was initiated. Used by DDUX in MATLAB."""
54-
return "MHLM_CONTEXT"
54+
return "MWI_APP_HOST"
5555

5656

5757
def get_env_name_testing():
5858
"""Set to true when we are running tests in development mode."""
59-
return "TEST"
59+
return "MWI_TEST"
6060

6161

6262
def get_env_name_development():
6363
"""Set to true when we are in development mode."""
64-
return "DEV"
64+
return "MWI_DEV"
6565

6666

6767
def is_development_mode_enabled():

pytest.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[pytest]
22
env =
3-
D:DEV=true
4-
D:TEST=true
3+
D:MWI_DEV=true
4+
D:MWI_TEST=true
55
testpaths =
66
tests
77

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import os, pytest, shutil
44
from jupyter_matlab_proxy import settings
5+
from jupyter_matlab_proxy import mw_environment_variables as mw_env
56

67

78
def pytest_generate_tests(metafunc):
8-
os.environ["DEV"] = "true"
9+
os.environ[mw_env.get_env_name_development()] = "true"
910

1011

1112
def __get_matlab_config_file():

tests/test_jupyter_server_proxy.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import jupyter_matlab_proxy
44
import os
55
from pathlib import Path
6+
from jupyter_matlab_proxy import mw_environment_variables as mw_env
67

78

89
def test_get_env():
910
port = 10000
1011
base_url = "/foo/"
1112
r = jupyter_matlab_proxy._get_env(port, base_url)
12-
assert r["APP_PORT"] == str(port)
13-
assert r["BASE_URL"] == f"{base_url}matlab"
13+
assert r[mw_env.get_env_name_app_port()] == str(port)
14+
assert r[mw_env.get_env_name_base_url()] == f"{base_url}matlab"
1415

1516

1617
def test_setup_matlab():

tests/test_non_dev_mode.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
def matlab_port_fixture(monkeypatch):
1919
"""A pytest fixture which monkeypatches an environment variable.
2020
21-
Pytest by default sets DEV to true.
21+
Pytest by default sets MWI_DEV to true.
2222
Args:
2323
monkeypatch : A built-in pytest fixture
2424
"""
@@ -127,8 +127,8 @@ def test_server_fixture(
127127
loop : Event Loop
128128
aiohttp_client : A built-in pytest fixture
129129
build_frontend: Pytest fixture which generates the directory structure of static files with some placeholder content
130-
matlab_port_setup: Pytest fixture which monkeypatches 'DEV' env to False. This is required for the test_server to add static content
131-
mock_settings_get: Pytest fixture which mocks settings.get() to return dev settings when env 'DEV' is set to False.
130+
matlab_port_setup: Pytest fixture which monkeypatches 'MWI_DEV' env to False. This is required for the test_server to add static content
131+
mock_settings_get: Pytest fixture which mocks settings.get() to return dev settings when env 'MWI_DEV' is set to False.
132132
133133
Yields:
134134
[aiohttp_client]: A aiohttp_client to send HTTP requests.

tests/test_settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ def patch_env_variables_fixture(monkeypatch):
130130
Args:
131131
monkeypatch : Built-in pytest fixture
132132
"""
133-
monkeypatch.setenv("BASE_URL", "localhost")
134-
monkeypatch.setenv("APP_PORT", "8900")
135-
monkeypatch.setenv("APP_HOST", "localhost")
133+
monkeypatch.setenv(mw_env.get_env_name_base_url(), "localhost")
134+
monkeypatch.setenv(mw_env.get_env_name_app_port(), "8900")
135+
monkeypatch.setenv(mw_env.get_env_name_app_host(), "localhost")
136136
monkeypatch.setenv(mw_env.get_env_name_network_license_manager(), "123@nlm")
137137

138138

tests/util/test_custom_headers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010

1111
def test_get_custom_header_env_var():
1212
"""Test to check if the __get_custom_header_env_var() method returns the expected environment variable name"""
13-
assert "CUSTOM_HTTP_HEADERS" == custom_http_headers.__get_custom_header_env_var()
13+
assert (
14+
mw_env.get_env_name_custom_http_headers()
15+
== custom_http_headers.__get_custom_header_env_var()
16+
)
1417

1518

1619
def test_get_exception_statement():

0 commit comments

Comments
 (0)