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&d'iZdedd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	   X/home/ubuntu/vllm_env/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REQUEST_LATENCY_BUCKETS_MSMODEL_LOAD_LATENCY_BUCKETS_MS"SERVE_REQUEST_PROCESSING_TIMEOUT_S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   
r.   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`.)r.   osenvironget_deprecation_warningr   __name__)	r)   r/   r0   r1   r2   explicitly_defined_valuerawvaluer"   r	   r	   r   _get_env_valueI   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)   r/   r	   r	   r   get_env_int      r@   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=   r?   r	   r	   r   get_env_int_positive      rI   c                 C   rB   )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 rD   r	   rE   r	   r	   r   rF      rG   z*get_env_int_non_negative.<locals>.<lambda>non negativer=   r?   r	   r	   r   get_env_int_non_negative   rJ   rM   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   r?   r	   r	   r   get_env_float   rA   rO   c                 C   rB   )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   rC   rD   r	   rE   r	   r	   r   rF      rG   z(get_env_float_positive.<locals>.<lambda>rH   rN   r?   r	   r	   r   get_env_float_positive   rJ   rP   c                 C   rB   )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   rK   rD   r	   rE   r	   r	   r   rF      rG   z,get_env_float_non_negative.<locals>.<lambda>rL   rN   r?   r	   r	   r   get_env_float_non_negative   rJ   rQ   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    r?   r	   r	   r   get_env_str   s   rS   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.
    1rR   )r)   r/   env_value_strr	   r	   r   get_env_bool   s   rV   #RAY_SERVE_HTTP_KEEP_ALIVE_TIMEOUT_Sz!http_options.keep_alive_timeout_sc                    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)   r-   r	   r   get_new_name  s
   z*_deprecation_warning.<locals>.get_new_namez3.0.0r*   rX   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   r6   	  s    
r6   c                 C   sF   | t v rtj| r!t |  }tjd|  d| dtdd dS dS dS )zhWarn if a fully deprecated environment variable is set.

    :param name: environment variable name
    `z>` environment variable will be deprecated in the future. Use `z` in the Serve config instead.   r^   N)_fully_deprecated_env_varsr3   r4   r5   r`   ra   DeprecationWarning)r)   config_optionr	   r	   r   warn_if_deprecated_env_var_set)  s   
rj   )NN)r3   r`   typingr   r   r   r   r   r    r   r   r#   r$   r,   r.   boolr;   r>   r@   rI   rM   rO   rP   rQ   rS   rV   rg   r6   rj   r	   r	   r	   r   <module>   sF    "
; 