o
    `۷i                     @   s   d dl mZ d dlmZmZ d dlmZ zd dlmZ W n e	y+   d dl
mZ Y nw deeef ddfdd	Zd
eeef ddfddZ	dddZdd Zdd Zdd Zdd Zdd ZdS )    )Path)AnyDict)
cli_logger)quotefile_mountsreturnNc                 C   s:   |   D ]\}}t| rtd| d| d qdS )a  Checks if files are passed as file_mounts. This is a problem for Docker
    based clusters because when a file is bind-mounted in Docker, updates to
    the file on the host do not always propagate to the container. Using
    directories is recommended.
    zFile Mount: (:zS) refers to a file.
 To ensure this mount updates properly, please use a directory.N)itemsr   is_filer   warning)r   remotelocal r   T/home/ubuntu/vllm_env/lib/python3.10/site-packages/ray/autoscaler/_private/docker.py_check_docker_file_mounts   s   r   configc                 C   s   d| vrdS t | di  | d d}| d d}| d d|}| d d|}|p1|o1|}|s8|s8dS |r<|s@J ddS )	z1Checks whether the Docker configuration is valid.dockerNr   imagecontainer_name
head_imageworker_imagez%Must provide a container & image name)r   get)r   docker_imagecnamehead_docker_imageworker_docker_imageimage_presentr   r   r   validate_docker_config   s   r   Fc                    s@   sJ dd|rd dd |D  fdd| D S )NzMust provide docker command  c                 S   s   g | ]}d j |dqS )z-e {env}=${env})envformat).0r!   r   r   r   
<listcomp>7   s    z$with_docker_exec.<locals>.<listcomp>c              	      s,   g | ]}d j rdnd t|dqS )zE{docker_cmd} exec {interactive} {env} {container} /bin/bash -c {cmd} -itr   )
docker_cmdinteractiver!   	containercmd)r#   r   )r$   r*   r   r'   env_strwith_interactiver   r   r%   8   s    
join)cmdsr   r'   env_varsr-   r   r+   r   with_docker_exec1   s   r2   c              	   C   s    d |ddd| d | ddgS )Nr    inspectz-fz'{{z}}'z||truer.   )r   templater'   r   r   r   _check_helperD   s   r6   c                 C      t | d|S )Nz.State.Runningr6   r   r'   r   r   r   check_docker_running_cmdJ      r:   c                 C   r7   )Nzjson .Mountsr8   r9   r   r   r   check_bind_mounts_cmdN   r;   r<   c                 C   r7   )Nz.Config.Imager8   r9   r   r   r   check_docker_imageR   r;   r=   c                    s   ddl m} ||  fdd|D }	dfdd|	 D }
ddd	}dd
d | D }d|}|ddd|dd|
||d|dg}d|S )Nr   )get_docker_host_mount_locationc                    s   i | ]
}  d | |qS )/r   )r$   dst)docker_mount_prefixr   r   
<dictcomp>d   s    z%docker_start_cmds.<locals>.<dictcomp>r    c              	      s*   g | ]\}}d j ||d d dqS )z-v {src}:{dest}z~/r?   )srcdest)r#   replacer$   kv)home_directoryr   r   r%   g   s    z%docker_start_cmds.<locals>.<listcomp>zC.UTF-8)LC_ALLLANGc                 S   s   g | ]\}}d j ||dqS )z-e {name}={val})namevalr"   rF   r   r   r   r%   p   s    runz--rmz	--name {}z-dr&   z
--net=hostbash)ray.autoscaler.sdkr>   r/   r
   r#   )userr   
mount_dictr   user_optionscluster_namerI   r'   r>   mountmount_flagsr1   	env_flagsuser_options_str
docker_runr   )rA   rI   r   docker_start_cmdsV   s6   



rZ   )NF)pathlibr   typingr   r   "ray.autoscaler._private.cli_loggerr   shlexr   ImportErrorpipesstrr   r   r2   r6   r:   r<   r=   rZ   r   r   r   r   <module>   s"    
