
@K7]c           @` s  d  Z  d d l m Z m Z m Z d d l m Z m Z d d l Z d d l	 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 Z d d l m Z d d l Z d d l Z d d	 l m Z d d l Z d d l Z d d
 l m  Z  d d l! m" Z" m# Z# d d l$ 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. m/ Z/ d d l% m0 Z0 d d l1 m2 Z2 m3 Z3 m4 Z4 m5 Z5 m6 Z6 d d l7 m8 Z8 d d l9 m: Z: d d l; m< Z< d d l= m> Z> d d l? m@ Z@ mA ZA d d lB mC ZD d ZE d d g ZF d d d d d  d! d" g ZG d# ZH i e dN dO g  d( 6e dP g  d+ 6e dQ g  d- 6e dR g  d0 6ZI d1 ZJ d2 ZK d3   ZL d d4  ZN d/ d/ d eO d5  ZP d d d6 d7  ZQ d8 d eR eR d9 eO eR d eR eR eR d d g  eR d:  ZS d;   ZT d<   ZU d=   ZV d>   ZW e jX d?  ZY d@   ZZ dA   Z[ dB   Z\ dC   Z] dD   Z^ dE   Z_ dF   Z` dG   Za dH   Zb dI   Zc eO dJ  Zd dK   Ze dL   Zf dM   Zg d S(S   s6   
Tools for converting PyPI packages to conda recipes.
i    (   t   absolute_importt   divisiont   print_function(   t   defaultdictt   OrderedDictN(   t   makedirst   listdirt   getcwdt   chdir(   t   joint   isdirt   existst   isfilet   abspath(   t   parse_version(   t   copy2(   t   mkdtemp(   t	   parse_url(   t   urljoint   urlsplit(   t   spec_from_line(   t   inputt   configparsert   StringIOt   string_typest   PY3(   t   download(   t   normalized_version(   t   human_bytest   hashsum_file(   t   default_python(   t   decompressible_extst   tar_xft   rm_rft   check_call_envt   ensure_list(   t   apply_patch(   t
   create_env(   t   Config(   t   MetaData(   t   allowed_license_familiest   guess_license_family(   t   FIELDSs7  
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
t   hostt   runt   homet   licenset   license_familyt   license_filet   summaryt   doc_urlt   dev_urlsF   {{% set name = "{packagename}" %}}
{{% set version = "{version}" %}}

t   names   {{ name|lower }}t   versions   {{ version }}t   packaget   urlsI   /packages/source/{{ name[0] }}/{{ name }}/{{ name }}-{{ version }}.tar.gzt   sourcet   numbert   builds   recipe-maintainerst    t   extras  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 yaml
+from 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
s   
    - c           C` s%   t  j j d d  j   j   d k S(   s   Gets 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.
    t   SSL_NO_VERIFYR;   t   1t   true(   R>   R?   (   t   ost   environt   gett   stript   lower(    (    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyt   _ssl_no_verify   s    c         C` s=   | s d } n  t  j | d |  d t   } | j d k S(   Ns   https://pypi.io/pypit   /t   verifyi  (   t   requestsRB   RE   t   status_code(   t   package_namet   pypi_urlt   r(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyt   package_exists   s    	!c         C` s9   d } | r d | } n  | | |  | | r4 d n d S(   NR;   t    s   
(    (   t   linet   prefixt   suffixt   levelt   newlinet   output(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyt   __print_with_indent   s    i   c   	      C` s  d } | s' t  t |  j     } n  x| D]} | |  k r. |  | r. | t | d d 7} xE|  | j   D]3\ } } | d  k r qq n  t | t  s t | d  r| t | d d d | | d t	 7} t | t  r | d | d 7} q| d	 t
 |  d
 7} qq t | d  rJ| t | t  t | j      7} qq | rq | t | d d d | | 7} x1 | D]& } | t | d d d | | 7} qwWqq qq W| d k r| d
 7} qq. q. W| S(   NR;   RQ   t   :t   __iter__RR   RS   s    "s   "
RN   s   
t   keysRP   s   - i    (   t   sortedt   listRX   RU   t   itemst   Nonet
   isinstanceR   t   hasattrt   Falset   strt   _print_dict(	   t   dt   orderRR   t   indentt   rendered_recipet   kt   _kt   _vt   item(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyRa      s2    
( t   .s   https://pypi.io/pypi/c   .      C` s[  i  } | s g  } n  t  | t  r0 | g } n  | sB t   } n  | pZ | j j d t  } g  } xz|  r|  j   } | j |  d | k } | r d } n t | d j	 | d f   } | st	 | | j
    } t |  r| rt d |   qn  | j | i | d 6d d 6d d	 6d d
 6d d 6d d 6 } | rN| d =n  | rgd | d <i  } n>d   } t j | d t   } | j d k rt j d | | j f  n  | j   } | | d j    } | r| |  n  | r#| | k rt j d | | f  n  | | d <n | s=t j d |  n  t |  d k rt d |  x | D] } t |  qdWt d | d  t d  n  | d | d <t | | | d | | | |	  \ } | d <| d <| d <d | d <| j d d  | d <t | | | | | |
 | | | | |  | d  | d! | | d d" | d# <| d d | d$ <| rf xy d	 d g D]h } | | } g  t |  D] \ } }  d% |  k r| ^ q}! |! rm| j |! d" d&  | | | <qmqmWqf qf Wxt| D]l} | | } | d j
   }" t t	 | |"   t d' | j
    t t	 | |" d(  d)  }# t j |   }$ t   }% xA t  D]9 }& y t! |& |% |& <Wqkt" k
 rt   |% |& <qkXqkWd* | k rt# d+   n  t$ |  }' d* j	 |' j% |' j& f  }' t |' |% d, d-  |% d, d- <| d$ |% d, d. <| d
 r:| d
 |% d/ d
 <n  | rQd |% d/ d0 <n  d1 d2 j	 |  |% d/ d3 <t   |% d4 <t' t( d d5 g t) | d	    |% d4 d6 <t' t( d g t) | d    |% d4 d7 <| d r| d |% d8 d9 <n  | d r| d |% d8 d: <n  | d r/| d |% d8 d; <n  t   |% d< <xF t* D]> }& y | |& |% d< |& <WqCt" k
 rd |% d< |& <qCXqCWd= g |% d> d? <|$ t+ |% t   7}$ |$ j,   g  }( xu |$ j-   D]g }) t. j/ d@ |) dA t. j0 }* |* r |) j1 dB  \ }+ }, }- dC |, }, |+ |, |- }) n  |( j |)  qWdD j	 |(  }$ |# j2 |$  Wd  QXqWd  S(E   Nt   pythonRV   R;   RF   t   jsons   directory already exists: %st   packagenamet   run_dependst   build_dependst   entry_pointst   test_commandst   tests_requiret   UNKNOWNR5   c         S` s   t  |  d t S(   Nt   key(   RY   R   (   t   l(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyt   <lambda>   R;   RG   i   s*   Request to fetch %s failed with status: %dt   releasess1   Error: Version %s of %s is not available on PyPI.s0   Error: Could not find any versions of package %si   s1   Warning, the following versions were found for %ss   Using %sis-   Use --version to specify a different version.t   pypiurlt   filenamet   digestt   import_testsR1   t   configt   setup_optionsi    t	   hash_typet
   hash_valuet   numpys	   numpy x.xs   Writing recipe for %ss	   meta.yamlt   ws   ://s3   pypi_url must have protocol (e.g. http://) includedR8   R7   t   sha256R:   t   noarchs?   {{ PYTHON }} -m pip install . --no-deps --ignore-installed -vv RN   t   scriptt   requirementst   pipR+   R,   t   testt   importst   commandst   requirest   abouts   your-github-id-hereR<   s   recipe-maintainerss   ^\s+(-) t   flagst   -s     s   
