o
     JAf                     @   s   	 d dl Z d dlZd dlZd dlmZ zd dlZW n ey$   dZY nw d dlT d dlm	Z	m
Z
 d dlmZmZmZ d dlmZ d dlmZ edZd	d
 ZG dd dZG dd dZdd ZdS )    N)message_from_file)*)FancyGetopttranslate_longopt)check_environ	strtoboolrfc822_escapelog)DEBUGz^[a-zA-Z]([a-zA-Z0-9_]*)$c                 C   sP   t | tr	 | S t | ts&t| j}d| d| d}ttj| t| } | S )Nz
Warning: 'z' should be a list, got type '')
isinstancestrlisttype__name__r
   WARN)value	fieldnametypenamemsg r   %/usr/lib/python3.10/distutils/dist.py_ensure_list   s   


r   c                   @   sB  e Zd Z	 g dZdZg dZdd eD ZddiZdHd	d
Zdd Z	dIddZ
dd ZdHddZdd Zdd Zdd Zdd Zddg fddZdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* ZdJd+d,ZdHd-d.ZdKd0d1Zejfd2d3Zd4d5 Zd6d7 Zd8d9 Z d:d; Z!d<d= Z"d>d? Z#d@dA Z$dBdC Z%dDdE Z&dFdG Z'dS )LDistribution))verbosevzrun verbosely (default)   )quietqz!run quietly (turns verbosity off))zdry-runnzdon't actually do anything)helphzshow detailed help message)zno-user-cfgNz-ignore pydistutils.cfg in your home directoryzCommon commands: (see '--help-commands' for more)

  setup.py build      will build the package underneath 'build/'
  setup.py install    will install the package
))zhelp-commandsNzlist all available commands)nameNzprint package name)versionVzprint package version)fullnameNzprint <package name>-<version>)authorNzprint the author's name)author-emailNz print the author's email address)
maintainerNzprint the maintainer's name)zmaintainer-emailNz$print the maintainer's email address)contactNz7print the maintainer's name if known, else the author's)zcontact-emailNz@print the maintainer's email address if known, else the author's)urlNzprint the URL for this package)licenseNz print the license of the package)licenceNzalias for --license)descriptionNzprint the package description)zlong-descriptionNz"print the long package description)	platformsNzprint the list of platforms)classifiersNzprint the list of classifiers)keywordsNzprint the list of keywords)providesNz+print the list of packages/modules provided)requiresNz+print the list of packages/modules required)	obsoletesNz0print the list of packages/modules made obsoletec                 C   s   g | ]}t |d  qS r   r   ).0xr   r   r   
<listcomp>   s    zDistribution.<listcomp>r   r   Nc                 C   sF  	 d| _ d| _d| _| jD ]}t| |d qt | _| jjD ]}d| }t| |t| j| qi | _	d | _
d | _d | _i | _g | _d | _i | _d | _d | _d | _d | _d | _d | _d | _d | _d | _d | _d| _i | _i | _|r|d}|d ur|d= | D ]\}}|  |}| D ]
\}	}
d|
f||	< qqd|v r|d |d< |d= d	}t!d urt!"| nt#j$%|d
  | D ]<\}}
t&| jd| rt| jd| |
 qt&| j|rt| j||
 qt&| |rt| ||
 qdt'| }t!"| qd| _(| jd ur| jD ]}|)ds n|dkrd| _( nq| *  d S )Nr   r   get_ optionszsetup scriptr-   r,   z:'licence' distribution option is deprecated; use 'license'
Zset_zUnknown distribution option: %sT-z--no-user-cfgF)+r   dry_runr!   display_option_namessetattrDistributionMetadatametadata_METHOD_BASENAMESgetattrcmdclasscommand_packagesscript_namescript_argscommand_optionsZ
dist_filespackagesZpackage_dataZpackage_dir
py_modules	librariesheadersext_modulesZext_packageZinclude_dirsZ
extra_pathscripts
data_filespasswordcommand_objhave_rungetitemsget_option_dictwarningswarnsysstderrwritehasattrreprwant_user_cfg
startswithfinalize_options)selfZattrsattrbasenameZmethod_namer<   commandZcmd_optionsopt_dictoptvalr   keyargr   r   r   __init__   s   





