|
11 | 11 | import sys, subprocess, json, os, asyncio, functools |
12 | 12 | from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor |
13 | 13 | import pandas as pd |
| 14 | +import tempfile |
14 | 15 |
|
15 | 16 | from io import StringIO |
16 | 17 |
|
@@ -207,41 +208,53 @@ def _run_query(self, query, custom_auth=None, env_vars=None): |
207 | 208 | local_params = self.params.copy() |
208 | 209 | local_params.insert(1, f'"{query}"') |
209 | 210 |
|
210 | | - # # Handle custom authentication if provided |
211 | | - # if custom_auth: |
212 | | - # if '--auth' in local_params: |
213 | | - # auth_index = local_params.index('--auth') |
214 | | - # local_params.pop(auth_index) # remove --auth |
215 | | - # local_params.pop(auth_index) # remove the auth string |
216 | | - # authstr = json.dumps(custom_auth) |
217 | | - # local_params.extend(["--auth", f"'{authstr}'"]) |
218 | | - |
219 | 211 | # Handle custom authentication if provided |
220 | 212 | if custom_auth: |
221 | 213 | if '--auth' in local_params: |
222 | 214 | auth_index = local_params.index('--auth') |
223 | 215 | local_params.pop(auth_index) # remove --auth |
224 | 216 | local_params.pop(auth_index) # remove the auth string |
225 | 217 | authstr = json.dumps(custom_auth) |
226 | | - |
227 | | - # For Windows PowerShell, transpose quotes: wrap with " and use ' inside the JSON |
228 | | - if self.platform.startswith("Windows"): |
229 | | - authstr = authstr.replace('"', "'") # Replace inner double quotes with single quotes |
230 | | - authstr = f'"{authstr}"' # Wrap the entire string in double quotes |
231 | | - else: |
232 | | - authstr = f"'{authstr}'" # Use single quotes on non-Windows platforms |
233 | | - |
234 | | - local_params.extend(["--auth", authstr]) |
| 218 | + local_params.extend(["--auth", f"'{authstr}'"]) |
235 | 219 |
|
236 | 220 | output = {} |
237 | 221 | env_command_prefix = "" |
238 | 222 |
|
| 223 | + # # Determine platform and set environment command prefix accordingly |
| 224 | + # if env_vars: |
| 225 | + # if self.platform.startswith("Windows"): |
| 226 | + # # For Windows, use PowerShell syntax |
| 227 | + # env_command_prefix = "& { " + " ".join([f'$env:{key} = "{value}";' for key, value in env_vars.items()]) + " " |
| 228 | + # full_command = f"{env_command_prefix}{self.bin_path} " + " ".join(local_params) + " }" |
| 229 | + # is_github_actions = os.environ.get('GITHUB_ACTIONS') == 'true' |
| 230 | + # # ok new approach, if we are in github actions, dump the command to a file and run it |
| 231 | + # # GO! |
| 232 | + # else: |
| 233 | + # # For Linux/Mac, use standard env variable syntax |
| 234 | + # env_command_prefix = "env " + " ".join([f'{key}="{value}"' for key, value in env_vars.items()]) + " " |
| 235 | + # full_command = env_command_prefix + " ".join([self.bin_path] + local_params) |
| 236 | + # else: |
| 237 | + # full_command = " ".join([self.bin_path] + local_params) |
| 238 | + |
| 239 | + # print(full_command) # For debugging |
| 240 | + |
239 | 241 | # Determine platform and set environment command prefix accordingly |
240 | 242 | if env_vars: |
241 | 243 | if self.platform.startswith("Windows"): |
242 | | - # For Windows, use PowerShell syntax |
| 244 | + # For Windows, use PowerShell syntax with GitHub Actions check |
243 | 245 | env_command_prefix = "& { " + " ".join([f'$env:{key} = "{value}";' for key, value in env_vars.items()]) + " " |
244 | 246 | full_command = f"{env_command_prefix}{self.bin_path} " + " ".join(local_params) + " }" |
| 247 | + is_github_actions = os.environ.get('GITHUB_ACTIONS') == 'true' |
| 248 | + |
| 249 | + # If in GitHub Actions, write command to a PowerShell script file and execute it |
| 250 | + if is_github_actions: |
| 251 | + with tempfile.NamedTemporaryFile(delete=False, suffix=".ps1", mode="w") as script_file: |
| 252 | + # Write environment variable setup and command to script file |
| 253 | + for key, value in env_vars.items(): |
| 254 | + script_file.write(f'$env:{key} = "{value}";\n') |
| 255 | + script_file.write(f"{self.bin_path} " + " ".join(local_params) + "\n") |
| 256 | + script_path = script_file.name |
| 257 | + full_command = f"powershell -File {script_path}" |
245 | 258 | else: |
246 | 259 | # For Linux/Mac, use standard env variable syntax |
247 | 260 | env_command_prefix = "env " + " ".join([f'{key}="{value}"' for key, value in env_vars.items()]) + " " |
|
0 commit comments