
    xheA                        d Z ddlZddlZddlZddlZddlZddlZddlmZm	Z	 ddlm
Z
mZmZ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mZ ddlZddlZddlZdd	lmZ d
dl m!Z!m"Z"m#Z#m$Z$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/m0Z0 d
dl1m2Z2 d
dl3m4Z5 d
dl6m7Z7 d
dl8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z> d
dl?m@ZA dZBddgZCg dZDdZE eddg           edg           edg           edg          dZFdZGd ZHd! ZIdJd"ZJdKd%ZKdLd&ZLd' ZMd(dd)d)d*d$d)dd)d)d)ddg d)fd+ZNd, ZOd- ZPd. ZQd/ ZR ejS        d0          ZTd1 ZUd2 ZVd3 ZWd4 ZXd5 ZYd6 ZZd7 Z[d8 Z\dMd9Z]dNd:Z^d; Z_dJd<Z`d= ZadOd>Zbd? Zcd@ ZddA ZedB ZfdC ZgdD ZhdE ZidMdFZjdG ZkdH ZldI ZmdS )Pz6
Tools for converting PyPI packages to conda recipes.
    N)OrderedDictdefaultdict)chdirgetcwdlistdirmakedirs)abspathexistsisdirisfilejoin)copy2)mkdtemp)urljoinurlsplit)	parse_url   )	StringIOconfigparserdefault_pythondownloadhashsum_filehuman_bytesinputnormalized_versionspec_from_line)Config)
create_env)allowed_license_familiesguess_license_family)MetaData)FIELDS)apply_patch)check_call_envdecompressible_extsensure_liston_winrm_rftar_xf)_parsea7  
Examples:

Create a recipe for the sympy package:

    conda skeleton pypi sympy

Create a recipes for the flake8 package and all its dependencies:

    conda skeleton pypi --recursive flake8

Use the --pypi-url flag to point to a PyPI mirror url:

    conda skeleton pypi --pypi-url <mirror-url> package_name
hostrun)homelicenselicense_familylicense_filesummarydoc_urldev_urlzF{{% set name = "{packagename}" %}}
{{% set version = "{version}" %}}

)namez{{ name|lower }})versionz{{ version }})urlzI/packages/source/{{ name[0] }}/{{ name }}/{{ name }}-{{ version }}.tar.gz)numberr   )recipe-maintainers )packagesourcebuildextraa  diff core.py core.py
--- core.py
+++ core.py
@@ -166,5 +167,40 @@ def setup (**attrs):
 

