ó
@K7]c           @   sÆ   d  Z  d d l Z d d l Z d d l Z d d l m Z d d l Z d d l m Z d Z	 d Z
 d Z d Z d	 Z d
 Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d e d „ Z d S(   s:   
Tools for converting luarocks packages to conda recipes.
iÿÿÿÿN(   t   glob(   t   platforms   
    - s  
local ok,cjson = pcall(require, "cjson")
if not ok then
   print("ERROR: lua-cjson not installed. Use conda to install luarocks, "
         "then run 'luarocks install lua-cjson'.")
   os.exit()
end

local rockspecFile = "%s"
local origPackage = package
local ok, _ = pcall(dofile, rockspecFile)
if not ok then
   print("ERROR: could not load rockspecFile " .. tostring(rockspecFile))
   os.exit()
end

-- Resolve name clash
if origPackage == package then
   package = nil
end
local out = {
   rockspec_format=rockspec_format,
   package=package,
   version=version,
   description=description,
   supported_platforms=supported_platforms,
   dependencies=dependencies,
   external_dependencies=external_dependencies,
   source=source,
   build=build,
   modules=modules,
}
print(cjson.encode(out))
s×  package:
  name: {packagename}
  version: "{version}"

source:
  {usefile}fn: {filename}
  {usefile}url: {url}
  {usegit}git_url: {url}
  {usegittag}git_tag: {gittag} # can also be a branch, but that is highly discouraged
  {usegitrev}git_rev: {gitrev} # prefer tags over commits, commits over branches
  {usemd5}md5:{md5}
#  patches:
   # List any patch files here
   # - fix.patch

build:
  {noarch_python_comment}noarch: generic
  # Useful to leave this on by default, will allow relocating
  # packages that have hard-coded paths in them
  detect_binary_files_with_prefix: true
  # 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.
  # number: 1

requirements:
  build:{build_depends}

  run:{run_depends}

{test_comment}test:
  {entry_comment}commands:
    # You can put test commands to be run here.  Use this to test that the
    # entry points work.
{test_commands}

  # You can also put a file called run_test.lua in the recipe that will be run
  # at test time.

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

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

# Make sure luarocks can see all local dependencies
$PREFIX/bin/luarocks-admin make_manifest --local-tree

# Install
# Rocks aren't located in a standard location, although
# they tend to be top-level or in a rocks/ directory.
# NOTE: we're just picking the first rock we find. If there's
# more than one, specify it manually.
ROCK=$(find . -name "*.rockspec" | sort -n -r | head -n 1)
$PREFIX/bin/luarocks install "$ROCK" --local-tree

# 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.
sm   # Let luarocks know that we've installed a new project
$PREFIX/bin/luarocks-admin make_manifest --local-tree
sQ   # Tell luarocks we've removed the project
$PREFIX/bin/luarocks remove {rockname}
c         C   sw   |  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 ƒd  S(   Nt   luarockst   helpsI   
    Create recipe skeleton for luarocks, hosted at luarocks.org
        t   packagest   nargst   +s1   luarocks packages to create recipe skeletons for.s   --output-dirs5   Directory to write recipes to (default: %(default)s).t   defaultt   .s	   --versions(   Version to use. Applies to all packages.s   --recursivet   actiont
   store_trues=   Create recipes for dependencies if they do not already exist.(   t
   add_parsert   add_argument(   t   reposR   (    (    s=   lib/python2.7/site-packages/conda_build/skeletons/luarocks.pyR   ‡   s$    	c         C   s   t  S(   N(   t   True(   t   package_name(    (    s=   lib/python2.7/site-packages/conda_build/skeletons/luarocks.pyt   package_exists¢   s    c         C   s+   | |  k r t  d | ƒ ‚ n |  | Sd  S(   Ns   Required key %s not in spec(   t	   Exception(   t   spect   k(    (    s=   lib/python2.7/site-packages/conda_build/skeletons/luarocks.pyt   getval¨   s    c         C   s:   d GHd GHd GHd GHd |  GHd GHd GHd GHd GHd GHd  S(   Nt    s)   =========================================s   WARNING:s(   Building a rock referenced to branch %s.s8   This is not a tag. This is dangerous, because rebuildings0   at a later date may produce a different package.s2   Please replace with a tag, git commit, or tarball.(    (   t   branch(    (    s=   lib/python2.7/site-packages/conda_build/skeletons/luarocks.pyt   warn_against_branches¯   s    	c         C   sô   d j  g  |  D] } | j ƒ  r | ^ q ƒ } | d k rZ |  d  d k rZ d |  }  qZ n  |  j d d ƒ j ƒ  }  g  |  D] } | d k ^ qy } x\ t | ƒ D]N \ } } | rž g  |  D] } | ^ q· } | j | d ƒ d j  | ƒ }  Pqž qž W|  S(   NR   t   luai   s   lua-t    s   <>=~(   R   (   t   joint   isalphat   replacet   lowert	   enumeratet   insert(   t   dept   ct   name_without_vert   special_char_testt   it   vt	   split_dep(    (    s=   lib/python2.7/site-packages/conda_build/skeletons/luarocks.pyt
   format_dep¼   s    .c         C   sœ   g  |  D]4 } d j  g  | D] } | j ƒ  r | ^ q ƒ ^ q } g  } d | k rc | j d ƒ n  d | k r | j d ƒ n  t | ƒ r˜ | |  }  n  |  S(   NR   R   R   (   R   R   t   appendt   len(   t   depsR    R!   t	   basenamest
   extra_deps(    (    s=   lib/python2.7/site-packages/conda_build/skeletons/luarocks.pyt   ensure_base_depsÒ   s    AR   c         C   s’  t  d k r d n t  } t j ƒ  } t j ƒ  } i  } t j | ƒ x¬|  rñ|  j ƒ  } | d  d k rx d | j ƒ  n	 | j ƒ  }	 | j | i |	 d 6d d 6d	 d
 6d	 d 6d	 d 6d d 6d d 6d d 6d d 6d d 6d	 d 6d	 d 6d d 6d	 d 6d	 d 6d	 d 6d	 d 6d	 d 6d d 6d	 d 6d d 6d d 6d	 d  6ƒ }
 t	 j
 d! d" | d# g ƒ } | d$ k rvt d% j | ƒ ƒ ‚ n  t | d& ƒ } t | ƒ d' k r§t d( ƒ ‚ n  | d$ |
 d) <t	 j d* d+ t |
 d) g d, t	 j ƒ} | j ƒ  \ } } d- | k rt | j d. d	 ƒ ƒ ‚ n  t j | ƒ } t | d/ ƒ |
 d0 <t | d ƒ |
 d <d	 j g  |
 d D] } | j ƒ  r]| ^ q]ƒ |
 d <t | d1 ƒ } t | d ƒ |
 d <t j j |
 d ƒ d2 } | dN k r6d	 |
 d <t j j |
 d ƒ d2 |
 d
 <d | k rët | d ƒ } t | ƒ r3| |
 d <d	 |
 d <q3qënµ | dO k sV|
 d d  d9 k rëd	 |
 d <d: | k rŒd	 |
 d <t | d: ƒ |
 d <qëd; | k rÆd	 |
 d <t | d; ƒ |
 d <t |
 d ƒ qëd	 |
 d <d< |
 d <t |
 d ƒ n  d= | k rtt | d= ƒ } d> | k r-| d> |
 d <d	 |
 d <n  d  | k rT| d  |
 d  <d	 |
 d <n  d | k rt| d |
 d <qtn  d? | k rF t | d? ƒ } t | ƒ rît g  | D] } t | ƒ ^ q¥ƒ } t j d	 g | ƒ |
 d <|
 d |
 d <qîqF qF Wd@ | k rí| dA k rdB } n | d k r(dC } n  d  } dD | d@ k rO| d@ dD } n[ dE | d@ k rª| | d@ dE k rªdD | d@ dE | k r§| d@ dE | dD } q§qªn  | rít j d	 g g  | j! ƒ  D] } dF | ^ qÉƒ |
 d <qín  |
 d d	 k r%t j d	 g dG |
 d0 g ƒ |
 d <n  t j | ƒ xY| D]Q} | | }
 |
 d } t j" t j j | | ƒ ƒ dH | j ƒ  t j j | | ƒ f GHt# t j j | | dI ƒ dJ ƒ  } | j$ t% j |
   ƒ Wd  QXt# t j j | | dK ƒ dJ ƒ  } | j$ t& j |
   ƒ Wd  QXt# t j j | | dL ƒ dJ ƒ  } | j$ t' ƒ Wd  QXt# t j j | | dM ƒ dJ ƒ  } | j$ t( j |
   ƒ Wd  QXq9Wd  S(P   Nt   linux2t   linuxi   s   lua-s   lua-%st   packagenames   0.0t   versionR   t   filenamet   urlt   md5s   # t   usemd5t   usefilet   usegitt	   usegittagt	   usegitrevt   gittagt   gitrevt   noarch_python_commentt   build_dependst   run_dependst   test_commentt   entry_commentt   test_commandst   home_commentt   homeurlt   Unknownt   licenset   summary_commentt   summaryR   t   downloads
   --rockspeci    s"   Could not download rockspec for {}s
   *.rockspeci   s   Failed to download rockspect   rockspec_fileR   s   -et   stdoutt   ERRORs   ERROR: t   packaget   rocknamet   sourceiÿÿÿÿs   .zips   .tars   .tar.bz2s   .tar.xzs   .tar.gzs   .gits   git:t   tagR   t   mastert   descriptiont   homepaget   dependenciest   buildt   darwint   macosxt   unixt   modulest	   platformss   lua -e "require '%s'"s   lua -e "require '%s'" s   Writing recipe for %s to %ss	   meta.yamlt   ws   build.shs   post-link.shs   pre-unlink.sh(   s   .zips   .tars   .tar.bz2s   .tar.xzs   .tar.gz(   s   .git()   t	   _platformt   ost   getcwdt   tempfilet   mkdtempt   chdirt   popR   t
   setdefaultt
   subprocesst   callR   t   formatR    R)   t   Popent   rockspec_parsert   PIPEt   communicateR   t   jsont   loadsR   R   t   isalnumt   patht   splitextt   splitR   R-   R'   t   INDENTt   Nonet   keyst   makedirst   opent   writet   LUAROCKS_METAt   LUAROCKS_BUILD_SHt   LUAROCKS_POSTLINK_SHt   LUAROCKS_PREUNLINK_SH(   R   t
   output_dirR1   t	   recursiveR   t   cwdt   temp_dirt   package_dictsRL   R0   t   dt   ot   fst   pt   outt   errR   R!   RN   t   extR4   t   descR*   R    t   our_platRX   t   rt   namet   f(    (    s=   lib/python2.7/site-packages/conda_build/skeletons/luarocks.pyt   skeletonizeÞ   sð    		,	6

 




%		.(

$$$$$(   t   __doc__R\   Rc   R^   R    Rj   t   sysR   R[   Rp   Rg   Rv   Rw   Rx   Ry   R   R   R   R   R'   R-   Rq   t   FalseR‹   (    (    (    s=   lib/python2.7/site-packages/conda_build/skeletons/luarocks.pyt   <module>   s&   #2						