zDistribution.__init__c                 C   s(   	 | j |}|d u ri  }| j |< |S N)rJ   rU   )rb   re   dictr   r   r   rW   &  s
   zDistribution.get_option_dictr;   c           	      C   s   ddl m} |d u rt| j }|d ur | ||  |d }|s+| |d  d S |D ]4}| j|}|d u rC| |d|   q-| |d|   ||}|dD ]}| |d |  qUq-d S )Nr   )pformatz  zno commands known yetzno option dict for '%s' commandzoption dict for '%s' command:r=   )Zpprintrn   sortedrJ   keysannouncerU   split)	rb   headercommandsindentrn   Zcmd_namerf   outliner   r   r   dump_option_dicts1  s.   zDistribution.dump_option_dictsc                 C   s   	 g }t   tjtjd j}tj|d}tj|r"|	| tj
dkr*d}nd}| jrEtjtjd|}tj|rE|	| d}tj|rR|	| tr^| dd	|  |S )
N	distutilszdistutils.cfgposixz.pydistutils.cfgzpydistutils.cfg~z	setup.cfgzusing config files: %sz, )r   ospathdirnamerZ   modules__file__joinisfileappendr#   r_   
expanduserr   rq   )rb   filesZsys_dirZsys_fileZuser_filenameZ	user_fileZ
local_filer   r   r   find_config_filesM  s(   



zDistribution.find_config_filesc                 C   s|  ddl m} tjtjkrg d}ng }t|}|d u r|  }tr&| d | }|D ]D}tr6| d|  |	| |
 D ]+}||}| |}|D ]}	|	dkri|	|vri|||	}
|	dd}	||
f||	< qMq?|  q+d	| jv r| jd	  D ]?\}	\}}
| j|	}z!|rt| |t|
  n|	d
v rt| |	t|
 nt| |	|
 W q| ty } zt|d }~ww d S d S )Nr   )ConfigParser)zinstall-basezinstall-platbasezinstall-libzinstall-platlibzinstall-purelibzinstall-headerszinstall-scriptszinstall-dataprefixzexec-prefixhomeuserrootz"Distribution.parse_config_files():z  reading %sr   r>   _global)r   r?   )configparserr   rZ   r   base_prefix	frozensetr   r   rq   readZsectionsr<   rW   rU   replacerk   rJ   rV   negative_optrA   r   
ValueErrorDistutilsOptionError)rb   	filenamesr   Zignore_optionsparserfilenamesectionr<   rf   rg   rh   srcaliasr   r   r   r   parse_config_files}  sR   






zDistribution.parse_config_filesc                 C   s   	 |   }g | _t|| j }|| j |ddi |j| j| d}|	 }t
| j | |r5d S |rE| ||}|d u rCd S |s7| jrX| j|t| jdk| jd d S | js_tddS )Nr-   r,   )argsobjectr   display_optionsrt   zno commands suppliedT)_get_toplevel_optionsrt   r   r   set_negative_aliasesr   Zset_aliasesgetoptrI   Zget_option_orderr
   Zset_verbosityr   handle_display_options_parse_command_optsr!   
_show_helplenDistutilsArgError)rb   Ztoplevel_optionsr   r   option_orderr   r   r   parse_command_line  s2   	
zDistribution.parse_command_linec                 C   s   	 | j dg S )N)zcommand-packages=Nz0list of packages that provide distutils commands)global_optionsrb   r   r   r   r     s   z"Distribution._get_toplevel_optionsc              
   C   s  	 ddl m} |d }t|std| | j| z| |}W n ty3 } zt	|d }~ww t