+# ====== BEGIN CONDA SKELETON PYPI PATCH ======
+
+import distutils.core
+import io
+import os.path
+import sys
+import ruamel.yaml as yaml
+from ruamel.yaml import Loader, SafeLoader
+
+# Override the default string handling function to always return unicode
+# objects (taken from StackOverflow)
+def construct_yaml_str(self, node):
+    return self.construct_scalar(node)
+Loader.add_constructor(u'tag:yaml.org,2002:str', construct_yaml_str)
+SafeLoader.add_constructor(u'tag:yaml.org,2002:str', construct_yaml_str)
+
+def setup(*args, **kwargs):
+    data = {{}}
+    data['tests_require'] = kwargs.get('tests_require', [])
+    data['install_requires'] = kwargs.get('install_requires', [])
+    data['extras_require'] = kwargs.get('extras_require', {{}})
+    data['entry_points'] = kwargs.get('entry_points', [])
+    data['packages'] = kwargs.get('packages', [])
+    data['setuptools'] = 'setuptools' in sys.modules
+    data['summary'] = kwargs.get('description', None)
+    data['home'] = kwargs.get('url', None)
+    data['license'] = kwargs.get('license', None)
+    data['name'] = kwargs.get('name', '??PACKAGE-NAME-UNKNOWN??')
+    data['classifiers'] = kwargs.get('classifiers', None)
+    data['version'] = kwargs.get('version', '??PACKAGE-VERSION-UNKNOWN??')
+    with io.open(os.path.join("{}", "pkginfo.yaml"), 'w', encoding='utf-8') as fn:
+        fn.write(yaml.safe_dump(data, encoding=None))
+
+
+# ======= END CONDA SKELETON PYPI PATCH ======
 

 def run_setup (script_name, script_args=None, stop_after="run"):
     """Run a setup script in a somewhat controlled environment, and
z
    - c                      t           j                            dd                                                                          dv S )zGets whether the SSL_NO_VERIFY environment variable is set to 1 or True.

    This provides a workaround for users in some corporate environments where
    MITM style proxies make it difficult to fetch data over HTTPS.
    SSL_NO_VERIFYr9   )1true)osenvirongetstriplower     :lib/python3.11/site-packages/conda_build/skeletons/pypi.py_ssl_no_verifyrJ      s7     :>>/2..4466<<>>-OOrH   c                 r    |sd}t          j        |dz   | z   t                                 }|j        dk    S )Nzhttps://pypi.io/pypi/verifyi  )requestsrD   rJ   status_code)package_namepypi_urlrs      rI   package_existsrT      sB     *)X^l2~?O?O;OPPPA=CrH   r9   Tc                 8    d}|rd|z  }||z   | z   |z   |rdndz   S )Nr9    
rG   )lineprefixsuffixlevelnewlineoutputs         rI   __print_with_indentr^      s:    F uF?T!F*g.Edd2FFrH   c                    d}|s.t          t          |                                                     }|D ],}|| v r$| |         r|t          |d          z  }| |                                         D ]\  }}|t          |t                    st          |d          s-|t          |d||z   d          z  }|t          ||          z  }Zt          |d          r@|t          |t          t          |                                                              z  }|r5|t          |d||z   	          z  }|D ]}|t          |d
||z             z  }|dk    r|dz  }.|S )ak  Free function responsible to get the metadata which represents the
    recipe and convert it to the yaml format.

    :param OrderedDict recipe_metadata:
    :param list order: Order to be write each section
    :param int level:
    :param int indent: Indentation - Number of empty spaces for each level
    :return string: Recipe rendered with the metadata
    r9   :)rZ   N__iter__F)rZ   r[   r\   keys)rZ   r[   z- )rY   r[   r   rW   )
sortedlistrb   r^   items
isinstancestrhasattr_formating_value_print_dict)	recipe_metadataorderr[   indentrendered_recipesection_nameattribute_nameattribute_valueitems	            rI   rj   rj      s    O 5tO00223344 ( (?**|/L*2<LLLLO3B4egg / #*os33 7#Z< <  $':&s%&.RW( ( ( O $'7'X'XXOO_f55 #{'_5I5I5K5K0L0L)M)M( ( OO % #':&s%&.( ( ( O !0  '+> UV^, , ,  zz4'rH   c                     t          j        d          }t          |t                    r|                    |          s| dv rdt          |          z   dz   S dt          |          z   dz   S )zFormat the value of the yaml file. This function will quote the
    attribute value if needed.

    :param string attribute_name: Attribute name
    :param string attribute_value: Attribute value
    :return string: Value quoted if need
    z[@_!#$%^&*()<>?/\|}{~:])r1   descriptionr5   scriptz "z"
rV   rW   )recompilerf   rg   search)rp   rq   pattern_searchs      rI   ri   ri      sz     Z :;;N?C((3!!/223 LLLc/***U22_%%%,,rH   .Fhttps://pypi.io/pypi/c                    i }|sg }t          |t                    r|g}|st                      }|p|j                            dt
                    }g }| r|                                 }|                    |           d|v }|rd}n%t          |d	                    |df                    }|sEt          ||
                                          }t          |          r|st          d|z            |                    ||dddddd          }|r|d= |r	d	|d
<   i }nFt          j        |t                                 }|j        dk    rt#          j        d||j        fz             |                                }t)          |d                                         t,                    }|r ||           |r%||vrt#          j        d| d| d           ||d
<   n|st#          j        d|z             t/          |          dk    rMt1          d|z             |D ]}t1          |           t1          d|d         z             t1          d           |d         |d
<   t3          |||d
         ||||	          \  }|d<   |d<   |d<   d|d<   |                    dd          |d<   t5          ||||||
||||| |||           |d         d         |d <   |d         d         |d!<   |rId"D ]F}||         }d# t7          |          D             }|r!|                    |d         d$           |||<   G| |D ]}||         }|d         
                                }t;          t          ||                     t1          d%|
                                z             t=          t          ||d&          d'          5 } t?          j         dHi |}!tC                      }"tD          D ]4}#	 tF          |#         |"|#<   # tH          $ r tC                      |"|#<   Y 1w xY wd(|vrtK          d)          tM          |          }$d(	                    |$j'        |$j(        f          }$t          |$|"d*         d+                   |"d*         d+<   |d!         |"d*         d,<   |d-         r|d-         |"d.         d-<   |rd|"d.         d/<   d0g}%d1	                    |%|z             |"d.         d2<   tC                      |"d3<   t)          tS          dd4gtU          |d5                   z                       |"d3         d6<   t)          tS          dgtU          |d7                   z                       |"d3         d8<   |d         r|d         |"d9         d:<   |d;         r|d;         |"d9         d<<   |d=         r|d=         |"d9         d><   tC                      |"d?<   tV          D ]/}#	 ||#         |"d?         |#<   # tH          $ r d|"d?         |#<   Y ,w xY wd@g|"dA         dB<   |!tY          |"tD                    z  }!|!-                                 g }&|!.                                D ]`}'t_          j0        dC|'t^          j1        D          }(|(r&|'2                    dE          \  })}*}+dF|*z   }*|)|*z   |+z   }'|&                    |'           adG	                    |&          }!| 3                    |!           d d d            n# 1 swxY w Y   d S )INpythonr`   r9   rL   jsonzdirectory already exists: %s)packagenamerun_dependsbuild_dependsentry_pointstest_commandstests_requirer   UNKNOWNr5   rM      z*Request to fetch %s failed with status: %dreleases)keyzError: Version z of  is not available on PyPI.z0Error: Could not find any versions of package %s   z1Warning, the following versions were found for %szUsing %sz-Use --version to specify a different version.pypiurlfilenamedigestimport_testsr1   )configsetup_optionsr   	hash_type
hash_value)r   r   c                      g | ]\  }}d |v 	|S )numpyrG   ).0idxdeps      rI   
<listcomp>zskeletonize.<locals>.<listcomp>  s!    SSSXS#GsNNSNNNrH   z	numpy x.xzWriting recipe for %sz	meta.yamlwz://z3pypi_url must have protocol (e.g. http://) includedr;   r6   sha256r   r<   noarchz@{{ PYTHON }} -m pip install . -vv --no-deps --no-build-isolationrV   ru   requirementspipr   r+   r   r,   testimportsr   commandsr   requiresaboutzyour-github-id-herer=   r8   z^\s+(-) flags-z  rW   rG   )4rf   rg   r   variantrD   r   popappendr   r   rF   r
   RuntimeError
setdefaultrO   rJ   rP   sysexitr~   rc   rb   parse_versionlenprintget_download_dataget_package_metadata	enumerateinsertr   openPYPI_META_HEADERformatr   EXPECTED_SECTION_ORDERPYPI_META_STATICKeyError
ValueErrorr   schemenetlocsetrd   ABOUT_ORDERrj   rstrip
splitlinesrv   rx   	MULTILINE	partitionwrite),packages
output_dirr5   	recursiveall_urlsrR   nopromptversion_comparepython_version
manual_url
all_extrasnoarch_pythonr   r   extra_specs	pin_numpypackage_dictscreated_recipesr:   is_urlpackage_pypi_urldir_pathd	pypi_data	pypi_respversionsverdatadependsdeps	numpy_depr4   frn   ordered_reciper   base_urlrecipe_script_cmdrecipe_linesrX   matchpresepposts,                                               rI   skeletonizer      s   $ M -%% (& #Sv~'9'9(N'S'SNO
 p&,,..w''' 	N!&x7F:K1L1LMM 	NJ88Hh N N"#AH#LMMM$$&!!# "!#!# 

 

  	!-  %	,$AiLII %5.BRBR>RSSSI$++@')>?@  
 "((Ii
388::NNNH *))) ,(**HZ'ZZwZZZ    ')   HJWT   x==1$$MPWWXXX' # #c



*x|3444IJJJ'|)9Jw)fh*:
 :
6a	lAjM1X; . xx	2..)'	
 	
 	
 	
& 8Q+H+a.,
  	&; & &zSS4SSS	 & KK	!k:::!%AgJa  p&d ! Z% Z%'"%%''j$''(((%7888$z455s;; U	%q.5::::O(]]N- 8 88*:3*?N3'' 8 8 8*5--N3'''8 H$$ !VWWW))Hzz8?HO"DEEH.5.259/ /N8$U+ 23<N8$X.  L:;N:Kw'7 =4<w'1 S! 14!M11 1N7#H- .9]]N>*5;Xu%Q-?(@(@@AA6 6N>*62 5;XJa&6!7!77885 5N>*51   F45n4Ev&y1! H565Gv&z2! H565Gv&z2&1mmN7#" 6 6634S6N7+C00 6 6 635N7+C0006=R<SN7#$89 {>;QRRRO ""$$$ L'2244 * *	+t2<HHH ,%)^^C%8%8NCd*C9t+D##D))))"ii55OGGO$$$kU	% U	% U	% U	% U	% U	% U	% U	% U	% U	% U	% U	% U	% U	% U	%Z% Z%s\   )[#,O=<[#=P	[#P	F5[#W#"[##W;	8[#:W;	;C[##['	*['	c                 .   |                      ddt                    }|                    ddd           |                    dd	d
           |                    dd           |                    ddd           |                    ddd           |                    ddddd           |                    dddd            |                    d!dd"           |                    d#dd$           |                    d%d&t          d'g d()           |                    d*ddd+            |                    d,ddd-            |                    d.d/g d0            |                    d1dd2           |                    d3d/g d4            d5S )6z-Modify repos in place, adding the PyPI optionpypizl
    Create recipe skeleton for packages hosted on the Python Packaging Index
    (PyPI) (pypi.io).
        )helpepilogr   +zoPyPi packages to create recipe skeletons for.
                You can also specify package[extra,...] features.)nargsr   z--output-dirz5Directory to write recipes to (default: %(default)s).rz   )r   defaultz	--versionztVersion to use. Applies to all packages. If not specified the
              lastest visible version on PyPI is used.)r   z
--all-urls
store_truez`Look at all URLs, not just source URLs. Use this if it can't
                find the right URL.)actionr   z
--pypi-urlr{   z+URL to use for PyPI (default: %(default)s).)r   r   z--promptstore_falseTr   zhPrompt the user on ambiguous choices.  Default is to make the
        best possible choice and continue.)r   r   destr   z--all-extrasFz<Add all extra feature requirements. Applies to all packages.)r   r   r   z--recursivez=Create recipes for dependencies if they do not already exist.z--version-comparezVCompare the package version of the recipe with all available
        versions on PyPI.z--python-versionstorezAVersion of Python to use to run setup.py. Default is %(default)s.)	z2.7z3.5z3.6z3.7z3.8z3.9z3.10z3.11z3.12)r   r   r   choicesz--manual-urlziManually choose source url when more than one urls are present.Default is the one with least source size.z--noarch-pythonzCreates recipe as noarch pythonz--setup-optionsr   a,  Options to be added to setup.py install in the recipe. The same options are passed to setup.py install in both the construction of the recipe and in the recipe itself.For options that include a double-hypen or to pass multiple options, use the syntax --setup-options="--option1 --option-with-arg arg"z--pin-numpyzGEnsure that the generated recipe pins the version of numpyto CONDA_NPY.z--extra-specsz>Extra specs for the build environment to extract the skeleton.N)
add_parserpypi_exampleadd_argumentr   )reposr   s     rI   r   r     s       D 	E     	D    
 	:    
 	'     	':    
 	.     	K	     	L    
 	     	TRRR     	9     	.	     	<	  
 
 
 	     	M	      rH   c           
         |s| d         ni }|sd | d         |         D             n|g}|s|sd |D             }|s|                     d          rt          t          d|d         i          g}|d         d         st          j        d|z             t          |d         d                   }	|	j        st          j        d	| d
|	            |	j                            d          d         |d         d<   |	j        pd}
|
	                    d          }nt          j        d|z             t          |          dk    r|st          d|z             |rgt          |          D ]:\  }}t          d||d         t          |d                   |d         fz             ;t          t          d                    }nJt          d           t          d           t!          d t          |          D                       \  }}nd}|su||         }|d         }t          d                    |t          |d         pd          |                     |d         d         rd|d         d         f}nd}|d         pd}n`t          d|z             |}t          |          }	|	j        	                    d          }|	j                            dd          d         pd}||||fS ) av  
    Get at least one valid *source* download URL or fail.

    Returns
    -------

    data : dict
        Summary of package information
    pypiurl : str
        Download URL of package, which may or may not actually be from PyPI.
    filename : str
        Name of file; used to check cache
    digest : dict
        Key is type of checksum, value is the checksum.
    infoc                     g | ]}|S rG   rG   r   r6   s     rI   r   z%get_download_data.<locals>.<listcomp>v  s    :::CC:::rH   r   c                 *    g | ]}|d          dk    |S )packagetypesdistrG   r   s     rI   r   z%get_download_data.<locals>.<listcomp>z  s'    EEEs='9W'D'D'D'D'DrH   download_urlr6   r   zDError: Could not build recipe for %s. Could not find any valid urls.zError: Could not parse url for z: rL   r   r   r9   =z"Error: No source urls found for %sr   z1More than one source version is available for %s:z%d: %s (%s) %ssizecomment_textzwhich version should i use? z(Using the one with the least source sizez*use --manual-url to override this behaviorc              3   0   K   | ]\  }}|d          |fV  dS )r  NrG   )r   ir6   s      rI   	<genexpr>z$get_download_data.<locals>.<genexpr>  s/      HHHQFQ'HHHHHHrH   zUsing url {} ({}) for {}.digestsr   rG   r:   zUsing url %s)rD   r   rg   r   r   r   pathrsplitfragmentsplitr   r   r   r   intr   minr   )r   r:   r5   r   r   r   r   r   urlsUr  r   r  r6   n_r   r   s                     rI   r   r   `  s]   $ %+29VD CIW::9Z09::::wiD F( FEEtEEE E88N## 	EeT.-A%BCCDD75> 57>?   $q'%.))A6 KI7IIaIIJJJ"#&--"4"4R"8DGJz'RH^^C((FFH9GCDDD
4yy1}}X}AGKLLL 
	I#D//  3$#e*k#f+&>&>N@STU    E899::AA<===>???HH	$HHHHHDAqq :1ge*'..S[%5A66 	
 	
 	
 y>(# 	Ix 89FF
 Fz?/i 	nw&'''g!!#&&6==a((,9	'8V,,rH   c                    |sd S t           fd|D             }t          |                                           }t          |          st	          j        d|z             t          |          } |                                          }t          d|  d|            ||vrt	          j        d|  d| d           d S |d |	                    |                   }t          |          dk    r't          d	| z             |D ]}t          |           nt          d
| z             t	          j                     d S )Nc                 &    g | ]} |          S rG   rG   )r   r   nvs     rI   r   z#version_compare.<locals>.<listcomp>  s!    111RRWW111rH   zError: no such directory: %szLocal recipe for z has version zError: rV   r   r   z*Following new versions of %s are avaliablez"No new version for %s is available)r   r	   rF   r   r   r   r!   r5   r   indexr   )	r:   r   norm_versions
recipe_dirmlocal_versionnew_versionsr   r  s	           @rI   r   r     sn     		B1111111M))J >/*<===ABqyy{{OOM	
Cg
C
CM
C
CDDDH$$N7NN]NNNOOOOO   D-"5"5m"D"D DE|q  >'JKKK#  c



 6'BCCC




rH   c                 R   |                      d          d}t          fd|D                       r                                 t                    dz
  }t	          |                   dz   |<   d                    d d|dz            D                       }d|  d	| }|S )
zAConvert version into a pin-compatible format according to PEP440.rz   )r   r   c              3   ,   K   | ]}|d          v V  dS )r   NrG   )r   rZ   version_partss     rI   r  z"convert_version.<locals>.<genexpr>  s-      
>
>66]2&&
>
>
>
>
>
>rH   r   r   c              3   4   K   | ]}t          |          V  d S N)rg   )r   vs     rI   r  z"convert_version.<locals>.<genexpr>  s(      HH!s1vvHHHHHHrH   N >=z,<)r  anyr   r   r  r   )r5   suffixesmax_ver_lenmax_pinpin_compatibler  s        @rI   convert_versionr(    s    MM#&&MH

>
>
>
>X
>
>
>>> m$$q(K!$];%?!@!@1!DM+hhHH}5F{Q5F'GHHHHHG/7//g//NrH   z(?P<name>^[^=<>!~\s;]+)\s*(?P<constraint>[=!><~]=?\s*[^\s;]+)?(?:\s*;\s+)?(?P<env_mark_name>[^=<>!~\s;]+)?\s*(?P<env_mark_constraint>[=<>!\s]+[^=<>!~\s]+)?c                     |                                  \  }}|                    d                              d                                          }||fS )N'")r  rE   )
constraintoperatorvalues      rI   "_get_env_marker_operator_and_valuer/    sL     &&((OHeKK""3''--//EU?rH   c                    | }t          |                                           dk    rYt          |           \  }}d                    |                    d          d d                   }d                    ||f          }d| S )Nr   r9   rz   rV   zpy )r   r  r/  r   )r,  translationr-  r.  s       rI   _translate_python_constraintr2    s    K
:!##<ZHH%C((!,--hh%011rH   c                     t          |           \  }}dddd                    ||                                          }d                    |dk    rdnd|          S )	Nlinuxosxwin)LinuxDarwinWindows{}{}!=not r9   )r/  rD   rF   r   r,  r-  r.  systems       rI   %_translate_platform_system_constraintr?    sh    8DDOHe  
c%	 
 ==8t#3#3VDDDrH   c                     t          |           \  }}t          j        d|t          j                  d         }d                    |dk    rdnd|          S )Nz^[a-z]*r   r:  r;  r<  r9   )r/  rv   r   Ir   r=  s       rI   "_translate_sys_platform_constraintrB    sO    8DDOHeXi--a0F==8t#3#3VDDDrH   c                 ^    t           t          t          d} ||          |          }d|z   dz   S )zyreturns translated variable name and corresponding function to run to normalize the
    version constraint to conda style)r   platform_systemsys_platformz  # [ z ])r2  r?  rB  )env_mark_nameenv_mark_constraintenv_mark_tablemarkers       rI   env_mark_lookuprJ    s@     7@: N
 +^M*+>??Fft##rH   c                    t                               |           }|                    d          }|                    d          r>d                    ||                    d                              dd          f          }d}|                    d          r6t          |                    d          |                    d                    }||fS )Nr4   r,  rV   r9   rF  rG  )	MARKER_REr   groupr   replacerJ  )dep_strr   r4   env_marks       rI   parse_dep_with_env_markerrQ     s    OOG$$E;;vD{{<   Lxxu{{<88@@bIIJKKH{{?## 
"KK((%++6K*L*L
 
 >rH   c           
         t          d| z             t          d|d                    t          | |d         |d         |d         ||||          }|                    t          |                     t	          | ||          }|st          |          rAt          |t          |                    }dg|z   |d	<   ||d
<   |r|
t          |||          z  }
d|vr|d                                         |d<   |d         dk    r|d         |d<   t          ||
                    d                    |d<   t          |          |d<   t          ||          |d<   |
                    d          st          |          |d<   t          | ||	|          }t          |          |d<   t!          |t"                    |d<   d|v r|d         |d<   d S d S )NzDownloading %sz
PyPI URL: r   r   r   )r   r   r   r   r   r   r   )r   r   r   r   r   r4   r5   r   r   r   r-   r1   r.   r/   new_hash_value)r   get_pkginfoupdateget_entry_pointsget_requirementsis_setuptools_enabledget_dependenciesget_recursive_depsrF   get_import_testsrD   get_tests_requireget_homeget_summaryget_license_nameclean_license_namer    r   )r:   metadatar   r   r   r   r   r   r   	no_promptr   r   r   r   pkginfor   	list_depslicense_names                     rI   r   r   -  s!     

W
$%%%	,+,,,*%#!%#	 	 	G OO$W--...ZHHHH S(11 S$X/DW/M/MNN	%*Gi$7!"+ 	S*?IzRRRHH$$")&/"7"7"9"9	i''%i0/n9U9UVVH^ 1' : :H_..HV<<	"" 3)'22#GWiFFL,\::HY!5." "H 7""$%56 #"rH   c                     g }|D ]S}|                                 d         }t          t          ||                    s|| v r>|                    |           T|S )zFunction responsible to return the list of dependencies of the other
    projects which were requested.

    :param list created_recipes:
    :param list list_deps:
    :param output_dir:
    :return list:
    r   )r  r
   r   r   )r   rd  r   recursive_depsr   s        rI   rZ  rZ  p  sm     N # #iikk!n$z3''(( 	C?,B,Bc""""rH   c                 N  
 d 

