B YI~d���@s�ddlZddlZddlZddlmZy ddlZWnek rHdZYnXddlTddlm Z m Z ddl m Z m Z mZddlmZddlmZe�d�Zd d �ZGd d �d �ZGd d�d�Zdd�ZdS)�N)�message_from_file)�*)� FancyGetopt�translate_longopt)� check_environ� strtobool� rfc822_escape)�log)�DEBUGz^[a-zA-Z]([a-zA-Z0-9_]*)$cCsLt|t�r n�Zd?d@�ZdAdB�ZdcdCdD�ZdddEdF�ZdedHdI�ZejfdJdK�ZdLdM�ZdNdO�ZdPdQ�Z dRdS�Z!dTdU�Z"dVdW�Z#dXdY�Z$dZd[�Z%d\d]�Z&d^d_�Z'd S)f� Distribution)�verbose�vzrun verbosely (default)�)�quiet�qz!run quietly (turns verbosity off))zdry-run�nzdon't actually do anything)�help�hzshow detailed help message)z no-user-cfgNz-ignore pydistutils.cfg in your home directoryz�Common commands: (see '--help-commands' for more) setup.py build will build the package underneath 'build/' setup.py install will install the package )z help-commandsNzlist all available commands)�nameNzprint package name)�version�Vzprint package version)�fullnameNzprint -)�authorNzprint the author's name)z author-emailNz print the author's email address)� maintainerNzprint the maintainer's name)zmaintainer-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)�urlNzprint the URL for this package)�licenseNz print the license of the package)�licenceNzalias for --license)� descriptionNzprint the package description)zlong-descriptionNz"print the long package description)� platformsNzprint the list of platforms)� classifiersNzprint the list of classifiers)�keywordsNzprint 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 obsoletecCsg|]}t|d��qS)r)r)�.0�xrrr� �szDistribution.rrNcCsld|_d|_d|_x|jD]}t||d�qWt�|_x,|jjD] }d|}t||t|j|��q@Wi|_ d|_ d|_ d|_ i|_ g|_d|_i|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_i|_i|_|�r|�d�}|dk �rH|d=xD|��D]8\}}|� |�}x"|��D]\} } d| f|| <�q(W�q Wd|k�r�|d|d<|d=d } t!dk �r~t!�"| �nt#j$�%| d �x�|��D]�\} } t&|jd | ��r�t|jd | �| �nNt&|j| ��r�t|j| | �n0t&|| ��rt|| | �nd t'| �} t!�"| ��q�Wd |_(|j dk �r`x0|j D]&} | �)d��sHP| dk�r6d|_(P�q6W|�*�dS)Nrr�get_��optionsz setup scriptr)r(z:'licence' distribution option is deprecated; use 'license'� Zset_zUnknown 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_filesZpassword� command_obj�have_run�get�items�get_option_dict�warnings�warn�sys�stderr�write�hasattr�repr� want_user_cfg� startswith�finalize_options)�selfZattrs�attr�basenameZ method_namer6�commandZ cmd_options�opt_dict�opt�valr�key�argrrr�__init__�s~                 zDistribution.__init__cCs&|j�|�}|dkr"i}|j|<|S)N)rDrN)r[r^�dictrrrrP&s zDistribution.get_option_dictr5c Cs�ddlm}|dkr"t|j���}|dk r@|�||�|d}|sV|�|d�dSxt|D]l}|j�|�}|dkr�|�|d|�q\|�|d|�||�}x$|�d�D]}|�|d|�q�Wq\WdS)Nr)�pformatz zno commands known yetzno option dict for '%s' commandzoption dict for '%s' command:r7)Zpprintrf�sortedrD�keys�announcerN�split) r[�header�commands�indentrfZcmd_namer_�out�linerrr�dump_option_dicts1s&    zDistribution.dump_option_dictscCs�g}t�tj�tjdj�}tj�|d�}tj�|�rB|� |�tj dkrRd}nd}|j r�tj�tj� d�|�}tj�|�r�|� |�d}tj�|�r�|� |�t r�|�dd �|��|S) N� distutilsz distutils.cfg�posixz.pydistutils.cfgzpydistutils.cfg�~z setup.cfgzusing config files: %sz, )r�os�path�dirnamerS�modules�__file__�join�isfile�appendr rX� expanduserr ri)r[�filesZsys_dirZsys_fileZ user_filenameZ user_fileZ local_filerrr�find_config_filesMs&       zDistribution.find_config_filesc Cs�ddlm}tjtjkr8ddddddd d d d d ddg }ng}t|�}|dkrT|��}trb|�d�|�}x�|D]�}tr�|�d|�|� |�xf|� �D]Z}|� |�}|� |�}x@|D]8} | dkr�| |kr�|� || �} | �dd�} || f|| <q�Wq�W|��qnWd|jk�r�x�|jd��D]�\} \} } |j� | �} yF| �rRt|| t| � �n(| dk�rnt|| t| ��n t|| | �Wn,tk �r�} z t| ��Wdd} ~ XYnX�qWdS)Nr)� ConfigParserz install-basezinstall-platbasez install-libzinstall-platlibzinstall-purelibzinstall-headerszinstall-scriptsz install-data�prefixz exec-prefix�home�user�rootz"Distribution.parse_config_files():z reading %srr8�_�global)rr9)Z configparserrrSr�� base_prefix� frozensetr~r ri�readZsectionsr6rPrN�replacerdrDrO� negative_optr;r� ValueError�DistutilsOptionError)r[� filenamesrZignore_options�parser�filename�sectionr6r_r`ra�src�aliasrrrr�parse_config_files}sJ               zDistribution.parse_config_filescCs�|��}g|_t||j�}|�|j�|�ddi�|j|j|d�}|� �}t � |j �|� |�rhdSx |r�|�||�}|dkrjdSqjW|jr�|j|t|j�dk|jd�dS|js�td��dS)Nr)r()�args�objectr)�display_optionsrlzno commands suppliedT)�_get_toplevel_optionsrlrr��set_negative_aliasesr�Z set_aliases�getoptrCZget_option_orderr Z set_verbosityr�handle_display_options�_parse_command_optsr� _show_help�len�DistutilsArgError)r[Ztoplevel_optionsr�r�� option_orderrrr�parse_command_line�s,       zDistribution.parse_command_linecCs |jdgS)N)zcommand-packages=Nz0list of packages that provide distutils commands)�global_options)r[rrrr��sz"Distribution._get_toplevel_optionsc Csddlm}|d}t�|�s*td|��|j�|�y|�|�}Wn*tk rn}z t |��Wdd}~XYnXt ||�s�t d|��t |d�r�t |jt�s�d}t ||��|j}t |d�r�|��}|�|j�t |d�r�t |jt�r�t|j�}ng}|�|j|j|�|�|�|�|d d��\}} t | d ��rV| j�rV|j|d|gd �dSt |d��r�t |jt��r�d} xP|jD]F\} } } }t | |�| ���r|d } t|��r�|�nt d || f���q|W| �r�dS|�|�}x&t| ���D]\}}d |f||<�q�W|S)Nr)�Commandzinvalid 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_optionsrr)r�rlzYinvalid help function %r for help option '%s': must be a callable object (function, etc.)z command line) � distutils.cmdr�� command_re�match� SystemExitrlr{�get_command_class�DistutilsModuleErrorr�� issubclassZDistutilsClassErrorrVr r�rr��copy�updater��fix_help_options�set_option_tabler�r�r�rr�Z get_attr_name�callablerP�varsrO)r[r�r�r�r^Z cmd_classrr�r�ZoptsZhelp_option_foundZ help_optionZshortZdesc�funcr_r rrrrr�sb                   z Distribution._parse_command_optscCsTxNdD]F}t|j|�}|dkr qt|t�rdd�|�d�D�}t|j||�qWdS)N)r-r+cSsg|] }|���qSr)�strip)r1Zelmrrrr3jsz1Distribution.finalize_options..�,)r?r=r r rjr;)r[r\rrrrrZ`s   zDistribution.finalize_optionsrc Cs ddlm}ddlm}|rR|r*|��}n|j}|�|�|�|jd�t d�|rt|�|j �|�d�t d�x�|j D]z}t |t �r�t||�r�|} n |�|�} t| d�r�t | jt�r�|�| jt| j��n |�| j�|�d| j�t d�q|Wt ||j��dS) Nr)� gen_usage)r�z Global options:r5zKInformation display options (just display information, ignore any commands)r�zOptions for '%s' command:)�distutils.corer�r�r�r�r�r�� print_help� common_usage�printr�rlr rr�r�rVr�rr�r�rrB) r[r�r�r�rlr�r�r6r^�klassrrrr�ms4           zDistribution._show_helpc Cs�ddlm}|jr4|��td�t||j��dSd}i}x|jD]}d||d<qDWxt|D]l\}}|r^|�|�r^t|�}t |j d|��}|dkr�td� |��n |dkr�td � |��nt|�d}q^W|S) Nr)r�r5rr4)r-r+r�)r,r.r/r0r7) r�r�Z help_commands�print_commandsr�rBr�rNrr?r=ry) r[r�r�Zany_display_optionsZis_display_option�optionr`rarrrrr��s*  z#Distribution.handle_display_optionsc Csnt|d�x\|D]T}|j�|�}|s0|�|�}y |j}Wntk rRd}YnXtd|||f�qWdS)N�:z(no description available)z %-*s %s)r�r@rNr�r*�AttributeError)r[rlrk� max_length�cmdr�r*rrr�print_command_list�s      zDistribution.print_command_listcCs�ddl}|jj}i}x|D] }d||<qWg}x&|j��D]}|�|�s:|�|�q:Wd}x$||D]}t|�|krdt|�}qdW|�|d|�|r�t �|�|d|�dS)NrrzStandard commandszExtra commands) �distutils.commandr^�__all__r@rhrNr{r�r�r�)r[rq� std_commands�is_stdr��extra_commandsr�rrrr��s*     zDistribution.print_commandsc Cs�ddl}|jj}i}x|D] }d||<qWg}x&|j��D]}|�|�s:|�|�q:Wg}x\||D]P}|j�|�}|s�|�|�}y |j}Wnt k r�d}YnX|�||f�qdW|S)Nrrz(no description available)) r�r^r�r@rhrNr{r�r*r�) r[rqr�r�r�r��rvr�r*rrr�get_command_list�s(        zDistribution.get_command_listcCsN|j}t|t�sJ|dkrd}dd�|�d�D�}d|krD|�dd�||_|S)Nr5cSsg|]}|dkr|���qS)r5)r�)r1Zpkgrrrr3!sz5Distribution.get_command_packages..r�zdistutils.commandr)rAr rrj�insert)r[Zpkgsrrr�get_command_packagess  z!Distribution.get_command_packagesc Cs�|j�|�}|r|Sx�|��D]�}d||f}|}yt|�tj|}Wntk r^wYnXyt||�}Wn&tk r�t d|||f��YnX||j|<|SWt d|��dS)Nz%s.%sz3invalid command '%s' (no class '%s' in module '%s')zinvalid command '%s') r@rNr�� __import__rSrw� ImportErrorr?r�r�)r[r^r�ZpkgnameZ module_nameZ klass_name�modulerrrr�'s(   zDistribution.get_command_classcCsl|j�|�}|sh|rhtr&|�d|�|�|�}||�}|j|<d|j|<|j�|�}|rh|�||�|S)Nz.z1error in %s: command '%s' has no such option '%s')�get_command_namerPr rirOZboolean_optionsr�r�r r r;rrVr�r�) r[rLZ option_dict� command_namer��sourcerZ bool_optsZneg_optZ is_stringrrrrr�hs>           z!Distribution._set_command_optionsrcCs�ddlm}t||�s&|}|�|�}n|��}|js8|S|��d|_d|j|<|�|�|r|x|� �D]}|� ||�qhW|S)Nr)r�) r�r�r r�r�Z finalizedZinitialize_optionsrMr�Zget_sub_commands�reinitialize_command)r[r^Zreinit_subcommandsr�r��subrrrr��s     z!Distribution.reinitialize_commandcCst�||�dS)N)r )r[r�levelrrrri�szDistribution.announcecCsx|jD]}|�|�qWdS)N)rl� run_command)r[r�rrr� run_commands�s zDistribution.run_commandscCsD|j�|�rdSt�d|�|�|�}|��|��d|j|<dS)Nz running %sr)rMrNr �infor�Zensure_finalized�run)r[r^r�rrrr��s   zDistribution.run_commandcCst|jp|jpg�dkS)Nr)r�rErF)r[rrr�has_pure_modules�szDistribution.has_pure_modulescCs|jot|j�dkS)Nr)rIr�)r[rrr�has_ext_modules�szDistribution.has_ext_modulescCs|jot|j�dkS)Nr)rGr�)r[rrr�has_c_libraries�szDistribution.has_c_librariescCs|��p|��S)N)r�r�)r[rrr� has_modules�szDistribution.has_modulescCs|jot|j�dkS)Nr)rHr�)r[rrr� has_headers�szDistribution.has_headerscCs|jot|j�dkS)Nr)rJr�)r[rrr� has_scripts�szDistribution.has_scriptscCs|jot|j�dkS)Nr)rKr�)r[rrr�has_data_files�szDistribution.has_data_filescCs|��o|�� o|�� S)N)r�r�r�)r[rrr�is_pure�s zDistribution.is_pure)N)NNr5)N)r)N)r)(r� __module__� __qualname__r�r�r�r:r�rdrPrpr~r�r�r�r�rZr�r�r�r�r�r�r�r�r�r�r �INFOrir�r�r�r�r�r�r�r�r�r�rrrrr,sz   0 :C [  1(!" &  , ) rc@seZdZdZdAdd�Zdd�Zdd�Zd d �Zd d �Zd d�Z dd�Z dd�Z dd�Z dd�Z dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�ZeZd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Z d;d<�Z!d=d>�Z"d?d@�Z#dS)Br<)r r!r$� author_emailr%�maintainer_emailr'r(r*�long_descriptionr-r+r#r&Z contact_emailr,� download_urlr.r/r0NcCs�|dk r|�t|��nfd|_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ d|_d|_d|_d|_d|_dS)N)� read_pkg_file�openr r!r$r�r%r�r'r(r*r�r-r+r,r�r.r/r0)r[rurrrrd s&zDistributionMetadata.__init__cst|���fdd�}�fdd�}�d}|d�|_|d�|_|d�|_|d �|_d|_|d �|_d|_|d �|_|d �|_ d �kr�|d �|_ nd|_ |d�|_ |d�|_d�kr�|d�� d�|_ |d�|_|d�|_|dkr�|d�|_|d�|_|d�|_nd|_d|_d|_dS)Ncs�|}|dkrdS|S)N�UNKNOWNr)r r)rrr� _read_field(sz7DistributionMetadata.read_pkg_file.._read_fieldcs��|d�}|gkrdS|S)N)Zget_all)r �values)rrr� _read_list.s z6DistributionMetadata.read_pkg_file.._read_listzmetadata-versionr r!Zsummaryr$z author-emailz home-pager(z download-urlr*r-r��platformZ classifierz1.1r/r.r0)rr r!r*r$r%r�r�r'r(r�r�rjr-r+r,r/r.r0)r[�filer�r�Zmetadata_versionr)rrr�$s:                 z"DistributionMetadata.read_pkg_filec Cs2ttj�|d�ddd��}|�|�WdQRXdS)NzPKG-INFO�wzUTF-8)�encoding)r�rtrury�write_pkg_file)r[Zbase_dirZpkg_inforrr�write_pkg_infoXs z#DistributionMetadata.write_pkg_infocCsbd}|js"|js"|js"|js"|jr&d}|�d|�|�d|���|�d|���|�d|���|�d|� ��|�d|� ��|�d |� ��|�d |� ��|jr�|�d |j�t |���}|�d |�d �|���}|�r|�d|�|�|d|���|�|d|���|�|d|���|�|d|���|�|d|���dS)Nz1.0z1.1zMetadata-Version: %s z Name: %s z Version: %s z Summary: %s zHome-page: %s z Author: %s zAuthor-email: %s z License: %s zDownload-URL: %s zDescription: %s r�z Keywords: %s ZPlatformZ ClassifierZRequiresZProvidesZ Obsoletes)r.r/r0r,r�rU�get_name� get_version�get_description�get_url� get_contact�get_contact_email� get_licenser�get_long_descriptionry� get_keywords� _write_list� get_platforms�get_classifiers� get_requires� get_provides� get_obsoletes)r[r�r!Z long_descr-rrrr�_s0  z#DistributionMetadata.write_pkg_filecCs$x|D]}|�d||f�qWdS)Nz%s: %s )rU)r[r�r r�rrrrr�s z DistributionMetadata._write_listcCs |jpdS)Nr�)r )r[rrrr��szDistributionMetadata.get_namecCs |jpdS)Nz0.0.0)r!)r[rrrr��sz DistributionMetadata.get_versioncCsd|��|��fS)Nz%s-%s)r�r�)r[rrr� get_fullname�sz!DistributionMetadata.get_fullnamecCs |jpdS)Nr�)r$)r[rrr� get_author�szDistributionMetadata.get_authorcCs |jpdS)Nr�)r�)r[rrr�get_author_email�sz%DistributionMetadata.get_author_emailcCs |jpdS)Nr�)r%)r[rrr�get_maintainer�sz#DistributionMetadata.get_maintainercCs |jpdS)Nr�)r�)r[rrr�get_maintainer_email�sz)DistributionMetadata.get_maintainer_emailcCs|jp|jpdS)Nr�)r%r$)r[rrrr��sz DistributionMetadata.get_contactcCs|jp|jpdS)Nr�)r�r�)r[rrrr��sz&DistributionMetadata.get_contact_emailcCs |jpdS)Nr�)r')r[rrrr��szDistributionMetadata.get_urlcCs |jpdS)Nr�)r()r[rrrr��sz DistributionMetadata.get_licensecCs |jpdS)Nr�)r*)r[rrrr��sz$DistributionMetadata.get_descriptioncCs |jpdS)Nr�)r�)r[rrrr��sz)DistributionMetadata.get_long_descriptioncCs |jpgS)N)r-)r[rrrr��sz!DistributionMetadata.get_keywordscCst|d�|_dS)Nr-)rr-)r[rrrr� set_keywords�sz!DistributionMetadata.set_keywordscCs |jp dgS)Nr�)r+)r[rrrr�sz"DistributionMetadata.get_platformscCst|d�|_dS)Nr+)rr+)r[rrrr� set_platforms�sz"DistributionMetadata.set_platformscCs |jpgS)N)r,)r[rrrr�sz$DistributionMetadata.get_classifierscCst|d�|_dS)Nr,)rr,)r[rrrr�set_classifiers�sz$DistributionMetadata.set_classifierscCs |jpdS)Nr�)r�)r[rrr�get_download_url�sz%DistributionMetadata.get_download_urlcCs |jpgS)N)r/)r[rrrr�sz!DistributionMetadata.get_requirescCs0ddl}x|D]}|j�|�qWt|�|_dS)Nr)�distutils.versionpredicate�versionpredicate�VersionPredicaterr/)r[rrqrrrr� set_requires�s z!DistributionMetadata.set_requirescCs |jpgS)N)r.)r[rrrr�sz!DistributionMetadata.get_providescCs:dd�|D�}x |D]}ddl}|j�|�qW||_dS)NcSsg|] }|���qSr)r�)r1rrrrr3�sz5DistributionMetadata.set_provides..r)rrZsplit_provisionr.)r[rrrqrrr� set_provides�s  z!DistributionMetadata.set_providescCs |jpgS)N)r0)r[rrrr�sz"DistributionMetadata.get_obsoletescCs0ddl}x|D]}|j�|�qWt|�|_dS)Nr)rrrrr0)r[rrqrrrr� set_obsoletes�s z"DistributionMetadata.set_obsoletes)N)$rr�r�r>rdr�r�r�rr�r�rrrr r r�r�r�r�Z get_licencer�r�r�r rr rr rrrrrrrrrrrr<�sB 4"r<cCs(g}x|D]}|�|dd��q W|S)Nr�)r{)r6Z new_optionsZ help_tuplerrrr��s r�)rSrt�reZemailrrQr�Zdistutils.errorsZdistutils.fancy_getoptrrZdistutils.utilrrrrqr Zdistutils.debugr �compiler�rrr<r�rrrr�s2      Zc