||s?td| t|drJt|jtsRd}t|| | j}t|drd| }||j t|drut|jtrut|j}ng }|| j|j |  || ||d	d  \}}	t|	d
r|	jr| j|d|gd d S t|drt|jtrd}
|jD ] \}}}}t|	||rd	}
t|r|  qtd||f q|
rd S | |}t|	 D ]
\}}d|f||< q|S )Nr   Commandzinvalid command name '%s'z&command class %s must subclass Commanduser_optionszIcommand class %s must provide 'user_options' attribute (a list of tuples)r   help_optionsr   r!   r   zYinvalid help function %r for help option '%s': must be a callable object (function, etc.)zcommand line) distutils.cmdr   
command_rematch
SystemExitrt   r   get_command_classDistutilsModuleErrorr   
issubclassZDistutilsClassErrorr]   r   r   r   r   copyupdater   fix_help_optionsset_option_tabler   r   r   r!   r   Zget_attr_namecallablerW   varsrV   )rb   r   r   r   re   Z	cmd_classr   r   r   ZoptsZhelp_option_foundZhelp_optionZshortZdescfuncrf   r#   r   r   r   r   r     sz   	











z Distribution._parse_command_optsc                 C   sR   	 dD ]#}t | j|}|d u rqt|tr&dd |dD }t| j|| qd S )Nr1   r/   c                 S      g | ]}|  qS r   strip)r7   Zelmr   r   r   r9   j      z1Distribution.finalize_options.<locals>.<listcomp>,)rE   rC   r   r   rr   rA   )rb   rc   r   r   r   r   ra   `  s   
zDistribution.finalize_optionsr   c           
      C   s
  	 ddl m} ddlm} |r*|r|  }n| j}|| || jd  t	d |r;|| j
 |d t	d | jD ]=}t|trMt||rM|}	n| |}	t|	drit|	jtri||	jt|	j  n||	j |d|	j  t	d q>t	|| j d S )	Nr   	gen_usager   z
Global options:r;   zKInformation display options (just display information, ignore any commands)r   zOptions for '%s' command:)distutils.corer   r   r   r   r   r   
print_helpcommon_usageprintr   rt   r   r   r   r   r]   r   r   r   r   r   rH   )
rb   r   r   r   rt   r   r   r<   re   klassr   r   r   r   m  s<   






zDistribution._show_helpc           	      C   s   	 ddl m} | jr|   td t|| j dS d}i }| jD ]}d||d < q"|D ]6\}}|rc||rct|}t	| j
d|  }|dv rQtd| n|dv r]td	| nt| d}q-|S )
Nr   r   r;   r   r:   r   r   )r0   r2   r3   r4   r=   )r   r   Zhelp_commandsprint_commandsr   rH   r   rU   r   rE   rC   r   )	rb   r   r   Zany_display_optionsZis_display_optionoptionrg   rh   r   r   r   r   r     s.   
z#Distribution.handle_display_optionsc              	   C   sj   	 t |d  |D ])}| j|}|s| |}z|j}W n ty(   d}Y nw t d|||f  q	d S )N:(no description available)z
  %-*s  %s)r   rF   rU   r   r.   AttributeError)rb   rt   rs   
max_lengthcmdr   r.   r   r   r   print_command_list  s   

zDistribution.print_command_listc                 C   s   	 dd l }|jj}i }|D ]}d||< qg }| j D ]}||s'|| qd}|| D ]}t||kr:t|}q.| |d| |rPt	  | |d| d S d S )Nr   r   zStandard commandszExtra commands)
distutils.commandre   __all__rF   rp   rU   r   r   r   r   )rb   ry   std_commandsis_stdr   extra_commandsr   r   r   r   r     s6   


zDistribution.print_commandsc           	   	   C   s   	 dd l }|jj}i }|D ]}d||< qg }| j D ]}||s'|| qg }|| D ]'}| j|}|s=| |}z|j}W n t	yM   d}Y nw |||f q.|S )Nr   r   r   )
r   re   r   rF   rp   rU   r   r   r.   r   )	rb   ry   r   r   r   r   rvr   r.   r   r   r   get_command_list  s.   