(3   R]   R   R&   t   variantRB   R   t   popt   appendR   R	   RD   R   t   RuntimeErrort
   setdefaultRH   RE   RI   t   syst   exitRl   RX   t   lent   printt   get_download_datat   get_package_metadatat	   enumeratet   insertR   t   opent   PYPI_META_HEADERt   formatR   t   EXPECTED_SECTION_ORDERt   PYPI_META_STATICt   KeyErrort
   ValueErrorR   t   schemet   netlocRY   t   setRZ   t   ABOUT_ORDERRa   t   rstript
   splitlinest   ret   searcht	   MULTILINEt	   partitiont   write(.   t   packagest
   output_dirR5   t	   recursivet   all_urlsRK   t   nopromptt   version_comparet   python_versiont
   manual_urlt
   all_extrast   noarch_pythonR|   R}   t   extra_specst	   pin_numpyt   package_dictst   created_recipesR6   t   is_urlt   package_pypi_urlt   dir_pathRb   t	   pypi_datat   sort_by_versiont	   pypi_respt   versionst   vert   datat   dependst   depst   idxt   dept	   numpy_depR4   t   fRe   t   ordered_recipeRt   t   base_urlt   recipe_linesRO   t   matcht   pret   sept   post(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyt   skeletonize   s   				

				$


	






c         C` s  |  j  d d d d t } | j d d d d d | j d	 d d
 d d | j d d d | j d d d d d | j d d d d d | j d d d d t d d d d | j d d d d t d d | j d d d d d | j d d d d d  | j d! d d" d t d d# d$ d% d& d' d( g | j d) d d d t d d* | j d+ d d d t d d, | j d- d d. d g  d d/ | j d0 d d d d1 | j d2 d d. d g  d d3 d4 S(5   s-   Modify repos in place, adding the PyPI optiont   pypit   helpsl   
    Create recipe skeleton for packages hosted on the Python Packaging Index
    (PyPI) (pypi.io).
        t   epilogR   t   nargst   +so   PyPi packages to create recipe skeletons for.
                You can also specify package[extra,...] features.s   --output-dirs5   Directory to write recipes to (default: %(default)s).t   defaultRj   s	   --versionst   Version to use. Applies to all packages. If not specified the
              lastest visible version on PyPI is used.s
   --all-urlst   actiont
   store_trues`   Look at all URLs, not just source URLs. Use this if it can't
                find the right URL.s
   --pypi-urls   https://pypi.io/pypi/s+   URL to use for PyPI (default: %(default)s).s   --promptt   store_falset   destR   sh   Prompt the user on ambiguous choices.  Default is to make the
        best possible choice and continue.s   --all-extrass<   Add all extra feature requirements. Applies to all packages.s   --recursives=   Create recipes for dependencies if they do not already exist.s   --version-comparesV   Compare the package version of the recipe with all available
        versions on PyPI.s   --python-versiont   storesA   Version of Python to use to run setup.py. Default is %(default)s.t   choicess   2.7s   3.5s   3.6s   3.7s   --manual-urlsi   Manually choose source url when more than one urls are present.Default is the one with least source size.s   --noarch-pythons   Creates recipe as noarch pythons   --setup-optionsR   s,  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"s   --pin-numpysG   Ensure that the generated recipe pins the version of numpyto CONDA_NPY.s   --extra-specss>   Extra specs for the build environment to extract the skeleton.N(   t
   add_parsert   pypi_examplet   add_argumentt   TrueR_   R   (   t   reposR   (    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyR     s    	c         C` s!  | s |  d n i  } | s= g  |  d | D] } | ^ q+ n | g }	 | r | r g  |	 D] } | d d k r[ | ^ q[ }	 n  |	 s^| j  d  rJt t i | d d 6 g }	 |	 d d s t j d |  n  t |	 d d  }
 |
 j st j d	 | |
 f  n  |
 j j d
  d |	 d d <|
 j p5d } | j	 d  } q^t j d |  n  t
 |	  d k r;| r;t d |  | rxF t |	  D]8 \ } } t d | | d t | d  | d f  qWt t d   } qAt d  t d  t g  t |	  D] \ } } | d | f ^ q \ } } n d } | s|	 | } | d } t d | t | d ptd  | f  | d d rd | d d f } n d } | d pd } nQ t d |  | } t |  }
 |
 j j	 d  } |
 j j d
 d  d pd } | | | | f S(   sv  
    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.
    t   infoRw   t   packagetypet   sdistt   download_urlR7   i    sD   Error: Could not build recipe for %s. Could not find any valid urls.s%   Error: Could not parse url for %s: %sRF   iRy   R;   t   =s"   Error: No source urls found for %si   s1   More than one source version is available for %s:s   %d: %s (%s) %st   sizet   comment_texts   which version should i use? s(   Using the one with the least source sizes*   use --manual-url to override this behaviors   Using url %s (%s) for %s.t   digestsR   R6   s   Using url %s(    (   RB   R   R`   R   R   R   t   patht   rsplitt   fragmentt   splitR   R   R   R   t   intR   t   min(   R   R6   R5   R   R   R   R   R   R7   t   urlst   UR   Rz   t   it   nt   _Rx   Ry   (    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyR     s\    0,			 

8

	c   	      C` s&  | s
 d  St  } g  | D] } | |  ^ q } t |  j    } t |  sa t j d |  n  t |  } | | j    } t d |  | f  | | k r t j d |  | f  ni | | j	 |   } t
 |  d k r
t d |   x) | D] } t |  q Wn t d |   t j   d  S(   Ns   Error: no such directory: %ss"   Local recipe for %s has version %ss&   Error: %s %s is not available on PyPI.i    s*   Following new versions of %s are avaliables"   No new version for %s is available(   R   R   RD   R
   R   R   R'   R5   R   t   indexR   (	   R6   R   t   nvR   t   norm_versionst
   recipe_dirt   mt   local_versiont   new_versions(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyR   Y  s(    	c         ` s   |  j  d    d	 } t   f d   | D  r>   j   n  t    d } t   |  d   | <d j d     | d  D  } d j |  |  } | S(
   sA   Convert version into a pin-compatible format according to PEP440.Rj   R   R   c         3` s   |  ] } |   d  k Vq d S(   iN(    (   t   .0RQ   (   t   version_parts(    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pys	   <genexpr>|  s    i   i   c         s` s   |  ] } t  |  Vq d  S(   N(   R`   (   R   t   v(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pys	   <genexpr>  s    s	    >={},<{}(   R   R   (   R   t   anyR   R   R   R	   R   (   R5   t   suffixest   max_ver_lent   max_pint   pin_compatible(    (   R   s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyt   convert_versionx  s    !s   (?P<name>^[^=<>!\s]+)\s*(?P<constraint>[=!><]=?\s*[^\s;]+)?(?:\s+;\s+)?(?P<env_mark_name>[^=<>!\s;]+)?\s*(?P<env_mark_constraint>[=<>!\s]+[^=<>!\s]+)?c         C` sz   |  j    } |  } t |  d k rv | \ } } d j | j d  j d  j  d  d   } d j | | f  } n  | S(   Ni   R;   t   't   "Rj   RN   (   R   R   R	   RC   (   t
   constraintt   partst   translationt   operatort   value(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyt   _translate_python_constraint  s    .c         C` sR   i i d d 6t  d 6d 6} d j | |  d | |  d |  f  } d | d S(   sy   returns translated variable name and corresponding function to run to normalize the
    version constraint to conda stylet   pyt   replt   constraint_trans_fnR   RN   s     # [ s    ](   R  R	   (   t   env_mark_namet   env_mark_constraintt   env_mark_tablet   marker(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyt   env_mark_lookup  s
    c         C` s   t  j |   } | j d  } | j d  rZ d j | | j d  j d d  f  } n  d } | j d  r t | j d  | j d   } n  | | f S(   NR4   R  RN   R;   R  R  (   t	   MARKER_RER   t   groupR	   t   replaceR  (   t   dep_strR   R4   t   env_mark(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyt   parse_dep_with_env_marker  s    -c   "      C` s  t  d |   t  d | d  t |  d | d d | d d | d d | d | d | d	 | } | j t |   t |  | d
 | } | s t |  rPg  } t |  r | j d  n  x| D]} t | t  r | j	   } n  x | D] } | j
 d  d j   } | r t |  \ } } t |  } | d  k rRt j d |  n  d | k r| j
   d } d j |  } t |  } | j | |  } n  | rd j | | f  } n  | j |  q q Wq Wd g | | d <| | d <| rPxU | D]J } | j
   d } t t | |   s| | k rF|
 j |  qFqqWqPn  d | k rs| d j   | d <n  | d d k r| d | d <n  | j d  rit | d  } | d r#| d s| d d k rg  } n/ g  | d j
   D] } | d k r| ^ q} t |  | B} n  t |  | d <t g  t | d  D] } t |  ^ qG | d <n  | j d  r| d | d <n- | rd | k r| d | d <n
 d  | d <| j d!  rd! | k r| d! r| d! | d! <qn
 d" | d! <d# } | r| j d$ g   n g  } | j d$ |  } | r<| n | } g  | D]+ } | j |  rI| j
 | d%  d% ^ qI} | sD| j d&  r| d& }  n% | rd& | k r| d& }  n d  }  |  r"|	 rqAd' |  k rt  d( |   qAt  d) |   t    t  |   t    t d*  }  qS|	 r1d }  qSt d+ |   }  n d, j |  }  t j d- d. |  d/ t j d }! |! | d& <t  |  t!  | d0 <d1 | k r| d1 | d <n  d  S(2   Ns   Downloading %ss
   PyPI URL: Rx   Ry   Rz   R   R   R}   R|   R   t
   setuptoolst   #i    s   Error: Could not parse: %st   ~is   ~ {}RN   R   Ro   Rn   Rm   R4   R5   Rs   R   R{   t   PLACEHOLDERR   Rr   R-   s   The package home pageR1   s   Summary of the packages   License :: OSI Approved :: t   classifiersi   R.   s   