fd}|rdgng }| D ]}t          |t                    r|                                }|D ]}|                    d          d                                         }|s2|}t          |          \  }}t          |          }d|v rd}|Vd|v r9t          j        t                    }	|	
                    d            ||          }|t          j        d	|z             |rd
                    ||f          }|                    |           |S )zReturn the whole dependencies of the specified package
    :param list requires: List of requirements
    :param Bool setuptools_enabled: True if setuptools is enabled and False otherwise
    :return list: Return list of dependencies
    c                 \    |                      d          d                                         S )N#r   )r  r   )rX   s    rI   _strip_commentz(get_dependencies.<locals>._strip_comment  s#    zz#q!((***rH   c                    t          j        dt           j                  }|                     |                     }|d S |                    d                                          |                    d          |                    d          }}}|r||                    dd          z   S |r|                    d          r|                    d          d	k    sJ d
|              |                    d          sJ d|              |                    dd          }d	                    |
                    d          d d                   dz   }|dz   |z   dz   |z   S |dz   |                    dd          z   S |S )Na  
            (?P<name>[^=<>!\s]+)  # package name
            \s*  # ignore spaces
            (
                (?P<cc>=[^=]+(=[^=]+)?)  # conda constraint
                |
                (?P<pc>(?:[=!]=|[><]=?|~=).+)  # new pip-style constraints
            )?$
            r4   ccpcr  rV   z~= ~=r   z5Overly complex 'Compatible release' spec not handled rz   z'No '.' in 'Compatible release' version r9   r   z.*r"  z,==)rv   rw   VERBOSEr   rM  rF   rN  
