Skip to content

Commit bd1a014

Browse files
krisctlprabhakk-mw
authored andcommitted
Passes environment variables available with matlab-proxy to xvfb process at time of xvfb process creation.
fixes #17 fixes #18
1 parent 482789f commit bd1a014

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

matlab_proxy/app_state.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,20 @@ async def __setup_env_for_matlab(self) -> dict:
628628

629629
return matlab_env
630630

631+
def __filter_env_variables(env_vars: dict[str, str], prefix: str) -> dict[str, str]:
632+
"""Removes the keys that starts with the prefix supplied to this function
633+
634+
Args:
635+
env_vars (dict[str, str]): dict to be filtered
636+
prefix (str): starting characters of the keys to be removed
637+
638+
Returns:
639+
dict[str, str]: dict with filtered keys
640+
"""
641+
return {
642+
key: value for key, value in env_vars.items() if not key.startswith(prefix)
643+
}
644+
631645
async def __start_xvfb_process(self):
632646
"""Private method to start the xvfb process. Will set appropriate
633647
errors to self.error and return None when any exceptions are raised.
@@ -639,9 +653,14 @@ async def __start_xvfb_process(self):
639653
# Start Xvfb process and update display number in settings
640654
create_xvfb_cmd = self.settings["create_xvfb_cmd"]
641655
xvfb_cmd, dpipe = create_xvfb_cmd()
656+
filtered_env_variables = AppState.__filter_env_variables(
657+
os.environ.copy(), "MWI_"
658+
)
642659

643660
try:
644-
xvfb, display_port = await mw.create_xvfb_process(xvfb_cmd, dpipe)
661+
xvfb, display_port = await mw.create_xvfb_process(
662+
xvfb_cmd, dpipe, filtered_env_variables
663+
)
645664
self.settings["matlab_display"] = ":" + str(display_port)
646665

647666
logger.debug(f"Started Xvfb with PID={xvfb.pid} on DISPLAY={display_port}")

matlab_proxy/util/mw.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def parse_other_error(logs):
257257
)
258258

259259

260-
async def create_xvfb_process(xvfb_cmd, pipe, env={}):
260+
async def create_xvfb_process(xvfb_cmd, pipe, env=None):
261261
"""Creates the Xvfb process.
262262
263263
The Xvfb process is run with '-displayfd' flag set. This makes Xvfb choose an available

0 commit comments

Comments
 (0)