Skip to content

Commit

Permalink
Avoid using lambda in skylet.constant (#3894)
Browse files Browse the repository at this point in the history
* fix

* add comment
  • Loading branch information
cblmemo authored Aug 30, 2024
1 parent 9b3312a commit 50f68d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 5 additions & 2 deletions sky/backends/backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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}',
Expand Down
7 changes: 3 additions & 4 deletions sky/skylet/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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; };'
Expand Down

0 comments on commit 50f68d2

Please sign in to comment.