@@ -26,51 +26,91 @@ def get_matlab_version(matlab_path):
26
26
return root .find ("release" ).text
27
27
28
28
29
- def get (dev = False ):
30
- devel_file = Path (__file__ ).resolve ().parent / "./devel.py"
31
- matlab_startup_file = str (Path (__file__ ).resolve ().parent / "matlab" / "startup.m" )
32
- matlab_ready_file = Path (tempfile .mkstemp ()[1 ])
29
+ def get_ws_env_settings ():
33
30
ws_env = (os .getenv ("WS_ENV" ) or "" ).lower ()
34
31
ws_env_suffix = f"-{ ws_env } " if "integ" in ws_env else ""
35
32
33
+ return ws_env , ws_env_suffix
34
+
35
+
36
+ def get_dev_settings ():
37
+ devel_file = Path (__file__ ).resolve ().parent / "./devel.py"
38
+ matlab_ready_file = Path (tempfile .mkstemp ()[1 ])
39
+ ws_env , ws_env_suffix = get_ws_env_settings ()
40
+
41
+ return {
42
+ "matlab_path" : Path (),
43
+ "matlab_version" : "R2020b" ,
44
+ "matlab_cmd" : [
45
+ "python" ,
46
+ "-u" ,
47
+ str (devel_file ),
48
+ "matlab" ,
49
+ "--ready-file" ,
50
+ str (matlab_ready_file ),
51
+ ],
52
+ "xvfb_cmd" : [
53
+ "python" ,
54
+ "-u" ,
55
+ str (devel_file ),
56
+ "xvfb" ,
57
+ "--ready-file" ,
58
+ str (Path (tempfile .gettempdir ()) / ".X11-unix" / "X1" ),
59
+ ],
60
+ "matlab_ready_file" : matlab_ready_file ,
61
+ "base_url" : os .environ .get ("BASE_URL" , "" ),
62
+ "app_port" : os .environ .get ("APP_PORT" , 8000 ),
63
+ "host_interface" : os .environ .get ("APP_HOST" , "127.0.0.1" ),
64
+ "mwapikey" : str (uuid .uuid4 ()),
65
+ "matlab_protocol" : "http" ,
66
+ "matlab_display" : ":1" ,
67
+ "nlm_conn_str" : os .environ .get ("MLM_LICENSE_FILE" ),
68
+ "matlab_config_file" : Path (tempfile .gettempdir ())
69
+ / ".matlab"
70
+ / "proxy_app_config.json" ,
71
+ "ws_env" : ws_env ,
72
+ "mwa_api_endpoint" : f"https://login{ ws_env_suffix } .mathworks.com/authenticationws/service/v4" ,
73
+ "mhlm_api_endpoint" : f"https://licensing{ ws_env_suffix } .mathworks.com/mls/service/v1/entitlement/list" ,
74
+ "mwa_login" : f"https://login{ ws_env_suffix } .mathworks.com" ,
75
+ }
76
+
77
+
78
+ def get (dev = False ):
79
+ """Method which returns the settings specific to the environment in which the server is running in
80
+ If the environment variable 'TEST' is set to true, will make some changes to the dev settings.
81
+
82
+ Args:
83
+ dev (bool, optional): development environment. Defaults to False.
84
+
85
+ Returns:
86
+ Dict: Containing data on how to start MATLAB among other information.
87
+ """
88
+
36
89
if dev :
37
- return {
38
- "matlab_path" : Path (),
39
- "matlab_version" : "R2020b" ,
40
- "matlab_cmd" : [
41
- "python" ,
42
- "-u" ,
43
- str (devel_file ),
44
- "matlab" ,
45
- "--ready-file" ,
46
- str (matlab_ready_file ),
47
- ],
48
- "xvfb_cmd" : [
49
- "python" ,
50
- "-u" ,
51
- str (devel_file ),
52
- "xvfb" ,
53
- "--ready-file" ,
54
- str (Path (tempfile .gettempdir ()) / ".X11-unix" / "X1" ),
55
- ],
56
- "matlab_ready_file" : matlab_ready_file ,
57
- "base_url" : os .environ .get ("BASE_URL" , "" ),
58
- "app_port" : os .environ .get ("APP_PORT" , 8000 ),
59
- "host_interface" : os .environ .get ("APP_HOST" , "127.0.0.1" ),
60
- "mwapikey" : str (uuid .uuid4 ()),
61
- "matlab_protocol" : "http" ,
62
- "matlab_display" : ":1" ,
63
- "nlm_conn_str" : os .environ .get ("MLM_LICENSE_FILE" ),
64
- "matlab_config_file" : Path (tempfile .gettempdir ())
65
- / ".matlab"
66
- / "proxy_app_config.json" ,
67
- "ws_env" : ws_env ,
68
- "mwa_api_endpoint" : f"https://login{ ws_env_suffix } .mathworks.com/authenticationws/service/v4" ,
69
- "mhlm_api_endpoint" : f"https://licensing{ ws_env_suffix } .mathworks.com/mls/service/v1/entitlement/list" ,
70
- "mwa_login" : f"https://login{ ws_env_suffix } .mathworks.com" ,
71
- }
90
+ settings = get_dev_settings ()
91
+
92
+ # If running tests using Pytest, it will set environment variable TEST to true before running tests.
93
+ # Will make test env specific changes before returning the settings.
94
+ if os .environ .get ("TEST" , "False" ).lower () == "true" :
95
+
96
+ # Set ready_delay value to 0 for faster fake MATLAB startup.
97
+ ready_delay = ["--ready-delay" , "0" ]
98
+ matlab_cmd = settings ["matlab_cmd" ]
99
+ matlab_cmd [4 :4 ] = ready_delay
100
+ settings ["matlab_cmd" ] = matlab_cmd
101
+
102
+ # Set NLM Connection string. Server will start using this connection string for licensing
103
+ settings ["nlm_conn_str" ] = "abc@nlm"
104
+
105
+ return settings
106
+
72
107
else :
108
+ matlab_startup_file = str (
109
+ Path (__file__ ).resolve ().parent / "matlab" / "startup.m"
110
+ )
73
111
matlab_path = get_matlab_path ()
112
+ ws_env , ws_env_suffix = get_ws_env_settings ()
113
+
74
114
return {
75
115
"matlab_path" : matlab_path ,
76
116
"matlab_version" : get_matlab_version (matlab_path ),
@@ -102,7 +142,8 @@ def get(dev=False):
102
142
"host_interface" : os .environ .get ("APP_HOST" ),
103
143
"mwapikey" : str (uuid .uuid4 ()),
104
144
"matlab_protocol" : "https" ,
105
- "matlab_display" : ":1" ,
145
+ # TODO: Uncomment this ?
146
+ # "matlab_display": ":1",
106
147
"nlm_conn_str" : os .environ .get ("MLM_LICENSE_FILE" ),
107
148
"matlab_config_file" : Path .home () / ".matlab" / "proxy_app_config.json" ,
108
149
"ws_env" : ws_env ,
0 commit comments