o
    ڷi                     @   s  d dl Z 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	ed
edefddZe
fdededee fddZdee d
ededefddZ	ddeded
ededef
ddZe
fdeded
edefddZg dZdS )    N)AnyOptional)	ContainerNode)_DEFAULT_MARKER_
_get_value)BaseContainer)ConfigKeyError)parse)dictobj_parent_returnc                 C   s(   ddl m} t|tsJ |j| |dS )z@Create a config object from `obj`, similar to `OmegaConf.create`r   )	OmegaConf)parent)	omegaconfr   
isinstancer   create)r   r   r    r   U/home/ubuntu/vllm_env/lib/python3.10/site-packages/omegaconf/resolvers/oc/__init__.pyr      s   r   keydefaultc                 C   sP   zt j|  W S  ty'   |tur|durt| Y S d Y S td|  dw )a=  
    :param key: Environment variable key
    :param default: Optional default value to use in case the key environment variable is not set.
                    If default is not a string, it is converted with str(default).
                    None default is returned as is.
    :return: The environment variable 'key'. If the environment variable is not set and a default is
            provided, the default is used. If used, the default is converted to a string with str(default).
            If the default is None, None is returned (without a string conversion).
    NzEnvironment variable 'z' not found)osenvironKeyErrorr   str)r   r   r   r   r   env   s   
r   expr_node_c                 C   sT   | du rdS t | tstd|  dt| j t| ddd}|j||d}t|S )z
    Parse and evaluate `expr` according to the `singleElement` rule of the grammar.

    If `expr` is `None`, then return `None`.
    Nz9`oc.decode` can only take strings or None as input, but `z` is of type singleElement
VALUE_MODE)parser_rule
lexer_mode)node)r   r   	TypeErrortype__name__r
   resolve_parse_treer   )r   r   r   
parse_treevalr   r   r   decode)   s   
r*   G'$OLD_KEY' is deprecated. Change your code and config to use '$NEW_KEY'messagec          	      C   s   ddl m} t| tstdt| j dt|ts&tdt|j d|jd d}||| dd}|d u rBtd	| d
|  d|jd d}t	
|j||d}tjt|d |S )Nr   )select_nodez7oc.deprecated: interpolation key type is not a string ()z;oc.deprecated: interpolation message type is not a string ()r   T)absolute_keyzIn oc.deprecated resolver at 'z': Key not found: '')OLD_KEYNEW_KEY)categoryr,   )omegaconf._implr-   r   r   r$   r%   r&   _get_full_keyr	   stringTemplatesafe_substitutewarningswarnUserWarning)	r   r,   r   r   r-   full_keytarget_nodenew_keymsgr   r   r   
deprecated=   s,   


r@   c                C   s   ddl m} ||| d|dS )Nr   )select_valueT)cfgr   r/   r   )r4   rA   )r   r   r   rA   r   r   r   select_   s   rC   )r   r*   r@   r   r   rC   )r+   )r   r6   r9   typingr   r   r   r   r   omegaconf._utilsr   r   omegaconf.basecontainerr   omegaconf.errorsr	   omegaconf.grammar_parserr
   omegaconf.resolvers.ocr   r   r   r   r*   r@   rC   __all__r   r   r   r   <module>   sH    
$
