@@ -28,14 +28,24 @@ def __init__(self, json_params: dict, _id: str = None):
2828
2929 def _custom_process (self , json_config : dict ) -> dict :
3030 """
31- This function predicts from a model, a dataset, and a new dataset
31+ This function is called to execute the custom process which sets up Superset.
3232 """
3333 # Map settings
3434 port = json_config ["port" ]
3535 python_path = json_config ["pythonPath" ]
36+ app_data_path = json_config .get ("appDataPath" )
37+
38+ if not app_data_path :
39+ # Fallback to default locations if not provided (for backward compatibility or testing)
40+ if sys .platform == "win32" :
41+ app_data_path = str (Path (os .getenv ('APPDATA' )) / "medomics-platform" )
42+ elif sys .platform == "darwin" :
43+ app_data_path = str (Path .home () / "Library/Application Support/medomics-platform" )
44+ else :
45+ app_data_path = str (Path .home () / ".config/medomics-platform" )
3646
3747 # Set up Superset
38- result = self .setup_superset (port , python_path )
48+ result = self .setup_superset (port , python_path , app_data_path )
3949
4050 return result
4151
@@ -53,13 +63,14 @@ def run_command(self, command, env=None, capture_output=True, timeout=None):
5363 return {"error" : f"Error while running command: { command } . Full error log:" + e .stderr }
5464
5565
56- def setup_superset (self , port , python_path ):
66+ def setup_superset (self , port , python_path , app_data_path ):
5767 """
5868 Set up Superset with the provided settings.
5969
6070 Args:
6171 scripts_path (path): The path to the Python scripts directory.
6272 port (path): The port on which to run Superset.
73+ app_data_path (path): The path to the application data directory.
6374
6475 Returns:
6576 A dictionary containing the error message, if any.
@@ -70,7 +81,7 @@ def setup_superset(self, port, python_path):
7081
7182 # Check if the virtual environment exists
7283 self .set_progress (now = progress , label = "Checking the Superset virtual environment..." )
73- manager = SupersetEnvManager (python_path )
84+ manager = SupersetEnvManager (python_path , app_data_path )
7485 if not manager .check_env_exists ():
7586 print ("Creating Superset virtual environment..." )
7687 self .set_progress (now = self ._progress ["now" ]+ step , label = "Creating Superset virtual environment..." )
@@ -147,7 +158,7 @@ def setup_superset(self, port, python_path):
147158 # Initialize the database
148159 print ("Initializing the Superset database..." )
149160 self .set_progress (now = self ._progress ["now" ]+ step , label = "Initializing the Superset database..." )
150- result = self .run_command (f"{ superset_path } db upgrade" , env )
161+ result = self .run_command (f' "{ superset_path } " db upgrade' , env )
151162 if "error" in result :
152163 return result
153164
@@ -162,7 +173,7 @@ def setup_superset(self, port, python_path):
162173 "password" : "admin" ,
163174 }
164175 result = self .run_command (
165- f"{ superset_path } fab create-admin "
176+ f' "{ superset_path } " fab create-admin '
166177 f"--username { admin_user ['username' ]} "
167178 f"--firstname { admin_user ['firstname' ]} "
168179 f"--lastname { admin_user ['lastname' ]} "
@@ -176,16 +187,17 @@ def setup_superset(self, port, python_path):
176187 # Initialize Superset
177188 print ("Initializing Superset..." )
178189 self .set_progress (now = self ._progress ["now" ]+ step , label = "Initializing Superset..." )
179- result = self .run_command (f"{ superset_path } init" , env )
190+ result = self .run_command (f' "{ superset_path } " init' , env )
180191 if "error" in result :
181192 return result
182193
183194 # Load examples (optional)
184195 print ("Loading example data..." )
185- self .set_progress (now = self ._progress ["now" ]+ step , label = "Loading default example data..." )
186- result = self .run_command (f"{ superset_path } load_examples" , env )
196+ self .set_progress (now = self ._progress ["now" ]+ step , label = "Loading default example data (this may take several minutes) ..." )
197+ result = self .run_command (f' "{ superset_path } " load_examples' , env )
187198 if "error" in result :
188- return result
199+ print (f"Warning: Failed to load examples: { result .get ('error' )} " )
200+ # We continue even if examples fail to load, as it is optional
189201
190202 # Check if port is available
191203 print (f"Checking if port { port } is available..." )
@@ -205,7 +217,7 @@ def setup_superset(self, port, python_path):
205217 print (f"Launching Superset on port { port } ..." )
206218 self .set_progress (now = self ._progress ["now" ]+ step , label = "Launching Superset..." )
207219 try :
208- subprocess .Popen (f"{ superset_path } run -p { port } " , shell = True , env = env , stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL )
220+ subprocess .Popen (f' "{ superset_path } " run -p { port } ' , shell = True , env = env , stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL )
209221 except subprocess .CalledProcessError as e :
210222 print (f"Error while running command: { f'{ superset_path } run -p { port } ' } " )
211223 print (e .stderr )
0 commit comments