
    xhez,                        d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl	m
Z
 ddlmZmZ ddlmZmZ d	d
lmZ  G d de          Z G d d          Z ee          ZdS )z!Tools to aid in deprecating code.    )annotationsN)Action)wraps)
ModuleType)AnyCallable)Versionparse   )__version__c                      e Zd ZdS )DeprecatedErrorN)__name__
__module____qualname__     8lib/python3.11/site-packages/conda_build/deprecations.pyr   r      s        Dr   r   c                      e Zd ZU ded<   d'dZdddd(dZddddd)dZdddd*dZdddd+dZdddd,dZ	dddd-d!Z
d.d#Zd/d&ZdS )0DeprecationHandlerr	   _versionversionVersion | strc                z    	 t          |          | _        dS # t          $ r t          d          | _        Y dS w xY w)zFactory to create a deprecation handle for the specified version.

        :param version: The version to compare against when checking deprecation statuses.
        z0.0.0.dev0+placeholderN)r
   r   	TypeError)selfr   s     r   __init__zDeprecationHandler.__init__   sI    
	<!'NNDMMM 	< 	< 	<!":;;DMMMM	<s    ::Nr   )addendumstackdeprecate_instr	remove_inr   
str | Noner   intreturnCallable[[Callable], Callable]c               $     d fd}|S )ar  Deprecation decorator for functions, methods, & classes.

        :param deprecate_in: Version in which code will be marked as deprecated.
        :param remove_in: Version in which code is expected to be removed.
        :param addendum: Optional additional messaging. Useful to indicate what to do instead.
        :param stack: Optional stacklevel increment.
        funcr   r%   c                                           j         d j                   \  st                    t	                      fd            }|S )N.r   c                 H    t          j        dz               | i |S N   
stacklevel)warningswarn)argskwargscategoryr(   messager   s     r   innerzHDeprecationHandler.__call__.<locals>.deprecated_decorator.<locals>.innerC   s3    gxAIFFFFtT,V,,,r   _generate_messager   r   r   r   )	r(   r7   r5   r6   r   r    r"   r   r   s	   ` @@r   deprecated_decoratorz9DeprecationHandler.__call__.<locals>.deprecated_decorator5   s     $ 6 6?88T%688!	 !7 ! !Hg  /%g... 4[[- - - - - - - [-
 Lr   r(   r   r%   r   r   )r   r    r"   r   r   r:   s   ````` r   __call__zDeprecationHandler.__call__%   sA     	 	 	 	 	 	 	 	 	 	, $#r   )renamer   r   argumentr=   c               ,     d fd}|S )a  Deprecation decorator for keyword arguments.

        :param deprecate_in: Version in which code will be marked as deprecated.
        :param remove_in: Version in which code is expected to be removed.
        :param argument: The argument to deprecate.
        :param rename: Optional new argument name.
        :param addendum: Optional additional messaging. Useful to indicate what to do instead.
        :param stack: Optional stacklevel increment.
        r(   r   r%   c           
          	                      j         d j         d drsd dn          \  st                    t	                      
fd            }|S )Nr*   ()zUse 'z
' instead.r+   c                     |v rHt          j        dz              |                    d           }r|                    |            | i |S r-   )r1   r2   pop
setdefault)	r3   r4   valuer>   r5   r(   r6   r=   r   s	      r   r7   zHDeprecationHandler.argument.<locals>.deprecated_decorator.<locals>.innerr   ss     v%%M'8E	JJJJ #JJx66E 9))&%888tT,V,,,r   r8   )r(   r7   r5   r6   r   r>   r    r"   r=   r   r   s   ` @@r   r:   z9DeprecationHandler.argument.<locals>.deprecated_decoratora   s     $ 6 6?DDT%6DDDDD "*33333 !7 ! !Hg  /%g... 4[[
- 
- 
- 
- 
- 
- 
- 
- 
- [
- Lr   r;   r   )r   r    r"   r>   r=   r   r   r:   s   ``````` r   r>   zDeprecationHandler.argumentM   sN    (	 	 	 	 	 	 	 	 	 	 	 	@ $#r   actiontype[Action]c               b      G  fdd          }t          |j        ||fi           S )Nc                  6     e Zd Z fdZd fd	Z xZS )3DeprecationHandler.action.<locals>.DeprecationMixinc                     t                      j        |i | 	                    | j        rd| j        d          dn
d| j         d          \  }}|st          |          || _        || _        d S )N`r+   )superr   r9   option_stringsdestr   r5   help)

inner_selfr3   r4   r5   r6   	__class__r   r    r"   r   s
        r   r   z<DeprecationHandler.action.<locals>.DeprecationMixin.__init__   s      $1&111$($:$: 
 &44<J5b9<<<< 4333% %; % %!'   3)'222&.
#")
r   Nc                    t          j        | j        | j        dz              t	                                          ||||           d S )N   r/   )r1   r2   rR   r5   rO   r<   )rS   parser	namespacevaluesoption_stringrT   r   s        r   r<   z<DeprecationHandler.action.<locals>.DeprecationMixin.__call__   sR    OZ%8QY      FMJJJJJr   )N)r   r   r   r   r<   __classcell__)rT   r   r    r"   r   r   s   @r   DeprecationMixinrK      s{        * * * * * * * * *0K K K K K K K K K K Kr   r\   )typer   )r   r    r"   rG   r   r   r\   s   ``` `` r   rG   zDeprecationHandler.action   sx    	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	K 	KB FO&6%?DDDr   Nonec               r    |                      |||                     |          d         |d|z              dS )a[  Deprecation function for modules.

        :param deprecate_in: Version in which code will be marked as deprecated.
        :param remove_in: Version in which code is expected to be removed.
        :param addendum: Optional additional messaging. Useful to indicate what to do instead.
        :param stack: Optional stacklevel increment.
        r   r.   )r    r"   topicr   r   N)r`   _get_module)r   r    r"   r   r   s        r   modulezDeprecationHandler.module   sO     	

