|
5 | 5 | from pathlib import Path |
6 | 6 | from typing import Dict, Optional, Union |
7 | 7 |
|
| 8 | +from runhouse.constants import INSUFFICIENT_DISK_MSG |
| 9 | +from runhouse.exceptions import InsufficientDisk |
| 10 | + |
8 | 11 | from runhouse.globals import obj_store |
9 | 12 |
|
10 | 13 | from runhouse.logger import get_logger |
@@ -239,6 +242,19 @@ def _reqs_install_cmd( |
239 | 242 | ) |
240 | 243 | return install_cmd |
241 | 244 |
|
| 245 | + def _install_and_validate_output( |
| 246 | + self, install_cmd: str, cluster: "Cluster" = None, node: Optional[str] = None |
| 247 | + ): |
| 248 | + install_res = run_setup_command(install_cmd, cluster=cluster, node=node) |
| 249 | + retcode = install_res[0] |
| 250 | + if retcode != 0: |
| 251 | + stdout, stderr = install_res[1], install_res[2] |
| 252 | + if INSUFFICIENT_DISK_MSG in stdout or INSUFFICIENT_DISK_MSG in stderr: |
| 253 | + raise InsufficientDisk(command=install_cmd) |
| 254 | + raise RuntimeError( |
| 255 | + f"Pip install {install_cmd} failed, check that the package exists and is available for your platform." |
| 256 | + ) |
| 257 | + |
242 | 258 | def _install( |
243 | 259 | self, |
244 | 260 | cluster: "Cluster" = None, |
@@ -287,35 +303,28 @@ def _install( |
287 | 303 | conda_env_name=conda_env_name, cluster=cluster |
288 | 304 | ) |
289 | 305 | logger.info(f"Running via install_method pip: {install_cmd}") |
290 | | - retcode = run_setup_command(install_cmd, cluster=cluster, node=node)[0] |
291 | | - if retcode != 0: |
292 | | - raise RuntimeError( |
293 | | - f"Pip install {install_cmd} failed, check that the package exists and is available for your platform." |
294 | | - ) |
| 306 | + self._install_and_validate_output( |
| 307 | + install_cmd=install_cmd, cluster=cluster, node=node |
| 308 | + ) |
295 | 309 |
|
296 | 310 | elif self.install_method == "conda": |
297 | 311 | install_cmd = self._conda_install_cmd( |
298 | 312 | conda_env_name=conda_env_name, cluster=cluster |
299 | 313 | ) |
300 | 314 | logger.info(f"Running via install_method conda: {install_cmd}") |
301 | | - retcode = run_setup_command(install_cmd, cluster=cluster, node=node)[0] |
302 | | - if retcode != 0: |
303 | | - raise RuntimeError( |
304 | | - f"Conda install {install_cmd} failed, check that the package exists and is " |
305 | | - "available for your platform." |
306 | | - ) |
| 315 | + self._install_and_validate_output( |
| 316 | + install_cmd=install_cmd, cluster=cluster, node=node |
| 317 | + ) |
307 | 318 |
|
308 | 319 | elif self.install_method == "reqs": |
309 | 320 | install_cmd = self._reqs_install_cmd( |
310 | 321 | conda_env_name=conda_env_name, cluster=cluster |
311 | 322 | ) |
312 | 323 | if install_cmd: |
313 | 324 | logger.info(f"Running via install_method reqs: {install_cmd}") |
314 | | - retcode = run_setup_command(install_cmd, cluster=cluster, node=node)[0] |
315 | | - if retcode != 0: |
316 | | - raise RuntimeError( |
317 | | - f"Reqs install {install_cmd} failed, check that the package exists and is available for your platform." |
318 | | - ) |
| 325 | + self._install_and_validate_output( |
| 326 | + install_cmd=install_cmd, cluster=cluster, node=node |
| 327 | + ) |
319 | 328 | else: |
320 | 329 | logger.info( |
321 | 330 | f"{self.install_target.full_local_path_str()}/requirements.txt not found, skipping reqs install" |
|
0 commit comments