zDistribution.get_command_listc                 C   sP   	 | j }t|ts&|d u rd}dd |dD }d|vr#|dd || _ |S )Nr;   c                 S   s   g | ]
}|d kr|  qS )r;   r   )r7   Zpkgr   r   r   r9   !  s    z5Distribution.get_command_packages.<locals>.<listcomp>r   zdistutils.commandr   )rG   r   r   rr   insert)rb   Zpkgsr   r   r   get_command_packages  s   
z!Distribution.get_command_packagesc              	   C   s   	 | j |}|r|S |  D ]?}d||f }|}zt| tj| }W n	 ty-   Y qw zt||}W n tyE   t	d|||f w || j |< |  S t	d| )Nz%s.%sz3invalid command '%s' (no class '%s' in module '%s')zinvalid command '%s')
rF   rU   r   
__import__rZ   r   ImportErrorrE   r   r   )rb   re   r   Zpkgnamemodule_nameZ
klass_namemoduler   r   r   r   '  s2   
zDistribution.get_command_classc                 C   sn   	 | j |}|s5|r5tr| d|  | |}||  }| j |< d| j|< | j|}|r5| || |S )Nz<Distribution.get_command_obj(): creating '%s' command objectr   )rS   rU   r   rq   r   rT   rJ   _set_command_options)rb   re   Zcreatecmd_objr   r<   r   r   r   get_command_objM  s   

zDistribution.get_command_objc                 C   sH  	 |  }|d u r| |}tr| d|  | D ]\}\}}tr-| d|||f  z
dd |jD }W n tyB   g }Y nw z|j}W n tyS   i }Y nw z=t|t	}	||v rl|	rlt
||| t|  n$||v r{|	r{t
||t| nt||rt
||| n	td|||f W q ty }
 zt|
d }
~
ww d S )Nz#  setting options for '%s' command:z    %s = %s (from %s)c                 S   s   g | ]}t |qS r   r6   )r7   or   r   r   r9   |  s    z5Distribution._set_command_options.<locals>.<listcomp>z1error in %s: command '%s' has no such option '%s')get_command_namerW   r   rq   rV   Zboolean_optionsr   r   r   r   rA   r   r]   r   r   )rb   rS   Zoption_dictcommand_namer   sourcer   Z	bool_optsZneg_optZ	is_stringr   r   r   r   r   h  sT   





z!Distribution._set_command_optionsr   c                 C   s~   	 ddl m} t||s|}| |}n| }|js|S |  d|_d| j|< | | |r=|	 D ]}| 
|| q4|S )Nr   r   )r   r   r   r   r   Z	finalizedZinitialize_optionsrT   r   Zget_sub_commandsreinitialize_command)rb   re   Zreinit_subcommandsr   r   subr   r   r   r     s    


z!Distribution.reinitialize_commandc                 C   s   t  || d S rl   r	   )rb   r   levelr   r   r   rq        zDistribution.announcec                 C   s   	 | j D ]}| | qd S rl   )rt   run_command)rb   r   r   r   r   run_commands  s   
zDistribution.run_commandsc                 C   sF   	 | j |r	d S td| | |}|  |  d| j |< d S )Nz
running %sr   )rT   rU   r
   infor   Zensure_finalizedrun)rb   re   r   r   r   r   r     s   
