o
    ;i                     @   sB  d dl Z d dlZd dlZd dlmZ d dlmZmZmZ d dl	m
Z
 ddlmZmZ ddgZd	d
 Zdeeeef defddZddddeeeef dedededdf
ddZe
dZedZ	d%deeeef dedededeeeef geeef f f
ddZdeeef deeef fdd Zd!ed"eddfd#d$ZdS )&    N)date)AnyCallableTypeVar)	ParamSpec   )DeprecationErrorPendingDeprecationErrormodalsynchronicityc                 C   s   | j d dd }|tv S )N__name__.r   )	f_globalssplit_INTERNAL_MODULES)framemodule r   L/home/ubuntu/.local/lib/python3.10/site-packages/modal/_utils/deprecation.py_is_internal_frame   s   r   deprecated_onmsgc                 C   s   t dt|   d| )NzDeprecated on : )r   r   )r   r   r   r   r   deprecation_error   s   r   FT)pendingshow_sourcer   r   returnc                C   s   d\}}|r4z$t  }|durt|r|j}|durt|s|dur)|jj}|j}W n	 ty3   Y nw |r8tnt	}t
t|   d| ||| dS )zIssue a Modal deprecation warning with source optionally attributed to user code.

    See the implementation of the built-in [warnings.warn](https://docs.python.org/3/library/warnings.html#available-functions).
    )z	<unknown>r   Nr   )sys	_getframer   f_backf_codeco_filenamef_lineno
ValueErrorr	   r   warningswarn_explicitr   )r   r   r   r   filenamelinenor   warning_clsr   r   r   deprecation_warning   s    "r)   PRr   old_namenew_namec                    s0   dt ttf dt ttf f fdd}|S )ah  Decorator for semi-gracefully changing a parameter name.

    Functions wrapped with this decorator can be defined using only the `new_name` of the parameter.
    If the function is invoked with the `old_name`, the wrapper will pass the value as a keyword
    argument for `new_name` and issue a Modal deprecation warning about the change.

    Note that this only prevents parameter renamings from breaking code at runtime.
    Type checking will fail when code uses `old_name`. To avoid this, the `old_name` can be
    preserved in the function signature with an `Annotated` type hint indicating the renaming.
    funcr   c                    s4   t  dtjdtjdtf fdd}|S )Nargskwargsr   c                     s`   t  d }|v r)||< jd}d d| d d}t |d | i |S )Nr0   _zThe 'z' parameter of `z` has been renamed to 'zX'.
Using the old name will become an error in a future release. Please update your code.r   )localspop__qualname__removeprefixr)   )r/   r0   
mut_kwargs	func_namemessage)r   r.   r-   r,   r   r   r   wrapperI   s   
z5renamed_parameter.<locals>.decorator.<locals>.wrapper	functoolswrapsr*   r/   r0   r+   r.   r:   r   r-   r,   r   )r.   r   	decoratorH   s   (z$renamed_parameter.<locals>.decorator)r   r*   r+   )r   r,   r-   r   r@   r   r?   r   renamed_parameter7   s   ,rA   r.   c                    s<   dddddt  dtjdtjdtf fd	d
}|S )Nmin_containersmax_containersbuffer_containersscaledown_window)	keep_warmconcurrency_limit_experimental_buffer_containerscontainer_idle_timeoutr/   r0   r   c            	         s   t  d }g } | @ } D ]\}}||v r1| }||||< |d| d|  q|rFd|}d| d}td|dd	  | i |S )
Nr0   z- z -> 
ztWe have renamed several parameters related to autoscaling. Please update your code to use the following new names:

zH

See https://modal.com/docs/guide/modal-1-0-migration for more details.)  r      Tr2   )r3   keysitemsr4   appendjoinr)   )	r/   r0   r7   substitutionsold_params_used	old_param	new_paramsubstitution_stringr9   r.   name_mapr   r   r:   d   s"   

z4warn_on_renamed_autoscaler_settings.<locals>.wrapperr;   r>   r   rV   r   #warn_on_renamed_autoscaler_settings\   s   "rX   	namespaceresource_namec                 C   s"   | durt dd| d dS dS )zIssue deprecation warning for namespace parameter if non-None value is passed.

    Args:
        namespace: The namespace parameter value (may be None or actual value)
        resource_name: Name of the resource type for the warning message
    N)rK         zThe `namespace` parameter for `zr` is deprecated and will be removed in a future release. It is no longer needed, so can be removed from your code.)r)   )rY   rZ   r   r   r   warn_if_passing_namespace   s   

r]   )T)r<   r   r$   datetimer   typingr   r   r   typing_extensionsr   	exceptionr   r	   r   r   tupleintstrr   boolr)   r*   r+   rA   rX   r]   r   r   r   r   <module>   sX   

"%#