From 50f68d2093cbe9dc7da6d53c3c17c45e0b97b84c Mon Sep 17 00:00:00 2001 From: Tian Xia Date: Thu, 29 Aug 2024 17:00:51 -0700 Subject: [PATCH] Avoid using lambda in `skylet.constant` (#3894) * fix * add comment --- sky/backends/backend_utils.py | 7 +++++-- sky/skylet/constants.py | 7 +++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/sky/backends/backend_utils.py b/sky/backends/backend_utils.py index d76c3fc80c5..e316a1380bb 100644 --- a/sky/backends/backend_utils.py +++ b/sky/backends/backend_utils.py @@ -882,6 +882,8 @@ def write_cluster_config( f'open(os.path.expanduser("{constants.SKY_REMOTE_RAY_PORT_FILE}"), "w", encoding="utf-8"))\'' ) + # We disable conda auto-activation if the user has specified a docker image + # to use, which is likely to already have a conda environment activated. conda_auto_activate = ('true' if to_provision.extract_docker_image() is None else 'false') @@ -919,10 +921,11 @@ def write_cluster_config( 'specific_reservations': specific_reservations, # Conda setup - 'conda_installation_commands': - constants.CONDA_INSTALLATION_COMMANDS(conda_auto_activate), # We should not use `.format`, as it contains '{}' as the bash # syntax. + 'conda_installation_commands': + constants.CONDA_INSTALLATION_COMMANDS.replace( + '{conda_auto_activate}', conda_auto_activate), 'ray_skypilot_installation_commands': (constants.RAY_SKYPILOT_INSTALLATION_COMMANDS.replace( '{sky_wheel_hash}', diff --git a/sky/skylet/constants.py b/sky/skylet/constants.py index 93dfd8b72ca..f23dc8100b5 100644 --- a/sky/skylet/constants.py +++ b/sky/skylet/constants.py @@ -126,9 +126,7 @@ # https://github.com/ray-project/ray/issues/31606 # We use python 3.10 to be consistent with the python version of the # AWS's Deep Learning AMI's default conda environment. -# Using lambda instead of str.format() since there are multiple {} in the -# installation commands and we only want to replace some of them. -CONDA_INSTALLATION_COMMANDS = lambda conda_auto_activate: ( +CONDA_INSTALLATION_COMMANDS = ( 'which conda > /dev/null 2>&1 || ' '{ curl https://repo.anaconda.com/miniconda/Miniconda3-py310_23.11.0-2-Linux-x86_64.sh -o Miniconda3-Linux-x86_64.sh && ' # pylint: disable=line-too-long # We do not use && for installation of conda and the following init commands @@ -137,7 +135,8 @@ # true. '{ bash Miniconda3-Linux-x86_64.sh -b; ' 'eval "$(~/miniconda3/bin/conda shell.bash hook)" && conda init && ' - f'conda config --set auto_activate_base {conda_auto_activate} && ' + # Caller should replace {conda_auto_activate} with either true or false. + 'conda config --set auto_activate_base {conda_auto_activate} && ' 'conda activate base; }; }; ' 'grep "# >>> conda initialize >>>" ~/.bashrc || ' '{ conda init && source ~/.bashrc; };'