zDistribution.run_commandc                 C   s   t | jp| jpg dkS Nr   )r   rK   rL   r   r   r   r   has_pure_modules  s   zDistribution.has_pure_modulesc                 C      | j o	t| j dkS r   )rO   r   r   r   r   r   has_ext_modules     zDistribution.has_ext_modulesc                 C   r   r   )rM   r   r   r   r   r   has_c_libraries  r   zDistribution.has_c_librariesc                 C   s   |   p|  S rl   )r   r   r   r   r   r   has_modules  r   zDistribution.has_modulesc                 C   r   r   )rN   r   r   r   r   r   has_headers  r   zDistribution.has_headersc                 C   r   r   )rP   r   r   r   r   r   has_scripts  r   zDistribution.has_scriptsc                 C   r   r   )rQ   r   r   r   r   r   has_data_files  r   zDistribution.has_data_filesc                 C   s   |   o|   o|   S rl   )r   r   r   r   r   r   r   is_pure  s
   zDistribution.is_purerl   )NNr;   )r   r5   )(r   
__module____qualname__r   r   r   r@   r   rk   rW   rx   r   r   r   r   r   ra   r   r   r   r   r   r   r   r   r   r   r
   INFOrq   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ,   sP    ,
 

0:C[
2(!"
&

,)
r   c                   @   s  e Zd Z	 dZdAddZdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" ZeZd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Z d;d< Z!d=d> Z"d?d@ Z#dS )BrB   )r#   r$   r'   author_emailr)   maintainer_emailr+   r,   r.   long_descriptionr1   r/   r&   r*   Zcontact_emailr0   download_urlr2   r3   r4   Nc                 C   s   |d ur|  t| d S d | _d | _d | _d | _d | _d | _d | _d | _	d | _
d | _d | _d | _d | _d | _d | _d | _d | _d S rl   )read_pkg_fileopenr#   r$   r'   r   r)   r   r+   r,   r.   r   r1   r/   r0   r  r2   r3   r4   )rb   r}   r   r   r   rk     s&   
zDistributionMetadata.__init__c                    s  	 t |  fdd} fdd} d }|d| _|d| _|d| _|d	| _d | _|d
| _d | _|d| _|d| _	d v rH|d| _
nd | _
|d| _|d| _d v ra|dd| _|d| _|d| _|dkr|d| _|d| _|d| _d S d | _d | _d | _d S )Nc                    s    |  }|dkr
d S |S NZUNKNOWNr   )r#   r   r   r   r   _read_field(  s   z7DistributionMetadata.read_pkg_file.<locals>._read_fieldc                    s     | d }|g krd S |S rl   )Zget_all)r#   valuesr  r   r   
_read_list.  s   z6DistributionMetadata.read_pkg_file.<locals>._read_listzmetadata-versionr#   r$   Zsummaryr'   r(   z	home-pager,   zdownload-urlr.   r1   r   platformZ
classifier1.1r3   r2   r4   )r   r#   r$   r.   r'   r)   r   r   r+   r,   r  r   rr   r1   r/   r0   r3   r2   r4   )rb   filer  r  Zmetadata_versionr   r  r   r  $  s<   













z"DistributionMetadata.read_pkg_filec                 C   sJ   	 t tj|dddd}| | W d    d S 1 sw   Y  d S )NzPKG-INFOwzUTF-8)encoding)r  r|   r}   r   write_pkg_file)rb   base_dirZpkg_infor   r   r   write_pkg_infoX  s   "z#DistributionMetadata.write_pkg_infoc                 C   sb  	 d}| j s| js| js| js| jrd}|d|  |d|    |d|    |d|    |d| 	   |d| 
   |d	|    |d
|    | jre|d| j  t|  }|d|  d|  }|r|d|  | |d|   | |d|   | |d|   | |d|   | |d|   d S )Nz1.0r
  zMetadata-Version: %s
z	Name: %s
zVersion: %s
zSummary: %s
zHome-page: %s
zAuthor: %s
zAuthor-email: %s
zLicense: %s
zDownload-URL: %s
zDescription: %s
r   zKeywords: %s
ZPlatformZ
ClassifierZRequiresZProvidesZ	Obsoletes)r2   r3   r4   r0   r  r\   get_nameget_versionget_descriptionget_urlget_contactget_contact_emailget_licenser   get_long_descriptionr   get_keywords_write_listget_platformsget_classifiersget_requiresget_providesget_obsoletes)rb   r  r$   Z	long_descr1   r   r   r   r  _  s8   z#DistributionMetadata.write_pkg_filec                 C   s    |D ]}| d||f  qd S )Nz%s: %s
)r\   )rb   r  r#   r  r   r   r   r   r    s   z DistributionMetadata._write_listc                 C   
   | j pdS r  )r#   r   r   r   r   r       
