a
    ze                     @   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yF   dZY n0 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   sL   t | trn<t | tsHt| 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.9/distutils/dist.py_ensure_list   s    


r   c                   @   s@  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dJd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dKd+d,ZdLd-d.ZdMd0d1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 )N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>       zDistribution.<listcomp>r   r   Nc                 C   s\  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r8|d= | D ]4\}}|  |}| D ]\}	}
d|
f||	< qqd|v r~|d |d< |d= d	}t!d urnt!"| nt#j$%|d
  | D ]\}}
t&| jd| rt| jd| |
 nNt&| j|rt| j||
 n0t&| |rt| ||
 ndt'| }t!"| qd| _(| jd urP| jD ].}|)ds6 qP|dkr d| _( qP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)self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   rf   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 }|sV| |d  d S |D ]h}| j|}|d u r| |d|   qZ| |d|   ||}|dD ]}| |d |  qqZd S )Nr   )pformatz  zno commands known yetzno option dict for '%s' commandzoption dict for '%s' command:r=   )Zpprintro   sortedrJ   keysannouncerU   split)	rb   headercommandsindentro   Zcmd_namerg   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|rB|	| tj
dkrRd}nd}| jrtjtjd|}tj|r|	| d}tj|r|	| 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   rr   )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rL| d | }|D ]}trl| d|  |	| |
 D ]V}||}| |}|D ]8}	|	dkr|	|vr|||	}
|	dd}	||
f||	< qq~|  qVd	| jv r| jd	  D ]\}	\}}
| j|	}zF|r.t| |t|
  n(|	d
v rJt| |	t|
 nt| |	|
 W q ty } zt|W Y d }~qd }~0 0 qd 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   rr   readZsectionsr<   rW   rU   replacerl   rJ   rV   negative_optrA   r   
ValueErrorDistutilsOptionError)rb   	filenamesr   Zignore_optionsparserfilenamesectionr<   rg   rh   ri   srcaliasr   r   r   r   parse_config_files}  sD    






zDistribution.parse_config_filesc                 C   s   |   }g | _t|| j }|| j |ddi |j| j| d}|	 }t
| j | |rhd S |r| ||}|d u rhd S qh| jr| j|t| jdk| jd d S | jstddS )Nr-   r,   )argsobjectr   display_optionsru   zno commands suppliedT)_get_toplevel_optionsru   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  s.    	
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yp } zt	|W Y d }~n
d }~0 0 t
||std| t|drt|jtsd}t|| | j}t|dr| }||j t|drt|jtrt|j}ng }|| j|j |  || ||d	d  \}}	t|	d
rX|	jrX| j|d|gd d S t|drt|jtrd}
|jD ]F\}}}}t|	||r|d	}
t|r|  nt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
SystemExitru   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   rf   Z	cmd_classr   r   r   ZoptsZhelp_option_foundZhelp_optionZshortZdescfuncrg   r#   r   r   r   r   r     sr    











