
    xhe/                         d Z ddlZddlZddlZddlZddlm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ZdS )z:
Tools for converting luarocks packages to conda recipes.
    N)glob)platformz
    - a  
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))
a  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
a  #!/bin/bash

set -o errexit -o pipefail

# 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.
zm# Let luarocks know that we've installed a new project
$PREFIX/bin/luarocks-admin make_manifest --local-tree
zQ# Tell luarocks we've removed the project
$PREFIX/bin/luarocks remove {rockname}
c                     |                      dd          }|                    ddd           |                    dd	d
           |                    dd           |                    ddd           d S )NluarockszI
    Create recipe skeleton for luarocks, hosted at luarocks.org
        )helppackages+z1luarocks packages to create recipe skeletons for.)nargsr   z--output-dirz5Directory to write recipes to (default: %(default)s)..)r   defaultz	--versionz(Version to use. Applies to all packages.z--recursive
store_truez=Create recipes for dependencies if they do not already exist.)actionr   )
add_parseradd_argument)reposr   s     >lib/python3.11/site-packages/conda_build/skeletons/luarocks.pyr   r      s        H @    
 D    
 7     L          c                     dS )NT )package_names    r   package_existsr      s    4r   c                 >    || vrt          d|z            | |         S )NzRequired key %s not in spec)	Exception)specks     r   getvalr      s(    }}59:::Awr   c                 8   t          d           t          d           t          d           t          d           t          d| z             t          d           t          d           t          d           t          d           t          d           d S )N z)=========================================zWARNING:z(Building a rock referenced to branch %s.z8This is not a tag. This is dangerous, because rebuildingz0at a later date may produce a different package.z2Please replace with a tag, git commit, or tarball.)print)branchs    r   warn_against_branchesr!      s    	"III	
5666	"III	*	
4v
=>>>	
DEEE	
<===	
>???	"III	
566666r   c                 z   d                     d | D                       }|dvr| d d         dk    rd| z   } |                     dd                                          } d | D             }t          |          D ]@\  }}|r9d | D             }|                    |d           d                     |          }  nA| S )	Nr   c                 :    g | ]}|                                 |S r   isalpha.0cs     r   
<listcomp>zformat_dep.<locals>.<listcomp>   s%    >>>a!))++>>>>r   )lua   lua- c                     g | ]}|d v S )z<>=~r   r&   s     r   r)   zformat_dep.<locals>.<listcomp>   s    222f222r   c                     g | ]}|S r   r   r&   s     r   r)   zformat_dep.<locals>.<listcomp>   s    (((q(((r   )joinreplacelower	enumerateinsert)depname_without_verspecial_char_testiv	split_deps         r   
format_depr;      s    ww>>3>>>??w&& rr7f3,C
++c2


$
$
&
&C 32c222+,,  1 	((C(((IQ$$$'')$$CE		
 Jr   c                     d | D             }g }d|vr|                     d           d|vr|                     d           t          |          r|| z   } | S )Nc                 L    g | ]!}d                      d |D                       "S )r   c                 :    g | ]}|                                 |S r   r$   r&   s     r   r)   z/ensure_base_deps.<locals>.<listcomp>.<listcomp>   s%    888AIIKK8!888r   )r0   r'   r5   s     r   r)   z$ensure_base_deps.<locals>.<listcomp>   s3    JJJc88S88899JJJr   r*   r   )appendlen)deps	basenames
extra_depss      r   ensure_base_depsrE      su    JJTJJJIJI%   ""*%%%
: !D Kr   r   Fc                    t           dk    rdnt           }t          j                    }t          j                    }i }t          j        |           | r|                                 }|d d         dk    rd|                                z  n|                                }	|                    |i 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
dd
d
dd
ddd
d          }
t          j
        dd|dg          }|dk    rt          d |           t          |d!z             }t          |          d"k    rt          d#          |d         |
d$<   t          j        d%d&t          |
d$         z  gt          j        '          }|                                \  }}d(|v r#t          |                    d)d
                    t'          j        |          }t+          |d*          |
d+<   t+          |d          |
d<   d
                    d, |