s   Using "%s" for the licenses   This is the license for %ss"   What license string should I use? sV   No license could be found for %s on PyPI or in the source. What license should I use? s    or s   (.*)\s+licenses   \1R   R/   t   new_hash_value("   R   t   get_pkginfot   updatet   get_entry_pointst   get_requirementst   is_setuptools_enabledR   R]   R   R   R   RC   R  R   R\   R   R   R   R  R  R	   R   RD   RB   R   RY   R#   t
   startswithR   R   t   subnt
   IGNORECASER)   R(   ("   R6   Rb   R   R   R   R   R   R   R   R   R   R   R|   R}   t   pkginfoR   R   t   deptextR   R  t   specR5   t   tilde_versionR  t   olddepst   xt   pkgt   license_classifiert   data_classifiert   pkg_classifiert
   classifiert   licensest   license_namet   clean_license_name(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyR     s    	


	

	0


+
	"
c   
      C` s  |  j  d  } | s i  St | t  rd j d   | j   D  } t j   } y | j t |   Wn- t	 k
 r } t
 d |  t
 d |  qXi  } xb | j   D]Q } | d k r g  | j |  D]" } d | | j  | |  f ^ q | | <q q Wn  t | t  rot | j  d g    } t | j  d g    } | | }	 |	 ri |	 d 6t |	  d	 6Sn t
 d
  t
 |  i  S(   s   Look at the entry_points and construct console_script and gui_scripts entry_points for conda
    :param pkginfo:
    :return dict:
    Rp   s   
c         s` s   |  ] } | j    Vq d  S(   N(   RC   (   R   R/  (    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pys	   <genexpr>F  s    s&   WARNING: entry-points not understood: s   The string wast   console_scriptst   gui_scriptss   %s=%sRq   s/   WARNING: Could not add entry points. They were:(   R8  R9  (   RB   R]   R`   R	   R   R   t   ConfigParsert   readfpR   t	   ExceptionR   t   sectionst   optionst   dictt   convert_to_flat_listt   make_entry_tests(
   R*  Rp   t   newstrt   _configt   errt   sectiont   optiont   console_scriptR9  t
   entry_list(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyR$  ;  s:    C


c         C` s   t  |  t  r |  g }  nd |  r t  |  t  r t  |  d t  r g  g  |  D] } | ^ qM D] } | D] } | ^ qg q] }  n  |  S(   s   Convert 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
    i    (   R]   R   RZ   (   t   var_scriptst   st   sublistRi   (    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyR@  n  s
    (<c         C` sF   |  j  d  } t | t  s" t St | j    d d h rB t St S(   s   Function 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
    Rp   R8  R9  (   RB   R]   R?  R_   R   RX   R   (   R*  Rp   (    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyR&  }  s    c         C` s.   t  j d |   r& t j |   r& |  Sd Sd  S(   Ns   [_A-Za-z][_a-zA-Z0-9]*$R;   (   R   R   t   keywordt	   iskeyword(   R4   (    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyt   valid  s    "c         C` s9   |  j    j t  r% t |  |  n t d |    d  S(   Ns   not a valid source: %s(   RD   t   endswithR   R    R<  (   t   src_patht   tempdir(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyt   unpack  s    c         C` s   g  t  |   D]1 } | j d  r t t |  |   r | ^ q } t |  d k r| t |  | d  } t |  r| | Sn  | s |  St d   d  S(   NRj   i   i    s"   could not find unpacked source dir(   R   R'  R
   R	   R   R<  (   RQ  t   fnt   lstR   (    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyt   get_dir  s    #!c         C` s\  t  j d |   } | r< | j   \ }  } | j d  } n g  } | ra t | d j    } ny% g  | D] } | d | ^ qk } Wn+ t k
 r t j d d j	 |   n Xt  j
 d  } x<| d D]0} | j |  }	 |	 r |	 j   \ }
 } y, t d   | j d  j d  D  } Wn t k
 r:qX|
 d	 k rYt j | k  } n |
 d
 k rwt j | k } ni |
 d k rt j | k } nK |
 d k rt j | k } n- |
 d k rt j | k } n t j | k } | r| | d | 7} qq q Wg  } xM | j d d  g | D]2 } t | t  rG| j |  q"| j |  q"W| S(   Ns   ^([^[]+)\[([^]]+)\]$t   ,t   extras_requires#   Error: Invalid extra features: [%s]s&   ^:python_version(<|<=|!=|==|>=|>)(.+)$c         s` s   |  ] } t  |  Vq d  S(   N(   R   (   R   R/  (    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pys	   <genexpr>  s    s   '"Rj   t   <s   <=s   !=s   ==s   >=t   install_requiresR;   (   R   R   t   groupsR   RZ   t   valuesR   R   R   R	   t   compilet   tupleRC   R   t   version_infoRB   R]   R   R   t   extend(   R6   R*  R   t   match_extrast   extrasRW  R/  t   version_markerR<   t   match_ver_markt   opR   t	   ver_tuplet   satisfies_verR   t   specs(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyR%    sN    %, c      
   C` s  t  d |  } t | j  s/ t | j  n  | d }	 | d }
 zt | j |  } t |  sz t | |	  |
 k r t | t | j |   t | |	  |
 k r t d j	 |  |	 |
    q n
 t
 d  |	 d k r t | d  } n d } t
 d |   t t | j |  |  t
 d	  t
 d
 |  t |  } t | | | d | d | d | y1 t t | d    } t j |  } Wd  QXWn# t k
 rt j |  j } n X| rd | f | d <n  Wd  t |  X| S(   Nt   conda_skeleton_i    i   sL    Download of {} failed checksum type {} expected value {}. Please try again.s   Using cached downloadR   R;   s   Unpacking %s...t   dones   working in %sR   R|   R}   s   pkginfo.yamlR!  (   R   R
   t	   src_cacheR   R	   R   R   R   R   R   R   RR  RU  t   run_setuppyR   t   yamlt	   safe_loadt   IOErrorR*  t   SDistt   __dict__R!   (   R6   Ry   Rx   Rz   R   R   R|   R}   RQ  R~   R   t   download_pathR!  t   src_dirRS  t   pkg_info(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyR"    sB    

	

c         C` s0  d | d d g } t  t j j |  d   ; } | j   } d | k sU d | k re | j d  n  Wd QX| j |  t | j  t	 | j d	 | d
 d d | j
 d t d | t | j t j d k r d n d |  }	 t | d  }
 t  |
 d  ) } | j t j | j d d    Wd QXt t |	 d d   rt t |	 d d   t t |	 d d  t |	 d d   t rt t |	 d d d t j d    t t |	 d d d t j d    qt t |	 d d   t t |	 d d   n% t t |	 d d  t |	 d d   t t |	 d  |
 d | t j j   } d | k r{t |  d  | d  | t d  <n t |   | t d  <t   } t |   | j d d! g } | j |  z[ y t | d
 | Wn@ t j k
 rt  d" | d  t j! d# d$ j |   n XWd t |  Xd S(%   s   
    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
    s
   python %s*t   pyyamlR  s   setup.pys   import numpys
   from numpyR   Nt   specs_or_actionst   envR+   t   subdirt   clear_cacheR|   t   win32t   Libs   lib/python%ss   pypi-distutils.patchR   s   \s   \\t	   distutilss   core.py-copys   core.pyt   __pycache__s   core.cpython-%s%s.pyci   s   core.cpython-%s%s.pyos   core.pycs   core.pyot
   PYTHONPATHRV   t   installs   $PYTHONPATH = %ss   Error: command failed: %sRN   ("   R   R@   R   R	   t   readR   R_  R!   t   host_prefixR%   t   host_subdirR_   R   t   platformR   t   DISTUTILS_PATCHR   R  R   R   R   R^  R$   RA   t   copyR`   R   R   t   host_pythonR"   t
   subprocesst   CalledProcessErrorR   R   (   Rr  t   temp_dirR   R   R|   R}   Rg  t   setupt   textt
   stdlib_dirt   patchR   Rv  t   cwdt   cmdargs(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyRk    sX    	(%	
 "c         C` sE   g  } x8 |  D]0 } | j  d  d j   } | j | d  q W| S(   NR   i    s    --help(   R   RC   R   (   RH  t   testst   entry_pointt   entry(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyRA  ]  s
    (   R4   s   {{ name|lower }}(   R5   s   {{ version }}(   R7   sI   /packages/source/{{ name[0] }}/{{ name }}/{{ name }}-{{ version }}.tar.gz(   R9   i    (   s   recipe-maintainersR;   (h   t   __doc__t
   __future__R    R   R   t   collectionsR   R   RL  R@   R   R   R   R   t   os.pathR	   R
   R   R   R   t   pkg_resourcesR   R   t   shutilR   R  R   t   tempfileR   R*  RH   t"   requests.packages.urllib3.util.urlR   t   six.moves.urllib.parseR   R   Rl  t   conda_build.conda_interfaceR   R   R   R   R   R   R   R   R   R   R   t   conda_build.utilsR   R    R!   R"   R#   t   conda_build.sourceR$   t   conda_build.environR%   t   conda_build.configR&   t   conda_build.metadataR'   t   conda_build.license_familyR(   R)   t   conda_build.renderR*   R   R   t   REQUIREMENTS_ORDERR   R   R   R  t   INDENTRE   R\   RM   R   RU   Ra   R_   R   R   R   R   R  R\  R  R  R  R  R   R$  R@  R&  RN  RR  RU  R%  R"  Rk  RA  (    (    (    s9   lib/python2.7/site-packages/conda_build/skeletons/pypi.pyt   <module>   s   "(((1		 				p	V				
				3					8	9	E