startswithcountr   r  )	rX   spec_patr  r4   rm  rn  r   ver2rk  s	           rI   _spec_from_linez)get_dependencies.<locals>._spec_from_line  s   : J
 
 NN>>$//0094--//"b 	"**S#.... 	}}U## 	8HHTNNa'''Q4QQ (''xx}}VV&VPT&V&VVVVjj++xx		#ss 344t;e|c)E1D88czBJJsB$7$777KrH   
setuptoolsrj  r   ro  Nz]Your conda is too old to handle ~= PEP440 'Compatible versions', using copied implementation.zError: Could not parse: %srV   )rf   rg   r   r  rE   rQ  r   logging	getLogger__name__warningr   r   r   r   )r   setuptools_enabledru  rd  dep_textr   dep_origrI  speclogrk  s             @rI   rY  rY    s   + + +    F #5<"I (# (#h$$ 	-**,,H  #	# #	#C))C..#))++C H3H==KC "#&&Dx|8##!+H55CKK7   +?844D<H9C?@@@ 0xxv//T""""G#	#H rH   c                      | j         d          s|S g }|dk    rd |                                D             }t          t          |          t          | d                   z            S )zReturn the section import in tests

    :param dict pkginfo: Package information
    :param dict import_tests_metada: Imports already present
    :return list: Sorted list with the libraries necessary for the test phase
    r   PLACEHOLDERc                     g | ]
}|d k    |S )r   rG   r   xs     rI   r   z$get_import_tests.<locals>.<listcomp>  s    FFFQ#XX1XXXrH   )rD   r  rc   r   )rc  import_tests_metadaolddepss      rI   r[  r[    st     7;z"" #""Gm++FF17799FFF#g,,WZ%8!9!99:::rH   c                 Z    t          d t          | d                   D                       S )Nc              3   4   K   | ]}t          |          V  d S r   )r   )r   pkgs     rI   r  z$get_tests_require.<locals>.<genexpr>  s*      WW#.%%WWWWWWrH   r   )rc   r&   rc  s    rI   r\  r\    s,    WWW_=U1V1VWWWWWWrH   c                 j    d} | j         d          r| d         S |r|                     d|          S |S )NzThe package home pager-   rD   )rc  r   default_homes      rI   r]  r]    sG    *Lw{6 v .xx---rH   c                 L     | j         dd                              dd          S )Nr1   zSummary of the packager+  z\")rD   rN  r  s    rI   r^  r^    s'    7;y":;;CCCOOOrH   c                    d|r|                     dg           ng } |j         d|          }|r|n|}fd|D             }|rd                    |          S  |j         d          r	|d         }n|rd|v r	|d         }nd}|rh|r|S d|vrt          d|z             ndt          d	| z             t                       t          |           t                       t          d
          }n|rd}nt          d| z            }|S )zResponsible to return the license name
    :param str package: Package's name
    :param dict pkginfo:Package information
    :param no_prompt: If Prompt is not enabled
    :param dict data: Data
    :return str: License name
    zLicense :: OSI Approved :: classifiersc                 r    g | ]3}|                               |                    d           d          4S )r   )rq  r  )r   