z Distribution._parse_command_optsc                 C   sP   dD ]F}t | j|}|d u rqt|trdd |dD }t| j|| qd S )Nr1   r/   c                 S   s   g | ]}|  qS r   strip)r6   Zelmr   r   r   r8   j  r9   z1Distribution.finalize_options.<locals>.<listcomp>,)rE   rC   r   r   rs   rA   )rb   rd   r   r   r   r   ra   `  s    
zDistribution.finalize_optionsr   c           
      C   s  ddl m} ddlm} |rR|r*|  }n| j}|| || jd  t	d |rt|| j
 |d t	d | jD ]z}t|trt||r|}	n
| |}	t|	drt|	jtr||	jt|	j  n||	j |d|	j  t	d qzt	|| 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   ru   r   r   r   r   r]   r   r   r   r   r   rH   )
rb   r   r   r   ru   r   r   r<   rf   klassr   r   r   r   m  s:    






zDistribution._show_helpc           	      C   s   ddl m} | jr4|   td t|| j dS d}i }| jD ]}d||d < qB|D ]l\}}|rX||rXt|}t	| j
d|  }|dv rtd| n |dv rtd	| nt| d}qX|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optionrh   ri   r   r   r   r   r     s*    
z#Distribution.handle_display_optionsc              	   C   sh   t |d  |D ]R}| j|}|s.| |}z
|j}W n tyN   d}Y n0 t d|||f  qd S )N:(no description available)z
  %-*s  %s)r   rF   rU   r   r.   AttributeError)rb   ru   rt   
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 ]}||s4|| q4d}|| D ]}t||krZt|}qZ| |d| |rt	  | |d| d S )Nr   r   zStandard commandszExtra commands)
distutils.commandrf   __all__rF   rq   rU   r   r   r   r   )rb   rz   std_commandsis_stdr   extra_commandsr   r   r   r   r     s.    


zDistribution.print_commandsc           	   	   C   s   dd l }|jj}i }|D ]}d||< qg }| j D ]}||s4|| q4g }|| D ]N}| j|}|sx| |}z
|j}W n t	y   d}Y n0 |||f qZ|S )Nr   r   r   )
r   rf   r   rF   rq   rU   r   r   r.   r   )	rb   rz   r   r   r   r   rvr   r.   r   r   r   get_command_list  s(    	




zDistribution.get_command_listc                 C   sN   | j }t|tsJ|d u rd}dd |dD }d|vrD|dd || _ |S )Nr;   c                 S   s   g | ]}|d kr|  qS )r;   r   )r6   Zpkgr   r   r   r8   !  r9   z5Distribution.get_command_packages.<locals>.<listcomp>r   zdistutils.commandr   )rG   r   r   rs   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Y n0 zt||}W n$ ty   t	d|||f Y n0 || j |< |  S t	d| d S )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   rf   r   Zpkgnamemodule_nameZ
klass_namemoduler   r   r   r   '  s,    


zDistribution.get_command_classc                 C   sl   | j |}|sh|rhtr&| d|  | |}||  }| j |< d| j|< | j|}|rh| || |S )Nz<Distribution.get_command_obj(): creating '%s' command objectr   )rS   rU   r   rr   r   rT   rJ   _set_command_options)rb   rf   Zcreatecmd_objr   r<   r   r   r   get_command_objM  s    

zDistribution.get_command_objc                 C   sZ  |  }|d u r| |}tr,| d|  | D ]\}\}}trZ| d|||f  zdd |jD }W n ty   g }Y n0 z
|j}W n ty   i }Y n0 z|t|t	}	||v r|	rt
||| t|  nJ||v r|	rt
||t| n,t||rt
||| ntd|||f W q4 tyR }
 zt|
W Y d }
~
q4d }
~
0 0 q4d S )Nz#  setting options for '%s' command:z    %s = %s (from %s)c                 S   s   g | ]}t |qS r   r5   )r6   or   r   r   r8   |  s   z5Distribution._set_command_options.<locals>.<listcomp>z1error in %s: command '%s' has no such option '%s')get_command_namerW   r   rr   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  sF    	






z!Distribution._set_command_optionsr   c                 C   s|   ddl m} t||s&|}| |}n| }|js8|S |  d|_d| j|< | | |rx|	 D ]}| 
|| qf|S )Nr   r   )r   r   r   r   r   Z	finalizedZinitialize_optionsrT   r   Zget_sub_commandsreinitialize_command)rb   rf   Zreinit_subcommandsr   r   subr   r   r   r     s    


z!Distribution.reinitialize_commandc                 C   s   t  || d S rm   r	   )rb   r   levelr   r   r   rr     s    zDistribution.announcec                 C   s   | j D ]}| | qd S rm   )ru   run_command)rb   r   r   r   r   run_commands  s    
zDistribution.run_commandsc                 C   sD   | j |rd S td| | |}|  |  d| j |< d S )Nz
running %sr   )rT   rU   r
   infor   Zensure_finalizedrun)rb   rf   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   s   | j ot| j dkS r   )rO   r   r   r   r   r   has_ext_modules  s    zDistribution.has_ext_modulesc                 C   s   | j ot| j dkS r   )rM   r   r   r   r   r   has_c_libraries  s    zDistribution.has_c_librariesc                 C   s   |   p|  S rm   )r   r   r   r   r   r   has_modules  s    zDistribution.has_modulesc                 C   s   | j ot| j dkS r   )rN   r   r   r   r   r   has_headers  s    zDistribution.has_headersc                 C   s   | j ot| j dkS r   )rP   r   r   r   r   r   has_scripts  s    zDistribution.has_scriptsc                 C   s   | j ot| j dkS r   )rQ   r   r   r   r   r   has_data_files  s    zDistribution.has_data_filesc                 C   s   |   o|   o|   S rm   )r   r   r   r   r   r   r   is_pure  s
    zDistribution.is_pure)N)NNr;   )N)r   )N)r   )(r   
__module____qualname__r   r   r   r@   r   rl   rW   ry   r   r   r   r   r   ra   r   r   r   r   r   r   r   r   r   r   r
   INFOrr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ,   sL   ,
 
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| nfd | _d | _d | _d | _d | _d | _d | _d | _	d | _
d | _d | _d | _d | _d | _d | _d | _d | _d S rm   )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   rl     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 r|d| _
nd | _
|d| _|d| _d v r|dd| _|d| _|d| _|dkr|d| _|d| _|d| _n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 rm   )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   rs   r1   r/   r0   r3   r2   r4   )rb   filer  r  Zmetadata_versionr   r  r   r   $  s:    












z"DistributionMetadata.read_pkg_filec                 C   sF   t tj|dddd}| | W d    n1 s80    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r|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
  _  s6    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   s
   | j pdS r   )r#   r   r   r   r   r    s    zDistributionMetadata.get_namec                 C   s
   | j pdS )Nz0.0.0)r$   r   r   r   r   r    s    z DistributionMetadata.get_versionc                 C   s   d|   |  f S )Nz%s-%s)r  r  r   r   r   r   get_fullname  s    z!DistributionMetadata.get_fullnamec                 C   s
   | j pdS r   )r'   r   r   r   r   
get_author  s    zDistributionMetadata.get_authorc                 C   s
   | j pdS r   )r   r   r   r   r   get_author_email  s    z%DistributionMetadata.get_author_emailc                 C   s
   | j pdS r   )r)   r   r   r   r   get_maintainer  s    z#DistributionMetadata.get_maintainerc                 C   s
   | j pdS r   )r   r   r   r   r   get_maintainer_email  s    z)DistributionMetadata.get_maintainer_emailc                 C   s   | j p| jpdS r   )r)   r'   r   r   r   r   r    s    z DistributionMetadata.get_contactc                 C   s   | j p| jpdS r   )r   r   r   r   r   r   r    s    z&DistributionMetadata.get_contact_emailc                 C   s
   | j pdS r   )r+   r   r   r   r   r    s    zDistributionMetadata.get_urlc                 C   s
   | j pdS r   )r,   r   r   r   r   r    s    z DistributionMetadata.get_licensec                 C   s
   | j pdS r   )r.   r   r   r   r   r    s    z$DistributionMetadata.get_descriptionc                 C   s
   | j pdS r   )r   r   r   r   r   r    s    z)DistributionMetadata.get_long_descriptionc                 C   s
   | j pg S rm   )r1   r   r   r   r   r    s    z!DistributionMetadata.get_keywordsc                 C   s   t |d| _d S )Nr1   )r   r1   rb   r   r   r   r   set_keywords  s    z!DistributionMetadata.set_keywordsc                 C   s   | j p
dgS r   )r/   r   r   r   r   r    s    z"DistributionMetadata.get_platformsc                 C   s   t |d| _d S )Nr/   )r   r/   r!  r   r   r   set_platforms  s    z"DistributionMetadata.set_platformsc                 C   s
   | j pg S rm   )r0   r   r   r   r   r    s    z$DistributionMetadata.get_classifiersc                 C   s   t |d| _d S )Nr0   )r   r0   r!  r   r   r   set_classifiers  s    z$DistributionMetadata.set_classifiersc                 C   s
   | j pdS r   )r   r   r   r   r   get_download_url  s    z%DistributionMetadata.get_download_urlc                 C   s
   | j pg S rm   )r3   r   r   r   r   r    s    z!DistributionMetadata.get_requiresc                 C   s,   dd l }|D ]}|j| qt|| _d S r   )distutils.versionpredicateversionpredicateVersionPredicater   r3   rb   r   rz   r   r   r   r   set_requires  s    z!DistributionMetadata.set_requiresc                 C   s
   | j pg S rm   )r2   r   r   r   r   r    s    z!DistributionMetadata.get_providesc                 C   s6   dd |D }|D ]}dd l }|j| q|| _d S )Nc                 S   s   g | ]}|  qS r   r   )r6   r   r   r   r   r8     r9   z5DistributionMetadata.set_provides.<locals>.<listcomp>r   )r&  r'  Zsplit_provisionr2   )rb   r   r   rz   r   r   r   set_provides  s
    z!DistributionMetadata.set_providesc                 C   s
   | j pg S rm   )r4   r   r   r   r   r    s    z"DistributionMetadata.get_obsoletesc                 C   s,   dd l }|D ]}|j| qt|| _d S r   )r&  r'  r(  r   r4   r)  r   r   r   set_obsoletes  s    z"DistributionMetadata.set_obsoletes)N)$r   r   r   rD   rl   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  r*  r  r+  r  r,  r   r   r   r   rB     sB   	
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   rz   r
   Zdistutils.debugr   compiler   r   r   rB   r   r   r   r   r   <module>   s2   

       Z c