ó
@K7]c           @` st  d  Z  d d l m Z m Z m Z d d l Z d d l m Z d d l 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 d d l Z d d l Z d d l Z d d l m Z d d	 l m Z m Z d d
 l m Z 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" d d l# m$ Z$ d d l% Z% d Z& d Z' d Z( g  Z) d e* f d „  ƒ  YZ+ d e f d „  ƒ  YZ, d „  Z- d „  Z. d „  Z/ d d d e1 e1 d e1 d „ Z2 e d „  ƒ Z3 d „  Z4 e d „  ƒ Z5 d  „  Z6 e d! „  ƒ Z7 d" „  Z8 d# „  Z9 e d$ „  ƒ Z: d% „  Z; e1 d& „ Z< d' „  Z= d( „  Z> d S()   s6   
Tools for converting CPAN packages to conda recipes.
i    (   t   absolute_importt   divisiont   print_functionN(   t   parse_version(   t   glob(   t   makedirs(   t   basenamet   dirnamet   joint   exists(   t	   get_index(   t   TmpDownloadt   download(   t	   MatchSpect   Resolve(   t   memoized(   t   CondaHTTPErrort
   CondaError(   t   get_or_merge_config(   t   on_wint   check_call_env(   t   get_default_variants_  {{% set name = "{packagename}" %}}
{{% set version = "{version}" %}}
{{% set sha256 = "{sha256}" %}}

package:
  name: {{{{ name }}}}
  version: {{{{ version }}}}

{source_comment}source:
  {useurl}fn: {filename}
  {useurl}url: {cpanurl}
  {usesha256}sha256: {{{{ sha256 }}}}

# If this is a new build for the same version, increment the build
# number. If you do not include this key, it defaults to 0.
build:
  number: 0

requirements:
  build:
    - perl{build_depends}

  run:
    - perl{run_depends}

{import_comment}test:
  # Perl 'use' tests
  {import_comment}imports:{import_tests}

  # You can also put a file called run_test.pl (or run_test.py) in the recipe
  # that will be run at test time.

about:
  home: {homeurl}
  license: {license}
  summary: {summary}

# See
# https://docs.conda.io/projects/conda-build for
# more information about meta.yaml
s  #!/bin/bash

# If it has Build.PL use that, otherwise use Makefile.PL
if [ -f Build.PL ]; then
    perl Build.PL
    perl ./Build
    perl ./Build test
    # Make sure this goes in site
    perl ./Build install --installdirs site
elif [ -f Makefile.PL ]; then
    # Make sure this goes in site
    perl Makefile.PL INSTALLDIRS=site
    make
    make test
    make install
else
    echo 'Unable to find Build.PL or Makefile.PL. You need to modify build.sh.'
    exit 1
fi

# Add more build steps here, if they are necessary.

# See
# https://docs.conda.io/projects/conda-build
# for a list of environment variables that are set during the build process.
s5  :: If it has Build.PL use that, otherwise use Makefile.PL
IF exist Build.PL (
    perl Build.PL
    IF %ERRORLEVEL% NEQ 0 exit 1
    Build
    IF %ERRORLEVEL% NEQ 0 exit 1
    Build test
    :: Make sure this goes in site
    Build install --installdirs site
    IF %ERRORLEVEL% NEQ 0 exit 1
) ELSE IF exist Makefile.PL (
    :: Make sure this goes in site
    perl Makefile.PL INSTALLDIRS=site
    IF %ERRORLEVEL% NEQ 0 exit 1
    make
    IF %ERRORLEVEL% NEQ 0 exit 1
    make test
    IF %ERRORLEVEL% NEQ 0 exit 1
    make install
) ELSE (
    ECHO 'Unable to find Build.PL or Makefile.PL. You need to modify bld.bat.'
    exit 1
)

:: Add more build steps here, if they are necessary.

:: See
:: https://docs.conda.io/projects/conda-build
:: for a list of environment variables that are set during the build process.
t   InvalidReleaseErrorc           B` s   e  Z d  Z RS(   sR   
    An exception that is raised when a release is not available on MetaCPAN.
    (   t   __name__t
   __module__t   __doc__(    (    (    s9   lib/python2.7/site-packages/conda_build/skeletons/cpan.pyR   ‰   s   t   PerlTmpDownloadc           B` s   e  Z d  Z d „  Z RS(   s_   
    Subclass Conda's TmpDownload to replace : in download filenames.
    Critical on win.
    c         C` s$  d |  j  k r d  |  _ |  j  Sd |  j  k rM |  j  j d ƒ } | d } n t |  j  ƒ } | j d d ƒ t j ƒ  |  _ t j	 j
 d ƒ } t | d d	 t |  j  ƒ j d d ƒ ƒ } t | | ƒ } | j d d ƒ } t | ƒ } t | ƒ sý t | ƒ n  t | ƒ st |  j  | ƒ n  | Sd  S(
   Ns   ://t	   CHECKSUMSs   id/i   s   ::t   -t   ~s   .conda-buildt   cpan(   t   urlt   Nonet   tmp_dirt   splitR   t   replacet   tempfilet   mkdtempt   ost   patht
   expanduserR   R   R	   R   R   (   t   selft   turlt   filenamet   homet   base_dirt   dst(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/cpan.pyt	   __enter__˜   s(    	(   R   R   R   R/   (    (    (    s9   lib/python2.7/site-packages/conda_build/skeletons/cpan.pyR   ‘   s   c         C` s   t  t t  |  ƒ ƒ ƒ S(   N(   t   strR   (   t   ver(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/cpan.pyt   loose_version·   s    c      	   C` sÚ   | s |  j  d d ƒ }  n  t |  ƒ ­ } yX t j | ƒ  } | j ƒ  } Wd  QXt | d ƒ rr | j d ƒ } n  t j | ƒ } WnK t	 k
 r¹ t j t
 j | d d ƒj ƒ  ƒ } n t k
 rÏ d  } n XWd  QX| S(   Ns   ::R   t   decodes	   utf-8-sigt   encodings   utf-8(   R#   R   t   gzipt   opent   readt   hasattrR3   t   jsont   loadst   IOErrort   codecsR   R    (   R   t   colonst	   json_patht   dist_json_filet   outputt   rel_dict(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/cpan.pyt   get_cpan_api_url»   s    c         C` s}   y\ d d |  g } t  rK | j d d ƒ | j d d ƒ | j d d ƒ n  t | ƒ t } Wn t j k
 rx t } n X| S(   NR   s   -Di    s   /cs   /ds   cmd.exe(   R   t   insertR   t   Truet
   subprocesst   CalledProcessErrort   False(   t   package_namet   cmdt   in_repo(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/cpan.pyt   package_existsÍ   s    


t   .s   http://fastapi.metacpan.org/v1c   !      C` s?  t  | ƒ } | j j d t | ƒ d ƒ } | j d d ƒ } i  }	 d }
 d } t ƒ  } | } xÚ|  r:|  j ƒ  } d | k rš | j d ƒ \ } } } n | } | | k r² qa n  | j | ƒ | } t	 | | | d | ƒ} | d k r