classifierlicense_classifiers     rI   r   z$get_license_name.<locals>.<listcomp>  sT         !344+Q//2  rH   z or r.   NrW   zUsing "%s" for the licensezThis is the license for %sz"What license string should I use? r   zVNo license could be found for %s on PyPI or in the source. What license should I use? )rD   r   r   r   )	r:   rc  rb  r   data_classifierpkg_classifierlicensesre  r  s	           @rI   r_  r_    s    759Adhh}b111rO W[@@N'5J^^?N   (  H  %{{8$$$w{9 y)	 )t##I 
 
	G%%.=>>>> .8999GGG,GGG !EFFLL	 
 *,34
 
 rH   c                 R    t          j        dd| t           j                  d         S )zRemove the word ``license`` from the license
    :param str license_name: Receives the license name
    :return str: Return a string without the word ``license``
    z(.*)\s+licensez\1r   r   )rv   subn
IGNORECASE)re  s    rI   r`  r`  5  s&    
 7$e\OOOPQRRrH   c                 D    | j         d          }|si S t          |t                    rd                    d |                                D                       }t          j                    	                     t          |                     i }	                                D ]+dv r%fd
                              D             |<   ,n7# t          $ r*}t          d|           t          d|           Y d}~nd}~ww xY wt          |t                    r`t          |                     d	g                     }t          |                     d