%""5))!,e) 	 	
 	
 	
 	
 	
r   constantrF   r   c                  	
 |                                \  }
|                     ||
 d |          \  		st                    t          |dd          d		
fd}||_        dS )
a  Deprecation function for module constant/global.

        :param deprecate_in: Version in which code will be marked as deprecated.
        :param remove_in: Version in which code is expected to be removed.
        :param constant:
        :param value:
        :param addendum: Optional additional messaging. Useful to indicate what to do instead.
        :param stack: Optional stacklevel increment.
        r*   __getattr__Nnamer!   r%   r   c                    | k    rt          j        dz              S r |           S t          d d|  d          )Nr.   r/   zmodule 'z' has no attribute '')r1   r2   AttributeError)rf   r5   rc   fullnamer6   r   super_getattrrF   s    r   re   z0DeprecationHandler.constant.<locals>.__getattr__   sh    xgxAIFFFF +$}T*** !QH!Q!Q$!Q!Q!QRRRr   )rf   r!   r%   r   )ra   r9   r   getattrre   )r   r    r"   rc   rF   r   r   rb   re   r5   rj   r6   rk   s      `` `  @@@@r   rc   zDeprecationHandler.constant   s    (  ++E22 22$$($$	
 
'  	+!'***  t<<	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S )r   r`   c                   |                      ||||          \  }}|st          |          t          j        ||d|z              dS )a  Deprecation function for a topic.

        :param deprecate_in: Version in which code will be marked as deprecated.
        :param remove_in: Version in which code is expected to be removed.
        :param topic: The topic being deprecated.
        :param addendum: Optional additional messaging. Useful to indicate what to do instead.
        :param stack: Optional stacklevel increment.
        r.   r/   N)r9   r   r1   r2   )r   r    r"   r`   r   r   r5   r6   s           r   r`   zDeprecationHandler.topic   se    $ !22	
 
'  	+!'*** 	gxAI>>>>>>r   tuple[ModuleType, str]c                    ddl }	 t          j        d|z             }|                    |          }|	||j        fS n# t
          $ r Y nw xY wt          d          )zDetect the module from which we are being called.

        :param stack: The stacklevel increment.
        :return: The module and module name.
        r   Nr.   z&unable to determine the calling module)inspectsys	_getframe	getmoduler   
IndexErrorr   )r   r   rp   framerb   s        r   ra   zDeprecationHandler._get_module  s     		M!e),,E&&u--F!00 " 	 	 	D	 FGGGs   6> 
A
Aprefix tuple[type[Warning] | None, str]c           	        t          |          }t          |          }| j        |k     rt          }d| d}n!| j        |k     rt          }d| d}nd}d| d}|d                    t          d|||g                    fS )a  Deprecation decorator for functions, methods, & classes.

        :param deprecate_in: Version in which code will be marked as deprecated.
        :param remove_in: Version in which code is expected to be removed.
        :param prefix: The message prefix, usually the function name.
        :param addendum: Additional messaging. Useful to indicate what to do instead.
        :return: The warning category (if applicable) and the message.
        z.is pending deprecation and will be removed in r*   z%is deprecated and will be removed in Nzwas slated for removal in  )r
   r   PendingDeprecationWarningDeprecationWarningjoinfilter)	r   r    r"   rv   r   deprecate_versionremove_versionr5   warnings	            r   r9   z$DeprecationHandler._generate_message)  s     ",//y)) =,,,0HSySSSGG]^++)HJiJJJGGH?9???G HHVD67H"=>>??
 	
r   )r   r   )
r    r!   r"   r!   r   r#   r   r$   r%   r&   )r    r!   r"   r!   r>   r!   r=   r#   r   r#   r   r$   r%   r&   )
r    r!   r"   r!   rG   rH   r   r#   r   r$   )
r    r!   r"   r!   r   r#   r   r$   r%   r^   )r    r!   r"   r!   rc   r!   rF   r   r   r#   r   r$   r%   r^   )r    r!   r"   r!   r`   r!   r   r#   r   r$   r%   r^   )r   r$   r%   rn   )
r    r!   r"   r!   rv   r!   r   r#   r%   rw   )r   r   r   __annotations__r   r<   r>   rG   rb   rc   r`   ra   r9   r   r   r   r   r      sT        < < < <  $&$ &$ &$ &$ &$ &$\ "#4$ 4$ 4$ 4$ 4$ 4$x  $*E *E *E *E *E *Eb  $
 
 
 
 
 
<  $.) .) .) .) .) .)l  $? ? ? ? ? ?@H H H H& 
  
  
  
  
  
r   r   )__doc__
__future__r   rq   r1   argparser   	functoolsr   typesr   typingr   r   packaging.versionr	   r
    r   RuntimeErrorr   r   
deprecatedr   r   r   <module>r      s   ( ' " " " " " " 



                                    , , , , , , , ,      	 	 	 	 	l 	 	 	q
 q
 q
 q
 q
 q
 q
 q
h	  ,,


r   