o
    $i%                     @   s  d dl Z d dlZd dlmZmZmZmZmZ dedee fddZ	dedee
 dee
 fd	d
ZedZh dZdeddfddZ		d(dedee dee deeegef  dee dee fddZdedee dee fddZdedee dee fddZdedee dee fddZdedee
 dee
 fddZdedee
 dee
 fddZdedee
 dee
 fd d!Zdedee dee fd"d#Zdededefd$d%Zdeddfd&d'ZdS ))    N)CallableListOptionalTypeTypeVarsreturnc                 C   s   dd dd |  dD D S )z`Return a list from a comma-separated string.

    Trims whitespace and skips empty entries.
    c                 S   s   g | ]}|r|qS  r	   .0partr	   r	   _/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/ray/serve/_private/constants_utils.py
<listcomp>   s    zstr_to_list.<locals>.<listcomp>c                 s   s    | ]}|  V  qd S )N)stripr
   r	   r	   r   	<genexpr>       zstr_to_list.<locals>.<genexpr>,)split)r   r	   r	   r   str_to_list   s   r   
bucket_strdefault_bucketsc              
   C   s   |   dkr|S z,dd | dD }|stdtdd |D r&tdtt||kr2td	|W S  tyM } ztd
|  dt| |d}~ww )a}  Parse a comma-separated string of latency bucket values.

    Args:
        bucket_str: A comma-separated string of positive numbers in ascending order.
        default_buckets: Default bucket values to use if bucket_str is empty.

    Returns:
        A list of parsed float values.

    Raises:
        ValueError: If the format is invalid or values don't meet requirements.
     c                 S   s   g | ]}t | qS r	   )floatr   r   xr	   r	   r   r      s    z)parse_latency_buckets.<locals>.<listcomp>r   zEmpty bucket listc                 s   s    | ]}|d kV  qdS )r   Nr	   r   r	   r	   r   r   #   r   z(parse_latency_buckets.<locals>.<genexpr>zBucket values must be positivez1Bucket values must be in strictly ascending orderzInvalid format for `zH`. Expected comma-separated positive numbers in ascending order. Error: N)r   r   
