U
    ±§fš  ã                   @   s˜   d dl mZ d dlmZ d dlmZ d dlZd dlZd dlZddlm	Z	 ddl
mZ dd	d
dgZddd„Zddd	„ZG dd
„ d
e	ƒZG dd„ deƒZdS )é    )Úconvert_path)Úlog)ÚDistutilsOptionErrorNé   )ÚCommand)Ú_cfg_read_utf8_with_fallbackÚconfig_fileÚedit_configÚoption_baseÚsetoptÚlocalc                 C   sh   | dkrdS | dkr,t j t j tj¡d¡S | dkrZt jdkrBdpDd}t j td	| ƒ¡S t	d
| ƒ‚dS )zGet the filename of the distutils, local, global, or per-user config

    `kind` must be one of "local", "global", or "user"
    r   z	setup.cfgÚglobalzdistutils.cfgÚuserÚposixÚ.Ú z~/%spydistutils.cfgz7config_file() type must be 'local', 'global', or 'user'N)
ÚosÚpathÚjoinÚdirnameÚ	distutilsÚ__file__ÚnameÚ
expanduserr   Ú
ValueError)ZkindÚdot© r   ú8lib/python3.8/site-packages/setuptools/command/setopt.pyr      s    Fc           	   	   C   s2  t  d| ¡ t ¡ }dd„ |_t|| ƒ | ¡ D ]Æ\}}|dkrZt  d|| ¡ | |¡ q0| 	|¡s|t  d|| ¡ | 
|¡ | ¡ D ]p\}}|dkrÔt  d||| ¡ | ||¡ | |¡sôt  d|| ¡ | |¡ q„t  d	|||| ¡ | |||¡ q„q0t  d
| ¡ |s.t| ddd}| |¡ W 5 Q R X dS )aY  Edit a configuration file to include `settings`

    `settings` is a dictionary of dictionaries or ``None`` values, keyed by
    command/section name.  A ``None`` value means to delete the entire section,
    while a dictionary lists settings to be changed or deleted in that section.
    A setting of ``None`` means to delete that setting.
    zReading configuration from %sc                 S   s   | S ©Nr   )Úxr   r   r   Ú<lambda>'   ó    zedit_config.<locals>.<lambda>NzDeleting section [%s] from %szAdding new section [%s] to %szDeleting %s.%s from %sz#Deleting empty [%s] section from %szSetting %s.%s to %r in %sz
Writing %sÚwzutf-8)Úencoding)r   ÚdebugÚconfigparserZRawConfigParserZoptionxformr   ÚitemsÚinfoZremove_sectionZhas_sectionZadd_sectionZremove_optionÚoptionsÚsetÚopenÚwrite)	ÚfilenameZsettingsÚdry_runZoptsZsectionr(   ÚoptionÚvalueÚfr   r   r   r	      sD    




  ÿ    ÿc                   @   s2   e Zd ZdZdddgZddgZdd„ Zd	d
„ ZdS )r
   z<Abstract base class for commands that mess with config files)úglobal-configÚgz0save options to the site-wide distutils.cfg file)úuser-configÚuz7save options to the current user's pydistutils.cfg file)z	filename=r0   z-configuration file to use (default=setup.cfg)r1   r3   c                 C   s   d | _ d | _d | _d S r   )Úglobal_configÚuser_configr,   ©Úselfr   r   r   Úinitialize_optionsU   s    zoption_base.initialize_optionsc                 C   sv   g }| j r| tdƒ¡ | jr,| tdƒ¡ | jd k	rB| | j¡ |sT| tdƒ¡ t|ƒdkrjtd|ƒ‚|\| _d S )Nr   r   r   é   z/Must specify only one configuration file option)r5   Úappendr   r6   r,   Úlenr   )r8   Ú	filenamesr   r   r   Úfinalize_optionsZ   s    
 ÿzoption_base.finalize_optionsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úuser_optionsÚboolean_optionsr9   r>   r   r   r   r   r
   G   s   ýþc                   @   sJ   e Zd ZdZdZddddgej Zejdg Zdd	„ Zd
d„ Z	dd„ Z
dS )r   z#Save command-line options to a filez1set an option in setup.cfg or another config file)zcommand=Úczcommand to set an option for)zoption=Úozoption to set)z
set-value=Úszvalue of the option)ÚremoveÚrzremove (unset) the valuerH   c                 C   s&   t  | ¡ d | _d | _d | _d | _d S r   )r
   r9   Úcommandr.   Ú	set_valuerH   r7   r   r   r   r9   y   s
    
zsetopt.initialize_optionsc                 C   sB   t  | ¡ | jd ks| jd kr&tdƒ‚| jd kr>| js>tdƒ‚d S )Nz%Must specify --command *and* --optionz$Must specify --set-value or --remove)r
   r>   rJ   r.   r   rK   rH   r7   r   r   r   r>   €   s
    
zsetopt.finalize_optionsc                 C   s*   t | j| j| j dd¡| jii| jƒ d S )Nú-Ú_)r	   r,   rJ   r.   ÚreplacerK   r-   r7   r   r   r   Úrun‡   s
    ýz
setopt.runN)r?   r@   rA   rB   Zdescriptionr
   rC   rD   r9   r>   rO   r   r   r   r   r   k   s   üû)r   )F)Zdistutils.utilr   r   r   Zdistutils.errorsr   r   r%   r   r   Zunicode_utilsr   Ú__all__r   r	   r
   r   r   r   r   r   Ú<module>   s   

*$