a
    x.Cb/                     @   s   d Z ddlZddlZddlmZ ddlmZ ddlmZm	Z	 ddl
mZ ddlmZmZmZmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ G dd deZG dd deZej !ddg ej"!dg dS )z
bdist_conda

    N)defaultdict)install)DistutilsOptionErrorDistutilsGetoptError)Distribution)StringIOstring_typesconfigparserPY3	text_typespec_from_line)MetaData)api)pypi)handle_anaconda_upload)Configc                	       s8   e Zd ZdZdddddddddZd fdd	Z  ZS )	CondaDistributiona  
    Distribution subclass that supports bdist_conda options

    This class is required if you want to pass any bdist_conda specific
    options to setup().  To use, set distclass=CondaDistribution in setup().

    **NOTE**: If you use setuptools, you must import setuptools before
    importing distutils.commands.bdist_conda.

    Options that can be passed to setup() (must include
    distclass=CondaDistribution):

    - conda_buildnum: The build number. Defaults to 0. Can be overridden on
      the command line with the --buildnum flag.

    - conda_buildstr: The build string. Default is generated automatically
      from the Python version, NumPy version if relevant, and the build
      number, like py34_0.

    - conda_import_tests: Whether to automatically run import tests. The
      default is True, which runs import tests for the all the modules in
      "packages". Also allowed are False, which runs no tests, or a list of
      module names to be tested on import.

    - conda_command_tests: Command line tests to run. Default is True, which
      runs ``command --help`` for each ``command`` in the console_scripts and
      gui_scripts entry_points. Also allowed are False, which doesn't run any
      command tests, or a list of command tests to run.

    - conda_binary_relocation: Whether binary files should be made relocatable
      (using install_name_tool on OS X or patchelf on Linux). The default is
      True. See the "making packages relocatable" section in the conda build
      documentation for more information on this.

    - conda_preserve_egg_dir: Whether to preserve the egg directory as
      installed by setuptools.  The default is True if the package depends on
      setuptools or has a setuptools entry_points other than console_scripts
      and gui_scripts.

    Command line options:

    --buildnum: Set the build number. Defaults to the conda_buildnum passed to
      setup(), or 0. Overrides any conda_buildnum passed to setup().

    r   NT)conda_buildnumconda_buildstrconda_import_testsconda_command_testsconda_binary_relocationconda_preserve_egg_dirconda_featuresconda_track_featuresc              	      st   i }|r*| j D ]}||v r||||< qts<t| | nt | | j D ] }t| j|||| j |  qNd S N)	conda_attrspopr
   r   __init__supersetattrmetadataget)selfattrsZgiven_attrsattr	__class__ .lib/python3.9/distutils/command/bdist_conda.pyr   [   s    

zCondaDistribution.__init__)N)__name__
__module____qualname____doc__r   r   __classcell__r)   r)   r'   r*   r      s   4r   c                       sX   e Zd ZdZedeee d  ddZ fddZ	 fdd	Z
 fd
dZ  ZS )bdist_condazcreate a conda packageZbdist_conda_i  T)Zbuild_idZbuild_is_hostc                    s*   t st|  n
t   d | _d| _d S )NF)r
   r   initialize_optionsr    buildnumanaconda_uploadr$   r'   r)   r*   r1   s   s
    
zbdist_conda.initialize_optionsc                    sH   | j d}| jrtdd| jjf|d< ts:t|  n
t	   d S )Nr   z--prefix is not allowedr0   prefix)
distributionZget_option_dictr5   r   configZhost_prefixr
   r   finalize_optionsr    )r$   Zopt_dictr'   r)   r*   r8   |   s    zbdist_conda.finalize_optionsc              
      s  j j}tjD ] }t||st||tj|  qjd urBj|_tt	}|j
 |d d< |j|d d< |j|d d< |j|d d< |j|d d< |j|d d< |j|d d	< |j|d d