ValueErroranysortedset	Exceptionstr)r   r   bucketser	   r	   r   parse_latency_buckets   s*   r#   T>   MAX_CACHED_HANDLESCONTROLLER_MAX_CONCURRENCYREQUEST_LATENCY_BUCKETS_MSMAX_PER_REPLICA_RETRY_COUNTMODEL_LOAD_LATENCY_BUCKETS_MS"SERVE_REQUEST_PROCESSING_TIMEOUT_S&MAX_DEPLOYMENT_CONSTRUCTOR_RETRY_COUNTnamec                 C   s4   d}|  |s| tv rdS td|  d| ddS )z-Validate Ray Serve environment variable name.
RAY_SERVE_Nz*Got unexpected environment variable name `z3`! Ray Serve environment variables require prefix `z`. )
startswith_wrong_names_white_listr   )r,   required_prefixr	   r	   r   _validate_name>   s   
r1   default
value_typevalidation_funcexpected_value_descriptionc           	      C   s   t |  tj| }|du r|du rdS |}nt|  |}z||}W n ty? } ztd|  d| d|j d|d}~ww |rX||sXtd| d|  d| d	|j d
	|S )a  Get environment variable with type conversion and validation.

    This function retrieves an environment variable, converts it to the specified type,
    and optionally validates the converted value.

    Args:
        name: The name of the environment variable.
        default: Default value to use if the environment variable is not set.
            If None, the function will return None without validation.
        value_type: Type to convert the environment variable value to (e.g., int, float, str).
        validation_func: Optional function that takes the converted value and returns
            a boolean indicating whether the value is valid.
        expected_value_description: Description of the expected value characteristics
            (e.g., "positive", "non-negative") used in error messages.
            Optional, expected only if validation_func is provided.

    Returns:
        The environment variable value converted to the specified type and validated,
        or the default value if the environment variable is not set.

    Raises:
        ValueError: If the environment variable value cannot be converted to the specified
            type, or if it fails the optional validation check. Also, if name validation fails.
    NzEnvironment variable `z	` value `z` cannot be converted to `z`!zGot unexpected value `z` for `z!` environment variable! Expected z `z`.)r1   osenvironget_deprecation_warningr   __name__)	r,   r2   r3   r4   r5   explicitly_defined_valuerawvaluer"   r	   r	   r   _get_env_valueL   s6   r>   c                 C      t | |tS )aN  Get environment variable as an integer.

    Args:
        name: The name of the environment variable.
        default: Default value to use if the environment variable is not set.

    Returns:
        The environment variable value as an integer.

    Raises:
        ValueError: If the value cannot be converted to an integer.
    r>   intr,   r2   r	   r	   r   get_env_int      rC   c                 C      t | |tdd dS )aq  Get environment variable as a positive integer.

    Args:
        name: The name of the environment variable.
        default: Default value to use if the environment variable is not set.

    Returns:
        The environment variable value as a positive integer.

    Raises:
        ValueError: If the value cannot be converted to an integer or is not positive.
    c                 S      | dkS Nr   r	   r   r	   r	   r   <lambda>       z&get_env_int_positive.<locals>.<lambda>positiver@   rB   r	   r	   r   get_env_int_positive      rL   c                 C   rE   )au  Get environment variable as a non-negative integer.

    Args:
        name: The name of the environment variable.
        default: Default value to use if the environment variable is not set.

    Returns:
        The environment variable value as a non-negative integer.

    Raises:
        ValueError: If the value cannot be converted to an integer or is negative.
    c                 S      | dkS rG   r	   rH   r	   r	   r   rI      rJ   z*get_env_int_non_negative.<locals>.<lambda>non negativer@   rB   r	   r	   r   get_env_int_non_negative   rM   rP   c                 C   r?   )aE  Get environment variable as a float.

    Args:
        name: The name of the environment variable.
        default: Default value to use if the environment variable is not set.

    Returns:
        The environment variable value as a float.

    Raises:
        ValueError: If the value cannot be converted to a float.
    r>   r   rB   r	   r	   r   get_env_float   rD   rR   c                 C   rE   )aj  Get environment variable as a positive float.

    Args:
        name: The name of the environment variable.
        default: Default value to use if the environment variable is not set.

    Returns:
        The environment variable value as a positive float.

    Raises:
        ValueError: If the value cannot be converted to a float or is not positive.
    c                 S   rF   rG   r	   rH   r	   r	   r   rI      rJ   z(get_env_float_positive.<locals>.<lambda>rK   rQ   rB   r	   r	   r   get_env_float_positive   rM   rS   c                 C   rE   )an  Get environment variable as a non-negative float.

    Args:
        name: The name of the environment variable.
        default: Default value to use if the environment variable is not set.

    Returns:
        The environment variable value as a non-negative float.

    Raises:
        ValueError: If the value cannot be converted to a float or is negative.
    c                 S   rN   rG   r	   rH   r	   r	   r   rI      rJ   z,get_env_float_non_negative.<locals>.<lambda>rO   rQ   rB   r	   r	   r   get_env_float_non_negative   rM   rT   c                 C   r?   )a:  Get environment variable as a string.

    Args:
        name: The name of the environment variable.
        default: Default value to use if the environment variable is not set.

    Returns:
        The environment variable value as a string.
        Returns `None` if default is `None` and value not found.
    r>   r    rB   r	   r	   r   get_env_str   s   rV   c                 C   s   t | |t}|dkS )a  Get environment variable as a boolean.

    Environment variable values of "1" are interpreted as True, all others as False.

    Args:
        name: The name of the environment variable.
        default: Default value to use if the environment variable is not set.
            Expects "0" or "1".

    Returns:
        True if the environment variable value is "1", False otherwise.
    1rU   )r,   r2   env_value_strr	   r	   r   get_env_bool   s   rY   c                    sb   dt dt f fdd}d}d | tv s| dkr/|| }tjd| d	|  d
| dtdd dS dS )zLog replacement warning for wrong or legacy environment variables.

    TODO: remove this function for the '3.0.0' release.

    :param name: environment variable name
    r,   r   c                    s$   | dkrdS | dkrdS   |  S )N'RAY_SERVE_HANDLE_METRIC_PUSH_INTERVAL_S3RAY_SERVE_HANDLE_AUTOSCALING_METRIC_PUSH_INTERVAL_Sr*   &RAY_SERVE_REQUEST_PROCESSING_TIMEOUT_Sr	   )r,   r0   r	   r   get_new_name  s
   z*_deprecation_warning.<locals>.get_new_namez3.0.0r-   rZ   zStarting from version `z` environment variable `z"` will be deprecated. Please use `z
` instead.   )
stacklevelN)r    r/   warningswarnFutureWarning)r,   r^   change_versionnew_namer	   r]   r   r9     s    
r9   )NN)r6   ra   typingr   r   r   r   r   r    r   r   r#   r$   r/   r1   boolr>   rA   rC   rL   rP   rR   rS   rT   rV   rY   r9   r	   r	   r	   r   <module>   s@    "
;