g                     }||z   }|r|t          |          dS nt          d           t          |           i S )zLook at the entry_points and construct console_script and gui_scripts entry_points for conda
    :param pkginfo:
    :return dict:
    r   rW   c              3   >   K   | ]}|                                 V  d S r   )rE   r  s     rI   r  z#get_entry_points.<locals>.<genexpr>H  s*      HH17799HHHHHHrH   )console_scriptsgui_scriptsc                 F    g | ]}| d                      |           S )r  r  )r   option_configsections     rI   r   z$get_entry_points.<locals>.<listcomp>T  sE     - - -" "BBGKK$@$@BB- - -rH   z&WARNING: entry-points not understood: zThe string wasNr  r  )r   r   z/WARNING: Could not add entry points. They were:)rD   rf   rg   r   r   r   ConfigParser	read_filer   sectionsoptions	Exceptionr   dictconvert_to_flat_listmake_entry_tests)	rc  r   newstrerrconsole_scriptr  
entry_listr  r  s	          @@rI   rV  rV  =  s   
 7;~..L 	,$$ HHl.E.E.G.GHHHHH+--	hv..///
 L"++--  @@@- - - - -&-oog&>&>- - -L)  	, 	, 	,:C@@@"F++++++++	, ,%% -l.>.>?PRT.U.UVV*<+;+;M2+N+NOO $k1
 	 *!1*!=!=  	 	?@@@lIs   1"C 
D
  DD
c                     t          | t                    r| g} nH| rFt          | t                    r1t          | d         t                    rd d | D             D             } | S )zConvert a string to a list.
    If the first element of the list is a nested list this function will
    convert it to a flat list.

    :param str/list var_scripts: Receives a string or a list to be converted
    :return list: Return a flat list
    r   c                     g | ]	}|D ]}|
