o
    ;i                  	   @   s`  d dl Z d dlZd dlmZmZ d dlmZmZ d dlmZm	Z	 d dl
mZ ddlmZ ddlmZ dd	lmZ dd
lmZ ejde	eeef dZdedee	eef ef deeeef  fddZdee	eef ef fddZdee	eef e	eef f deeee	eef f  fddZdeeee	eef ef   dedeeeef  fddZdS )    N)MappingSequence)PurePathPurePosixPath)OptionalUnion)	TypeGuard   )_CloudBucketMount)InvalidError)_NetworkFileSystem)_VolumeT)bounddisplay_namevolume_likesreturnc                 C   s   t |tstd|  dt| dg }| D ]N\}}t| }t|}||kr5t|  d| d|dkrCt|  d| d|dkrQt|  d| d	|d
kr_t|  d| d|	||f q|S )zAMount point path validation for volumes and network file systems.z5`volume_likes` should be a dict[str | PurePosixPath, z], got z instead z$ must be a canonical, absolute path./z' cannot be mounted into root directory.z/rootz cannot be mounted at '/root'.z/tmpz cannot be mounted at '/tmp'.)

isinstancedictr   typeitemsr   as_posix	posixpathabspathappend)r   r   	validatedpathvolabs_path r!   L/home/ubuntu/.local/lib/python3.10/site-packages/modal/_utils/mount_utils.pyvalidate_mount_points   s$   

r#   network_file_systemsc                 C   sD   t d| }|D ]\}}t|tstdt| d| dd q|S )NNetworkFileSystemObject of type  mounted at 'z' z(is not useable as a network file system.)r#   r   r   r   r   )r$   validated_network_file_systemsr   network_file_systemr!   r!   r"   validate_network_file_systems.   s   

r*   volumesc                 C   s   t d| }i }|D ]&\}}t|ttfs!tdt| d| dt|tr/||g | q	| D ]}t	|dkrHd
|}td| q4|S )NVolumer&   r'   z' is not usable as a volume.   z, zOThe same Volume cannot be mounted in multiple locations for the same function: )r#   r   r   r
   r   r   
setdefaultr   valueslenjoin)r+   validated_volumesvolume_to_pathsr   volumepathsconflictingr!   r!   r"   validate_volumes=   s    


r7   caller_namec                 C   sd   | du rg S t | }dttttttf f  dtttttf   fdd}||s0t| d|S )z(Validate all volumes are `modal.Volume`.Nvolsr   c                 S   s   t dd | D S )Nc                 s   s    | ]
\}}t |tV  qd S )N)r   r   ).0_vr!   r!   r"   	<genexpr>b   s    zIvalidate_only_modal_volumes.<locals>.all_modal_volumes.<locals>.<genexpr>)all)r9   r!   r!   r"   all_modal_volumes_   s   z6validate_only_modal_volumes.<locals>.all_modal_volumesz, only supports volumes that are modal.Volume)	r7   r   tuplestrr   r   r
   r   r   )r+   r8   r2   r?   r!   r!   r"   validate_only_modal_volumesS   s   
rB   )r   typingcollections.abcr   r   pathlibr   r   r   r   typing_extensionsr   cloud_bucket_mountr
   	exceptionr   r)   r   r4   r   TypeVarr   rA   listr@   r#   r*   r7   r   rB   r!   r!   r!   r"   <module>   sB   