zDistributionMetadata.get_namec                 C   r   )Nz0.0.0)r$   r   r   r   r   r    r!  z DistributionMetadata.get_versionc                 C   s   d|   |  f S )Nz%s-%s)r  r  r   r   r   r   get_fullname  r   z!DistributionMetadata.get_fullnamec                 C   r   r  )r'   r   r   r   r   
get_author  r!  zDistributionMetadata.get_authorc                 C   r   r  )r   r   r   r   r   get_author_email  r!  z%DistributionMetadata.get_author_emailc                 C   r   r  )r)   r   r   r   r   get_maintainer  r!  z#DistributionMetadata.get_maintainerc                 C   r   r  )r   r   r   r   r   get_maintainer_email  r!  z)DistributionMetadata.get_maintainer_emailc                 C      | j p| jpdS r  )r)   r'   r   r   r   r   r    r   z DistributionMetadata.get_contactc                 C   r'  r  )r   r   r   r   r   r   r    r   z&DistributionMetadata.get_contact_emailc                 C   r   r  )r+   r   r   r   r   r    r!  zDistributionMetadata.get_urlc                 C   r   r  )r,   r   r   r   r   r    r!  z DistributionMetadata.get_licensec                 C   r   r  )r.   r   r   r   r   r    r!  z$DistributionMetadata.get_descriptionc                 C   r   r  )r   r   r   r   r   r    r!  z)DistributionMetadata.get_long_descriptionc                 C   
   | j pg S rl   )r1   r   r   r   r   r    r!  z!DistributionMetadata.get_keywordsc                 C      t |d| _d S )Nr1   )r   r1   rb   r   r   r   r   set_keywords  r   z!DistributionMetadata.set_keywordsc                 C   s   | j pdgS r  )r/   r   r   r   r   r    s   z"DistributionMetadata.get_platformsc                 C   r)  )Nr/   )r   r/   r*  r   r   r   set_platforms  r   z"DistributionMetadata.set_platformsc                 C   r(  rl   )r0   r   r   r   r   r    r!  z$DistributionMetadata.get_classifiersc                 C   r)  )Nr0   )r   r0   r*  r   r   r   set_classifiers  r   z$DistributionMetadata.set_classifiersc                 C   r   r  )r  r   r   r   r   get_download_url  r!  z%DistributionMetadata.get_download_urlc                 C   r(  rl   )r3   r   r   r   r   r    r!  z!DistributionMetadata.get_requiresc                 C   ,   dd l }|D ]}|j| qt|| _d S r   )distutils.versionpredicateversionpredicateVersionPredicater   r3   rb   r   ry   r   r   r   r   set_requires     z!DistributionMetadata.set_requiresc                 C   r(  rl   )r2   r   r   r   r   r    r!  z!DistributionMetadata.get_providesc                 C   s6   dd |D }|D ]}dd l }|j| q	|| _d S )Nc                 S   r   r   r   )r7   r   r   r   r   r9     r   z5DistributionMetadata.set_provides.<locals>.<listcomp>r   )r0  r1  Zsplit_provisionr2   )rb   r   r   ry   r   r   r   set_provides  s
   
z!DistributionMetadata.set_providesc                 C   r(  rl   )r4   r   r   r   r   r    r!  z"DistributionMetadata.get_obsoletesc                 C   r/  r   )r0  r1  r2  r   r4   r3  r   r   r   set_obsoletes  r5  z"DistributionMetadata.set_obsoletesrl   )$r   r   r   rD   rk   r  r  r  r  r  r  r"  r#  r$  r%  r&  r  r  r  r  Zget_licencer  r  r  r+  r  r,  r  r-  r.  r  r4  r  r6  r  r7  r   r   r   r   rB     sF    
	4"rB   c                 C   s&   	 g }| D ]}| |dd  q|S )Nr      )r   )r<   Znew_optionsZ
help_tupler   r   r   r     s
   r   )rZ   r|   reZemailr   rX   r   Zdistutils.errorsZdistutils.fancy_getoptr   r   Zdistutils.utilr   r   r   ry   r
   Zdistutils.debugr   compiler   r   r   rB   r   r   r   r   r   <module>   s8    
       Z c