S rG   rG   )r   sublistrr   s      rI   r   z(convert_to_flat_list.<locals>.<listcomp>y  s&    XXXPWXXtXXXXrH   c                     g | ]}|S rG   rG   )r   ss     rI   r   z(convert_to_flat_list.<locals>.<listcomp>y  s    +C+C+C!A+C+C+CrH   )rf   rg   rd   )var_scriptss    rI   r  r  j  s     +s## Y"mY{D))Y {1~t,,Y
 YX+C+C{+C+C+CXXXrH   c                      | j         d          }t          |t                    sdS t          |                                          ddhz
  rdS dS )zFunction responsible to inspect if skeleton requires setuptools
    :param dict pkginfo: Dict which holds the package information
    :return Bool: Return True if it is enabled or False otherwise
    r   Fr  r  T)rD   rf   r  r   rb   )rc  r   s     rI   rX  rX  }  s_    
 7;~..LlD)) u <#4m"DD t5rH   c                 \    t          j        d|           rt          j        |           s| S dS )Nz[_A-Za-z][_a-zA-Z0-9]*$r9   )rv   r   keyword	iskeyword)r4   s    rI   validr    s3    	x)400 9J49P9P rrH   c                     |                                                      t                    rt          | |           d S t	          d| z            )Nznot a valid source: %s)rF   endswithr%   r)   r  )src_pathtempdirs     rI   unpackr    sM    ~~  !455 =x!!!!!08;<<<rH   c                       fdt                     D             }t          |          dk    r't           |d                   }t          |          r|S |s S t	          d          )Nc                 x    g | ]6}|                     d           t          t          |                    4|7S )rz   )rq  r   r   )r   fnr  s     rI   r   zget_dir.<locals>.<listcomp>  sW       }}S!! ',D",=,=&>&>
  rH   r   r   z"could not find unpacked source dir)r   r   r   r   r  )r  lstr   s   `  rI   get_dirr    s       '""  C
 3xx1}}Q((?? 	O 
8
9
99rH   c                    t          j        d|           }|r-|                                \  } }|                    d          }ng }|r)t	          d                                                   }n	 fd|D             }n:# t          $ r- t          j        dd	                    |          z             Y nw xY wt          j
        d          }d         D ]}|                    |          }|r |                                \  }	}
	 t          d |
                    d                              d	          D                       }|	d
k    rt          j        |k     }nl|	dk    rt          j        |k    }nU|	dk    rt          j        |k    }n>|	dk    rt          j        |k    }n'|	dk    rt          j        |k    }nt          j        |k    }|r|d         |         z  }
# t          $ r Y w xY wg } j        dd          g|z   D ]B}t!          |t"                    r|                    |           -|                    |           C|S )Nz^([^[]+)\[([^]]+)\]$,extras_requirec                 ,    g | ]}d          |         S )r  rG   )r   r  rc  s     rI   r   z$get_requirements.<locals>.<listcomp>  s$    KKKqg&67:KKKrH   z#Error: Invalid extra features: [%s]z&^:python_version(<|<=|!=|==|>=|>)(.+)$c              3   4   K   | ]}t          |          V  d S r   )r  r  s     rI   r  z#get_requirements.<locals>.<genexpr>  s(      %R%Rc!ff%R%R%R%R%R%RrH   z'"rz   <z<=r;  z==z>=install_requiresr9   )rv   r   groupsr  rd   valuesr   r   r   r   rw   tuplerE   version_infor   rD   rf   rg   r   extend)r:   rc  r   match_extrasextrasr  version_markerr=   match_ver_markopr   	ver_tuplesatisfies_verr   specss    `             rI   rW  rW    s   83W==L &--//c""  !Kg&67>>@@AA	OKKKKFKKKNN 	O 	O 	OH:SXXf=M=MMNNNNN	O
 $MNN-. 	K 	KE+11%88N K(//11CK %%R%Rcii6F6F6L6LS6Q6Q%R%R%R R RI Syy(+(89(Dt(+(8I(Et(+(8I(Et(+(8I(Et(+(8I(E(+(89(D$ K&'2B*CE*JJ! "   D	K. H'+0"556G # #eS!! 	#OOE""""OOE""""Os$   4B 4B:9B:?G##
G10G1c           	      R   t          d|z             }t          |j                  st          |j                   |d         }	|d         }
	 t	          |j        |          }t          |          rt          ||	          |
k    rQt          |t	          |j        |                     t          ||	          |
k    rt          d|  d|	 d|
 d          nt          d           |	d	k    rt          |d	          }nd
}t          d| z             t          t	          |j        |          |           t          d           t          d|z             t          |          }t          ||||||           	 t          t	          |d                    5 }t          j        |          }d d d            n# 1 swxY w Y   n8# t           $ r+ t          d           t#          j        |          j        }Y nw xY w|rd	|f|d<   t)          |           n# t)          |           w xY w|S )Nconda_skeleton_r   r   z Download of z failed checksum type z expected value z. Please try again.zUsing cached downloadr   r9   zUnpacking %s...donezworking in %s)r   r   r   zpkginfo.yamlzHWARNING: the pkginfo.yaml file was absent, falling back to pkginfo.SDistrS  )r   r   	src_cacher   r   r   r   r   r   r   r  r  run_setuppyr   yaml	safe_loadOSErrorrc  SDist__dict__r(   )r:   r   r   r   r   r   r   r   r  r   r   download_pathrS  src_dirr  pkg_infos                   rI   rT  rT    s     '(233G!"" #!"""q	IJ2 V-x88}%%	+M955CCWd6#3X>>???M955CC""G " "&/" "AK" " "   D )***   )-BBNNN')***tF$h//999fo'((('""#'	
 	
 	
 	
	=d7N3344 .>"--. . . . . . . . . . . . . . . 	= 	= 	=Z   }]33<HHH		=
  	D*2N)CH%&ggOsU   D+H 8G F6*G 6F::G =F:>G H 2G74H 6G77H H$c           
      p   |j         }d| ddddg|j                             d          rddgnd	gz   }t          t          j                            | d
                    5 }|                                }	d|	v sd|	v r|                    d           ddd           n# 1 swxY w Y   |                    |           t          |j
                   t          |j
        |d|d|           t          |j
        t          rdnd|z            }
