
    Jui                         d dl Z d dlZddlmZ ddlmZ d dlZd dlmZ d dlm	Z	 d dl
mZ g dZdd	Zdd
Z G d de      Z G d de      Zy)    N   )Command)_cfg_read_utf8_with_fallback)log)DistutilsOptionError)convert_path)config_fileedit_configoption_basesetoptc                 ^   | dk(  ry| dk(  rKt         j                  j                  t         j                  j                  t        j
                        d      S | dk(  rGt         j                  dk(  xr dxs d}t         j                  j                  t        d	| d
            S t        d|       )zGet the filename of the distutils, local, global, or per-user config

    `kind` must be one of "local", "global", or "user"
    localz	setup.cfgglobalzdistutils.cfguserposix. z~/zpydistutils.cfgz7config_file() type must be 'local', 'global', or 'user')
ospathjoindirname	distutils__file__name
expanduserr   
ValueError)kinddots     c/root/.openclaw/workspace/chatterbox_venv/lib/python3.12/site-packages/setuptools/command/setopt.pyr	   r	      s    
 wxww||BGGOOI,>,>?QQv~gg (S.Bww!!,C5/H"IJJ
NPT
UU    c           	      f   t        j                  d|        t        j                         }d |_        t        ||        |j                         D ]  \  }}|)t        j                  d||        |j                  |       2|j                  |      s(t        j                  d||        |j                  |       |j                         D ]  \  }}|et        j                  d|||        |j                  ||       |j                  |      rDt        j                  d||        |j                  |       mt        j                  d||||        |j                  |||         t        j                  d	|        t        | d
d      5 }|j                  |       ddd       y# 1 sw Y   yxY w)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 N )	optionstrs    r   <lambda>zedit_config.<locals>.<lambda>(   s     r    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configparserRawConfigParseroptionxformr   itemsinforemove_sectionhas_sectionadd_sectionremove_optionoptionssetopenwrite)filenamesettingsoptssectionr3   optionvaluefs           r   r
   r
      sv    II-x8'')D2D x0$NN, 5?HH4gxH(##G,		97HM  )!( 5=II6R&&w7<<0A7H ++G4II3WfeX HHWfe455. HH\8$	hg	. !

1  s   F''F0c                   .    e Zd ZdZg dZddgZd ZddZy)	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=r=   z-configuration file to use (default=setup.cfg)r?   rA   c                 .    d | _         d | _        d | _        y r#   )global_configuser_configr7   selfs    r   initialize_optionszoption_base.initialize_optionsU   s    !r    Nc                 l   g }| j                   r|j                  t        d             | j                  r|j                  t        d             | j                  |j                  | j                         |s|j                  t        d             t        |      dkD  rt        d|      |\  | _        y )Nr   r   r      z/Must specify only one configuration file option)rD   appendr	   rE   r7   lenr   )rG   	filenamess     r   finalize_optionszoption_base.finalize_optionsZ   s    	[23[01==$T]]+[12y>A&A9  %r    returnN)__name__
__module____qualname____doc__user_optionsboolean_optionsrH   rN   r$   r    r   r   r   G   s%    FL 	O

%r    r   c                   l    e Zd ZdZdZg dej                  z   Zej                  dgz   Zd Zd	dZ	d	dZ
y)
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 valuer[   c                 f    t         j                  |        d | _        d | _        d | _        d | _        y r#   )r   rH   commandr;   	set_valuer[   rF   s    r   rH   zsetopt.initialize_optionsy   s,    &&t,r    Nc                     t         j                  |        | j                  | j                  t	        d      | j
                  | j                  st	        d      y y )Nz%Must specify --command *and* --optionz$Must specify --set-value or --remove)r   rN   r^   r;   r   r_   r[   rF   s    r   rN   zsetopt.finalize_options   sS    $$T*<<4;;#6&'NOO>>!$++&'MNN +6!r    c                     t        | j                  | j                  | j                  j	                  dd      | j
                  ii       y )N-_)r
   r7   r^   r;   replacer_   rF   s    r   runz
setopt.run   s7    MM\\DKK//S94>>JK	
r    rO   )rQ   rR   rS   rT   descriptionr   rU   rV   rH   rN   re   r$   r    r   r   r   k   sE    -EK
 	  !L "11XJ>OO
r    r   )r   rO   )r*   r   r   r   unicode_utilsr   r   r   distutils.errorsr   distutils.utilr   __all__r	   r
   r   r   r$   r    r   <module>rk      sG     	  8   1 '
AV&R!%' !%H 
[  
r    