< dd |jpg tj dg pg  D dg  |d d< |d d< tj dr,dd j jpg D |d d< |j|d d< |j|d d< |j|d d< tj dg }|r&t|tr2ddd | D }t  i }z t| W n> t y } z$t!dt"| d | W Y d }~nPd }~0 0  # D ]<dv r& fd d $D }||< nd |< qt|t	sLt!d!| n|%d"g }|%d#g }	|%d$g }
|s|	s|
st&|d%kr|d d 'd& |d d 'd& ||	 |
 }|
rj(j)d'krd(|d d)< t&|	|
 d*kr&||d d< |j*d(u r&t+t,t-t./||d d+< d&|d d v rDd(|d d< |j0r|j0d(u r~j j1pdg j j2ppg  |d d,< n|j0|d d,< |j*rt|j*t3st+t,t-|j*|d d+< t	|}d(j(_4t5j6|j(d-}|7  d.|j(_8d/t"t9j:j;t"t9j:j<f|j(j=d< t>j?|d(d(d0 |j(_(t@s:tAB n
tC B  t>j?|d(d(d1d* }t>jD||j(d- |j(E  jFrG fd2d3d3}tG|| nd4| }tH| d S )5NpackagenameversionbuildZnumberstringZbinary_relocationZpreserve_egg_dirZfeaturesZtrack_featuresc                 S   s   g | ]}t |qS r)   r   .0ir)   r)   r*   
<listcomp>       z#bdist_conda.run.<locals>.<listcomp>Zinstall_requiresZpythonZrequirementsruntests_requirec                 S   s   g | ]}t |qS r)   r   r>   r)   r)   r*   rA      rB   testrequiresZabouthomelicenseZsummaryentry_points
c                 s   s   | ]}|  V  qd S r   )strip)r?   xr)   r)   r*   	<genexpr>   rB   z"bdist_conda.run.<locals>.<genexpr>z$ERROR: entry-points not understood: z
The string was)console_scriptsgui_scriptsc                    s"   g | ]}| d   | qS )=)r#   )r?   Zoption)csectionr)   r*   rA      s   z.ERROR: Could not add entry points. They were:
ZscriptsrN   rO      Z
setuptoolsZosxTZ
osx_is_appr   ZcommandsZimports)r7   F.)Z
build_onlynotest)ZpostrU   c                       s   e Zd Z jZdS )zbdist_conda.run.<locals>.argsN)r+   r,   r-   r3   r)   r4   r)   r*   args  s   rV   z[# If you want to upload this package to anaconda.org later, type:
#
# $ anaconda upload %s
)Ir6   r"   r   r   hasattrr!   r2   r   r   dictr:   lowerr;   r   r   r   r   r   rF   getattrrD   ZurlrH   description
isinstancer   join
splitlinesr	   ZConfigParserZ	read_filer   	Exceptionr   strZsectionsZoptionsr#   lenappendr7   platformr   listmapunicoder   Zmake_entry_testsr   ZpackagesZ
py_modulesboolZkeep_old_workr   ZfromdictZcheck_fieldsZset_build_idsysversion_infomajorminorZvariantr   r<   r
   r   rC   r    rE   Zcleanr3   r   print)r$   r"   r&   drI   ZnewstrerrvalueZrsZcsZgsZ
entry_listmoutputrV   Zno_upload_messager'   )rQ   rR   r$   r*   rC      s    





 


zbdist_conda.run)r+   r,   r-   r[   r   r`   inttimer7   r1   r8   rC   r/   r)   r)   r'   r*   r0   n   s   	r0   )z	buildnum=NzThe build number of
    the conda package. Defaults to 0, or the conda_buildnum specified in the
    setup() function. The command line flag overrides the option to
    setup().)anaconda-uploadNz+Upload the finished package to anaconda.orgrt   )#r.   rh   rs   collectionsr   Zdistutils.command.installr   Zdistutils.errorsr   r   Zdistutils.distr   Zconda_build.conda_interfacer   r   r	   r
   r   rf   r   Zconda_build.metadatar   Zconda_buildr   Zconda_build.skeletonsr   Zconda_build.buildr   Zconda_build.configr   r   r0   Zuser_optionsextendZboolean_optionsr)   r)   r)   r*   <module>   s*   R 2