B
    ZMO\1                 @   s  d Z ddlmZmZm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$%e&dde&dfe&dddfg e#j'%e&dg dS )z
bdist_conda

    )print_functiondivisionunicode_literalsN)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 )	CondaDistributionaQ	  
    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.

    - conda_features: List of features for the package. See the features
      section of the conda build documentation for more information about
      features in conda.

    - conda_track_features: List of features that this package should track
      (enable when installed).  See the features section of the conda build
      documentation for more information about features in conda.

    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          	      s|   i }|r.x$| j D ]}||kr||||< qW ts@t| | nt | x*| j D ] }t| j|||| j |  qTW d S )N)	conda_attrspopr   r	   __init__supersetattrmetadataget)selfZattrsZgiven_attrsattr)	__class__ .lib/python3.7/distutils/command/bdist_conda.pyr    d   s    zCondaDistribution.__init__)N)__name__
__module____qualname____doc__r   r    __classcell__r(   r(   )r'   r)   r      s   5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)   r0   |   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 allowedr/   prefix)
distributionZget_option_dictr3   r   configZhost_prefixr   r   finalize_optionsr!   )r%   Zopt_dict)r'   r(   r)   r6      s    zbdist_conda.finalize_optionsc          
      s  j j}x*tjD ] }t||st||tj|  qW jd k	rF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r0dd j jp"g D |d d< |j|d d< |j|d d< |j|d d< tj dg }|r,t|tr8ddd | D }t  i }y t| W n< t k
r } zt!dt"| d | W d d }~X Y nLX xH # D ]<dkr* fd d $D }||< nd |< qW t|t	sRt!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(kr,t+t,t-t./||d d+< d&|d d krJd(|d d< |j0r|j0d(krj j1pjg j j2pvg  |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>   s    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(   r)   r>      s    testrequiresZabouthomelicenseZsummaryentry_points
c             s   s   | ]}|  V  qd S )N)strip)r<   xr(   r(   r)   	<genexpr>   s    z"bdist_conda.run.<locals>.<genexpr>z$ERROR: entry-points not understood: z
The string was)console_scriptsgui_scriptsc                s    g | ]}d |  |f qS )z%s=%s)r$   )r<   Zoption)csectionr(   r)   r>      s   z.ERROR: Could not add entry points. They were:
ZscriptsrJ   rK      Z
setuptoolsZosxTZ
osx_is_appr   ZcommandsZimports)r5   F.)Z
build_onlynotest)ZpostrP   c                   s   e Zd Z jZdS )zbdist_conda.run.<locals>.argsN)r*   r+   r,   r2   r(   )r%   r(   r)   args  s   rQ   z[# If you want to upload this package to anaconda.org later, type:
#
# $ anaconda upload %s
)Ir4   r#   r   r   hasattrr"   r1   r   r   dictr8   lowerr9   r   r   r   r   r   rB   getattrr@   ZurlrD   description
isinstancer   join
splitlinesr   ZConfigParserZreadfpr
   	Exceptionr   strZsectionsZoptionsr$   lenappendr5   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   r?   r!   rA   Zcleanr2   r   print)r%   r#   r&   drE   ZnewstrerrvalueZrsZcsZgsZ
entry_listmoutputrQ   Zno_upload_message)r'   )rL   rM   r%   r)   r?      s    

$
(


 

zbdist_conda.run)r*   r+   r,   rV   r   r[   inttimer5   r0   r6   r?   r.   r(   r(   )r'   r)   r/   w   s   	r/   z	buildnum=zThe 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().zanaconda-uploadz+Upload the finished package to anaconda.org)(r-   Z
__future__r   r   r   rc   rn   collectionsr   Zdistutils.command.installr   Zdistutils.errorsr   r   Zdistutils.distr	   Zconda_build.conda_interfacer
   r   r   r   r   ra   r   Zconda_build.metadatar   Zconda_buildr   Zconda_build.skeletonsr   Zconda_build.buildr   Zconda_build.configr   r   r/   Zuser_optionsextendr[   Zboolean_optionsr(   r(   r(   r)   <module>   s,   Z 2