d         D                       |
d<   t+          |d-          }t+          |d          |
d<   t          j                            |
d                   d.         }|d/v rad
|
d<   t          j                            |
d                   d.         |
d	<   d|v r)t+          |d          }t          |          r
||
d<   d
|
d<   n|d0v s|
d         d d         d1k    rsd
|
d<   d2|v rd
|
d<   t+          |d2          |
d<   nQd3|v r.d
|
d<   t+          |d3          |
d<   t5          |
d                    nd
|
d<   d4|
d<   t5          |
d                    d5|v rGt+          |d5          }d6|v r|d6         |
d7<   d
|
d8<   d9|v r|d9         |
d9<   d
|
d:<   d;|v r|d;         |
d;<   d<|v rdt+          |d<          }t          |          rEt7          d= |D                       }t8                              d
g|z             |
d<   |
d         |
d<   | d>|v r|d?k    rd@}n|dk    rdA}d }dB|d>         v r|d>         dB         }nJdC|d>         v r@||d>         dC         v r0dB|d>         dC         |         v r|d>         dC         |         dB         }|r=t8                              d
gdD |                                D             z             |
dE<   |
dE         d
k    r+t8                              d
gdF|
d+         z  gz             |
dE<   t          j        |           |D ],}||         }
|
d         }t          j        t          j                            ||                     t?          dG|                                 dHt          j                            ||                      tA          t          j                            ||dI          dJ          5 }|!                    tE          j#        dNi |
           d d d            n# 1 swxY w Y   tA          t          j                            ||dK          dJ          5 }|!                    tI          j#        dNi |
           d d d            n# 1 swxY w Y   tA          t          j                            ||dL          dJ          5 }|!                    tJ                     d d d            n# 1 swxY w Y   tA          t          j                            ||dM          dJ          5 }|!                    tM          j#        dNi |
           d d d            n# 1 swxY w Y   .d S )ONlinux2linuxr+   r,   zlua-%spackagenameversionz0.0filenamer   urlmd5usemd5z# usefileusegit	usegittag	usegitrevgittaggitrevnoarch_python_commentbuild_dependsrun_dependstest_commententry_commentUnknown)test_commandshome_commenthomeurllicensesummary_commentsummaryr   downloadz
--rockspecr   z Could not download rockspec for z
*.rockspec   zFailed to download rockspecrockspec_filer*   z-e)stdoutERRORzERROR: packagerocknamec                 :    g | ]}|                                 |S r   )isalnumr&   s     r   r)   zskeletonize.<locals>.<listcomp>/  s%    GGGa199;;GGGGr   source)z.zipz.tarz.tar.bz2z.tar.xzz.tar.gz)z.gitzgit:tagr    masterdescriptionhomepager]   r\   r`   r_   r^   dependenciesc                 ,    g | ]}t          |          S r   )r;   r?   s     r   r)   zskeletonize.<locals>.<listcomp>\  s    (I(I(ISC(I(I(Ir   builddarwinmacosxunixmodules	platformsc                     g | ]}d |z  S )zlua -e "require '%s'"r   )r'   rs     r   r)   zskeletonize.<locals>.<listcomp>p  s    QQQQ4q8QQQr   r[   zlua -e "require '%s'" zWriting recipe for z to z	meta.yamlwzbuild.shzpost-link.shzpre-unlink.shr   )'	_platformosgetcwdtempfilemkdtempchdirpopr2   
setdefault
subprocesscallr   r   rA   Popenrockspec_parserPIPEcommunicater1   jsonloadsr   r0   pathsplitextsplitr!   rE   INDENTkeysmakedirsr   openwriteLUAROCKS_METAformatLUAROCKS_BUILD_SHLUAROCKS_POSTLINK_SHLUAROCKS_PREUNLINK_SH)r   
output_dirrJ   	recursiver   cwdtemp_dirpackage_dictsrf   rI   dofspouterrr   rj   extrM   descrB   our_platrv   namefs                             r   skeletonizer      sH	    $x//wwYH )++C!!HM HX
 i6,,.. +2"1"+*?*?Hw}}&&W]]__ 	 $${5 B r	
 r $ 4 $ T T " " (   r  !"  #$ "$ $$#'/  
 
< OZWlKLL66HwHHIII 'L())r77a<<9:::U/ D/Ao,>>?

 
 
 ==??Sc>>CKK	266777z# tY//*dI..)wwGG1Y<GGGHH)h'' &%((%gqx((,DDDAiLGMM!E(33B7AjMVU++s88 %"AeH"$AhKH__%! 6 6AhK!#+$VU33(V##!#+$VX66(%ak2222!#+&(%ak222 D  $..DT!!#J/)$&.!D  #I)')#$D  #I) T!!$//D4yy 6'(I(ID(I(I(IJJ%+[["%=%=/"#$_#5- S  i6X $xHH  HW%%7mI.GGDM))4=555Wk :8 DDD"7mK8B9MG 	!'QQ',,..QQQQ" "Ao
 	R#[[D01Z=@AA
 
/
 HSMMM  7 7'"
BGLLT22333W'--//WWrw||JPT7U7UWW	
 	
 	
 "',,z4==sCC 	/qGGM(--1--...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/"',,z4<<cBB 	3aGG%,11q11222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3"',,z4@@#FF 	*!GG()))	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*"',,z4AA3GG 	71GG)055155666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	77 7sH   &%XX	X	%ZZ		Z	<[##['	*['	%]]	]	)r   NF)__doc__r   r|   r   r~   r   sysr   r{   r   r   r   r   r   r   r   r   r   r!   r;   rE   r   r   r   r   <module>r      s     				            % % % % % %	!H/b . 
   8    
7 
7 
7  ,	 	 	f7 f7 f7 f7 f7 f7r   