t          |d          }t          |d          5 }|                    t                              |                    dd                                        d                     ddd           n# 1 swxY w Y   t          |
d          }t%          |          r-t'          t          |d                    rt          t          |d                     t)          t          |d          t          |d                     t          t          |ddt*          j        d          t*          j        d          d                      t          t          |ddt*          j        d          t*          j        d          d!                     n,t)          t          |d          t          |d                     t/          |||"           t          |
d#dd$          }t%          |          rt/          |||"           t          j                                        }d%|v rt5          | d&z   |d%         z             |d%<   nt5          |           |d%<   t7                      }t9          |            |j        d
d'g}|                    |           	 t=          ||(           nW# t>          j         $ rE tC          d)|d%         z             t+          j"        d*d+                    |          z             Y nw xY wt9          |           dS # t9          |           w xY w),z
    Patch distutils and then run setup.py in a subprocess.

    :param src_dir: Directory containing the source code
    :type src_dir: str
    :param temp_dir: Temporary directory for doing for storing pkginfo.yaml
    :type temp_dir: str
    zpython *r   zruamel.yamlrv  r6  zm2-patchzm2-gcc-libspatchzsetup.pyzimport numpyz
from numpyr   Nr+   F)specs_or_actionsenvsubdirclear_cacher   Libzlib/python%szpypi-distutils.patchwb\z\\zutf-8	distutilszcore.py-copyzcore.py__pycache__zcore.cpython-r   r   z.pycz.pyo)r   zsite-packages
_distutils
PYTHONPATHr`   install)r  z$PYTHONPATH = %szError: command failed: %srV   )#host_subdirrq  r   rB   r	  r   readr   r  r(   host_prefixr   r'   r   DISTUTILS_PATCHr   rN  encoder   r
   r   r   r  r#   rC   copyrg   r   r   host_pythonr$   
subprocessCalledProcessErrorr   r   )r  temp_dirr   r   r   r   r  r  setuptext
stdlib_dirr  r   r  rv  r  cwdcmdargss                     rI   r  r  0  s    F#.###	 ((//	]##Y	E 
bgll7J//	0	0 "Ezz||T!!\T%9%9LL!!!" " " " " " " " " " " " " " "
 
LL	&
    <^n< J
 122E	eT		 Xa	&&x'7'7f'E'EFFMMgVVWWWX X X X X X X X X X X X X X X Z--IY 5$y.1122 	$y),,---Y//Y	**  
 !RC$4Q$7R9I!9LRRR    !RC$4Q$7R9I!9LRRR     Y	**Y//   	IuV4444j/<NNJZ 6Jf5555 *//

Cs#L0A ABBLLLL
((C	'NNN!:y9GNN=!!!wC(((((( B B B 3|#44555,sxx/@/@@AAAAAB 	c




c



sP   !2BB#&B#.AFFF*N< ;P$ <APP$ PP$ $P5c                     g }| D ]G}|                     d          d                                         }|                    |dz              H|S )Nr  r   z --help)r   rE   r   )r  testsentry_pointentrys       rI   r  r    sY    E! ( (%%c**1-3355UY&''''LrH   r   )r9   r9   r   T)Nr   r   )T)r9   )FN)n__doc__r  rw  rB   rv   r  r   collectionsr   r   r   r   r   r   os.pathr	   r
   r   r   r   shutilr   tempfiler   urllib.parser   r   rc  rO   r  "requests.packages.urllib3.util.urlr   conda_interfacer   r   r   r   r   r   r   r   r   r   r   rC   r   r/   r   r    ra  r!   renderr"   r   r;   r#   utilsr$   r%   r&   r'   r(   r)   r5   r*   r   r   REQUIREMENTS_ORDERr   r   r   r  INDENTrJ   rT   r^   rj   ri   r   r   r   r   r(  rw   rL  r/  r2  r?  rB  rJ  rQ  r   rZ  rY  r[  r\  r]  r^  r_  r`  rV  r  rX  r  r  r  rW  rT  r  r  rG   rH   rI   <module>r     s      				 				     



 0 0 0 0 0 0 0 0 / / / / / / / / / / / / 8 8 8 8 8 8 8 8 8 8 8 8 8 8             * * * * * * * *    8 8 8 8 8 8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
                   K K K K K K K K       5 5 5 5 5 5                            . - - - - -$ e_     {((	
  k	
  [	
 
 [4566)  2,\ 
P P P       G G G G- - - -`- - -( $!l% l% l% l%^o o odY- Y- Y-x  <   BJ6 	    E E EE E E$ $ $
 
 
@7 @7 @7F  &Z Z Z Zz; ; ; ; X X X   P P P1 1 1 1hS S S* * *Z  &     = = =: : :5 5 5 5pK K K\a a aH    rH   