t
 d d	 d
 j | ƒ ƒ qa n; | | | j d d ƒ h k rEt
 d d j | | ƒ ƒ n  t | | d: | d | ƒ} t | ƒ } | d: k	 rŒ| d | | k sa | d | d | k rªqa n  |	 j | i
 | d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6ƒ } | d: k r| } n! t | | t | ƒ | d | ƒ} t | | | d ƒ } t | | ƒ rž| swt
 d | ƒ qa n  d | d <d | d <d | d <t } nò t | d | d | d  | d! | d" | d | ƒ\ } } } } } | d c |
 j d g t | | Bƒ ƒ 7<| d c | j d g t | | Bƒ ƒ 7<| d c |
 j d g t | ƒ ƒ 7<| d c | j d g t | ƒ ƒ 7<|  j | ƒ t } d: } t | ƒ r½| r½t
 d# | ƒ qa n# t | ƒ rà| ràt
 d$ | ƒ n  d | d% <t d ƒ | d& <d | d' <| j d( ƒ r*t | d( ƒ | d& <n  | j d) ƒ r“| d) | d% <t | d) ƒ \ | d' <} t | d) ƒ | d& <t
 d* | d% | | f ƒ n d | d <d | d <d | d <y | d+ d, | d- <Wn t k
 rèd. | | d- <n Xd/ | k rt | d/ ƒ j d0 ƒ } | | d <n  y3 t | d1 t ƒ r?| d1 d2 n | d1 | d1 <Wn t k
 rkd3 | d1 <n X| d | d <| j | d | d ƒ | j d d ƒ j d ƒ d2 } d4 | k rxS t  t | d4 ƒ ƒ D]8 } | j! | ƒ rÕd5 | k rÕ| d c |
 | 7<qÕqÕWn  | d r+d | d6 <n
 d | d6 <t | ƒ sNt" | ƒ n  t
 d7 | | d f ƒ t# t | d8 ƒ d9 ƒ  }  |  j$ t% j |   ƒ Wd: QXt# t | d; ƒ d9 ƒ 3 }  | rÎ|  j$ d< ƒ n |  j$ t& j |   ƒ Wd: QXt# t | d= ƒ d9 ƒ 3 }  | r|  j$ d> ƒ n |  j$ t' j |   ƒ Wd: QXqa Wd: S(?   sS   
    Loops over packages, outputting conda recipes converted from CPAN metata.
    t   perls   .*t    s   
    - s   
    #- t   =t   configs9   WARNING: {0} is a Perl core module that is not developed s6   outside of Perl, so we are skipping creating a recipe s   for it.s   ::R   s9   WARNING: {0} was part of the {1} distribution, so we are s    making a recipe for {1} instead.t   versiont   packagenamet   run_dependst   build_dependss   # t   build_commentt   test_commandst	   usesha256t   useurlt   source_comments   ''t   summaryt   import_testss2   We found core module %s. Skipping recipe creation.t   #t   release_datat   perl_versiont
   output_dirt   meta_cpan_urlt	   recursives?   Directory %s already exists and you have not specified --force s8   Directory %s already exists, but forcing recipe creationt   cpanurlR+   t   sha256t   archivet   download_urls   Using url %s (%s) for %s.t	   resourcest   homepaget   homeurls   http://metacpan.org/pod/t   abstractt   ut   licensei    t   perl_5t   providess   ::_t   import_comments   Writing recipe for %s-%ss	   meta.yamlt   wNs   build.shs"   #!/bin/bash
echo "Nothing to do."
s   bld.bats   echo "Nothing to do."
((   R   t   variantt   getR   R#   t   sett   popt	   partitiont   addt   dist_for_modulet   printt   formatt   get_release_infoR    t   perl_to_condat
   setdefaultR   R   t   metacpan_api_is_core_versionRD   t   deps_for_packaget   listt   extendRG   R	   t   reprR   t   get_checksum_and_sizet   KeyErrort   lstript
   isinstanceR"   t   sortedt
   startswithR   R6   t   writet	   CPAN_METAt   CPAN_BUILD_SHt   CPAN_BLD_BAT(!   t   packagesR_   RQ   R`   Ra   t   forceRP   t
   write_coreR^   t   package_dictst   indentt   indent_coret   processed_packagest   orig_versiont   packaget   _t   orig_packaget   latest_release_dataRR   t   dR]   t   dir_patht   empty_recipet
   build_depst   build_core_depst   run_depst   run_core_depst   packages_to_appendt   sizeRZ   t   module_prefixt   provided_modt   f(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/cpan.pyt   skeletonizeÜ   s   		
									


	&&




!

c         C` sF   |  d  k r t S|  d  k	 r> | d k s: |  t | ƒ k r> t St Sd  S(   NRN   (   NRN   (   R    RG   R   RD   (   t   core_versionRQ   (    (    s9   lib/python2.7/site-packages/conda_build/skeletons/cpan.pyt   is_core_version   s    c         C` sÂ   |  j  d d d ƒ} | 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 d ƒ| j d d d d d ƒd  S(   NR   t   helpsy   
    Create recipe skeleton for packages hosted on the Comprehensive Perl Archive
    Network (CPAN) (cpan.org).
        R‹   t   nargst   +s-   CPAN packages to create recipe skeletons for.s   --output-dirs5   Directory to write recipes to (default: %(default)s).t   defaultRL   s	   --versions(   Version to use. Applies to all packages.s   --meta-cpan-urls   http://fastapi.metacpan.org/v1sB   URL to use for MetaCPAN API. It must include a version, such as v1s   --recursivet   actiont
   store_truesT   Create recipes for dependencies if they do not already exist (default: %(default)s).s   --forces;   Force overwrite of existing recipes (default: %(default)s).s   --write_cores<   Write recipes for perl core modules (default: %(default)s). (   t
   add_parsert   add_argument(   t   reposR   (    (    s9   lib/python2.7/site-packages/conda_build/skeletons/cpan.pyR¬   «  s<    	c         C` sd   t  t ƒ  ƒ } y t | j t |  ƒ ƒ ƒ } Wn d } n X| rZ t | d j ƒ } n d } | S(   sO   
    :returns: the latest version of the specified conda package available
    iÿÿÿÿN(   R   R
   R…   t   get_pkgsR   R    R   RQ   (   t   pkgt   rt   pkg_listt   pkg_version(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/cpan.pyt   latest_pkg_versionÏ  s    
c      
   C` s±  t  ƒ  } t  ƒ  } t  ƒ  }	 t  ƒ  }
 t  ƒ  } t d |  d d ƒt j j ƒ  | j d ƒ sp | | |	 |
 | f Sx+| d D]} yü| d d k r|t d d d ƒt j j ƒ  t | | d | d	 | ƒ} t | ƒ } | j ƒ  d
 k rñ w{ n  | d d d h k rd | d <n  t	 | d ƒ } y' t
 | | d | | d t d	 | ƒWnF t k
 r“t d d d d | |  t | ƒ f ƒ t	 d ƒ } n Xt | ƒ t d ƒ k rut | ƒ } | d k rÚt | | d ƒ } n  y= | d k	 rt | ƒ t | ƒ k r| d | d 7} n  Wqut k
 rqt d ƒ t d j | d ƒ ƒ t d j | ƒ ƒ t d j | ƒ ƒ quXn  | rúd | k rÎt t | | j d d ƒ ƒ ƒ s÷| j d j | | d f ƒ ƒ q÷qút t | | d ƒ ƒ sú| j | ƒ qún  t | | d ƒ } | d d k rC| r3|
 j | ƒ qy|	 j | ƒ q|| d d k r|| ri| j | ƒ qy| j | ƒ q|n  Wq{ t t f k
 r™q{ q{ Xq{ W| | |	 |
 | f S(   s¢  
    Build the sets of dependencies and packages we need recipes for. This should
    only be called for non-core modules/distributions, as dependencies are
    ignored for core modules.

    :param package: Perl distribution we're checking dependencies of.
    :type package: str
    :param release_data: The metadata about the current release of the package.
    :type release_data: dict
    :param perl_version: The target version of Perl we're building this for.
                         This only really matters for core modules.
    :type perl_version: str
    :param output_dir: The output directory to write recipes to
    :type output_dir: str
    :param processed_packages: The set of packages we have built recipes for
                               already.

    :returns: Build dependencies, runtime dependencies, and set of packages to
              add to list of recipes to create.
    :rtype: 3-tuple of sets
    s!   Processing dependencies for %s...t   endRN   t
   dependencyt   relationshipt   requiresRL   t   moduleRP   RM   RQ   t   undeft   0s'   WARNING: The version of %s listed as a s5   dependency for %s, %s, is not available on MetaCPAN, s.   so we are just assuming the latest version is s   okay.t    s6   We have got an expected error with dependency versionss	   Module {}s   Pkg_version {}s   Dep Version {}s   ::R   RO   s   -[v1-9][0-9.]*t   phaset   runtimet   developN(   Rr   Rw   t   syst   stdoutt   flushRq   Rv   Rz   t   lowerR   Ry   RD   R   R0   R2   R´   R    t   metacpan_api_get_core_versiont	   ExceptionRx   R	   R   R#   Ru   R   R|   R   R   (   R“   R]   R^   R_   R`   Ra   RP   Rš   R›   Rœ   R   Rž   t   dep_dictt	   orig_distt	   dep_entryt   dep_versionR³   t   core(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/cpan.pyR}   à  s„    					c         C` sA   t  |  | ƒ } | d k	 r$ | } n t |  | ƒ } | d } | S(   s]   
    Given a name that could be a module or a distribution, return the
    distribution.
    t   distributionN(   t   release_module_dictR    t   core_module_dict(   t   cpan_urlR¹   R^   RP   RA   RË   t   mod_dict(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/cpan.pyRv   i  s    	
c         C` sV   y" t  d j |  | ƒ d t ƒ} Wn- t k
 r; d  } n t k
 rQ d  } n X| S(   Ns   {0}/release/{1}R=   (   RB   Rx   RG   t   RuntimeErrorR    R   (   RÎ   R¹   RA   (    (    s9   lib/python2.7/site-packages/conda_build/skeletons/cpan.pyRÌ   {  s    	
c         C` s[   y" t  d j |  | ƒ d t ƒ} Wn" t k
 rF t j d | ƒ n Xi  } d | d <| S(   Ns   {0}/module/{1}R=   sP   Error: Could not find module or distribution named %s on MetaCPAN. Error was: %sRM   RË   (   RB   Rx   RD   R   RÀ   t   exit(   RÎ   R¹   RÏ   (    (    s9   lib/python2.7/site-packages/conda_build/skeletons/cpan.pyRÍ   ˆ  s    	
c         C` s   d j  |  | ƒ } | j d d ƒ } t j | ƒ } | j d k rF t Sd j  |  | ƒ } t j | ƒ } | j d k rz t St j d | ƒ d  S(   Ns   {0}/release/{1}s   ::R   iÈ   s   {0}/module/{1}sB   Error: Could not find module or distribution named %s on MetaCPAN.(	   Rx   R#   t   requestsRq   t   status_codeRG   RD   RÀ   RÑ   (   RÎ   R¹   R   t   req(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/cpan.pyR|   —  s    	c         C` sC   t  |  | ƒ } y | d d d } Wn t k
 r> d  } n X| S(   NR¹   iÿÿÿÿRQ   (   RÍ   RÅ   R    (   RÎ   R¹   t   module_dictRQ   (    (    s9   lib/python2.7/site-packages/conda_build/skeletons/cpan.pyRÄ   «  s    
c         C` s0  | } t  |  | | d | ƒ} y? t d j |  | ƒ d t ƒ} t | d ƒ j d ƒ | d <Wn¦ t k
 rt |  | ƒ } | d k	 rí | d k s  | | k rí t	 d d d d	 j | ƒ ƒ i t | ƒ d 6d
 d 6d g d 6i  d 6} qt
 j d d | ƒ n Xt }	 | d k	 rt | ƒ }
 t | d ƒ } t t |
 ƒ ƒ } y@ | d k	 o‚t d ƒ t |
 ƒ k o‚t | ƒ t |
 ƒ k }	 Wqt k
 rÿ} t	 d ƒ t	 | ƒ t	 d j | ƒ ƒ t	 d j | ƒ ƒ t	 d j | d ƒ ƒ t	 d j | ƒ ƒ qXn  |	 r,t	 d ƒ t	 d j |
 | ƒ ƒ n  | S(   s…   
    Return a dictionary of the JSON information stored at cpan.metacpan.org
    corresponding to the given package/dist/module.
    RP   s   {0}/release/{1}R=   RQ   t   vs6   WARNING: {0} is not available on MetaCPAN, but it's a s9   core module, so we do not actually need the source file, s1   and are omitting the URL and MD5 from the recipe s	   entirely.RN   Re   Rl   Rk   R¶   s4   Error: Could not find any versions of package %s on s	   MetaCPAN.R»   s<   We have some strange version mismatches. Please investigate.s
   Package {}s
   Version {}s   Pkg Version {}s   Loose Version {}s   We have a version mismatch!s   Version: {}, RelVersion: {}N(   Rv   RB   Rx   RG   R0   Rƒ   R   R|   R    Rw   RÀ   RÑ   R   R2   RÅ   (   RÎ   R“   RQ   R^   RP   R¶   R•   RA   R¤   t   version_mismatcht   version_strt   rel_versiont	   loose_strt   e(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/cpan.pyRy   ¶  sJ    !	


c   	      C` s  t  |  ƒ } t |  ƒ } t | d ƒ à } t | ƒ Ë } t } d	 } d	 } x¯ | D]§ } | j ƒ  } | j d | ƒ r t } qS | rS | j d ƒ rµ | j	 d ƒ d j d ƒ } qú | j d ƒ rä | j	 d ƒ d j d ƒ } Pqú | j d ƒ rú Pqú qS qS WWd	 QXWd	 QX| | f S(
   s   
    Looks in the CHECKSUMS file in the same directory as the file specified
    at download_url and returns the sha256 hash and file size.
    s
   /CHECKSUMSt   's   'sha256's   =>i   s   ', s   'sizet   }N(
   R   R   R   R6   RG   R    t   stripR†   RD   R"   (	   Re   t   base_urlR+   t   checksum_patht   checksum_filet
   found_fileRc   RŸ   t   line(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/cpan.pyR   ñ  s(    	c         C` s   d |  j  d d ƒ j ƒ  S(   s@    Sanitizes a Perl package name for use as a conda package name. s   perl-s   ::R   (   R#   RÃ   (   t   name(    (    s9   lib/python2.7/site-packages/conda_build/skeletons/cpan.pyRz     s    (?   R   t
   __future__R    R   R   R<   t   pkg_resourcesR   R   R5   R9   R&   R   t   os.pathR   R   R   R	   RE   RÀ   R$   t   conda_build.conda_interfaceR
   R   R   R   R   R   R   R   t   conda_build.configR   t   conda_build.utilsR   R   t   conda_build.variantsR   RÒ   Rˆ   R‰   RŠ   t	   perl_coreRÐ   R   R   R2   RB   RK   R    RG   R£   R¥   R¬   R´   R}   Rv   RÌ   RÍ   R|   RÄ   Ry   R   Rz   (    (    (    s9   lib/python2.7/site-packages/conda_build/skeletons/cpan.pyt   <module>   sZ   "+ &			Â	$	‰			:	