
@K7]c           @` s)  d  d l  m Z m Z m Z d  d l m 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 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 m Z m Z m Z d d
 l m Z d d l m  Z  d d l! m" Z" d e j# f d     YZ$ d e j% f d     YZ& d e' d e) d  Z* d e' d e) d  Z+ d   Z, e' d e) d  Z- i  a. d d d d e' e' e' d  Z/ e' d  Z0 d d e' e' e' e' d  Z1 d   Z2 e' d  Z3 e' d  Z4 e' e' d  Z5 e' e' e' d d  Z6 d S(    i    (   t   absolute_importt   divisiont   print_function(   t   partialNi   (   t   PY3(   t   get_dict(   t   get_installed_packagest   apply_pin_expressionst
   get_loggert   HashableDictt   string_types(   t   get_env_dependencies(   t	   copy_intot   check_call_envt   rm_rft   ensure_valid_spec(   t   DEFAULT_COMPILERS(   t   CondaBuildException(   t   _load_setup_py_datat   UndefinedNeverFailc           B` s   e  Z d  Z g  Z d e j j d e j j	 d  Z
 d   Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z  Z! d   Z" d   Z# Z$ d   Z% d   Z& d   Z' d   Z( d	   Z) d d
  Z* RS(   s  
    A class for Undefined jinja variables.
    This is even less strict than the default jinja2.Undefined class,
    because it permits things like {{ MY_UNDEFINED_VAR[:2] }} and
    {{ MY_UNDEFINED_VAR|int }}. This can mask lots of errors in jinja templates, so it
    should only be used for a first-pass parse, when you plan on running a 'strict'
    second pass later.

    Note:
        When using this class, any usage of an undefined variable in a jinja template is recorded
        in the (global) all_undefined_names class member.  Therefore, after jinja rendering,
        you can detect which undefined names were used by inspecting that list.
        Be sure to clear the all_undefined_names list before calling template.render().
    c         C` s    t  j j |  | | | |  d  S(   N(   t   jinja2t	   Undefinedt   __init__(   t   selft   hintt   objt   namet   exc(    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyR   (   s    c         O` s   |  j  |  j  S(   N(   t   _return_undefinedt   _undefined_name(   R   t   argst   kwargs(    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyt   <lambda>3   t    c         C` sD   y t  j |  |  SWn) t k
 r? |  j |  j d |  n Xd  S(   Nt   .(   t   objectt   __getattr__t   AttributeErrorR   R   (   R   t   k(    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyR$   7   s    c         C` s   |  j  t    S(   N(   t   _return_valuet   str(   R   (    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyR    ?   R!   c         C` s   |  j  d  S(   Nu    (   R'   (   R   (    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyR    @   R!   c         C` s   |  j  d  S(   Ni    (   R'   (   R   (    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyR    A   R!   c         C` s   |  j  d  S(   Ng        (   R'   (   R   (    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyR    B   R!   c         C` s   |  j  t  S(   N(   R'   t   False(   R   (    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyR    C   R!   c      	   C` s;   t  j j |  j  t  d |  j d |  j d | d |  j  S(   NR   R   R   R   (   R   t   all_undefined_namest   appendR   t   _undefined_hintt   _undefined_objt   _undefined_exception(   R   t   result_name(    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyR   E   s
    	c         C` s   t  j j |  j  | S(   N(   R   R*   R+   R   (   R   t   value(    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyR'   M   s    N(+   t   __name__t
   __module__t   __doc__R*   t   NoneR   t   runtimet   missingt
   exceptionst   UndefinedErrorR   t   __add__t   __radd__t   __mul__t   __rmul__t   __div__t   __rdiv__t   __truediv__t   __rtruediv__t   __floordiv__t   __rfloordiv__t   __mod__t   __rmod__t   __pos__t   __neg__t   __call__t   __getitem__t   __lt__t   __le__t   __gt__t   __ge__t   __complex__t   __pow__t   __rpow__R$   t   __str__t   __repr__t   __unicode__t   __int__t	   __float__t   __nonzero__R   R'   (    (    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyR      s   
a						t   FilteredLoaderc           B` s    e  Z d  Z d   Z d   Z RS(   s   
    A pass-through for the given loader, except that the loaded source is
    filtered according to any metadata selectors in the source text.
    c         C` s"   | |  _  | j |  _ | |  _ d  S(   N(   t   _unfiltered_loadert   list_templatest   config(   R   t   unfiltered_loaderRY   (    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyR   Y   s    	c         C` se   d d l  m } m } |  j j | |  \ } } } | | | |  j  d t |  j j  | | f S(   Ni   (   t   select_linest   ns_cfgt   variants_in_place(   t   metadataR[   R\   RW   t
   get_sourceRY   t   boolt   variant(   R   t   environmentt   templateR[   R\   t   contentst   filenamet   uptodate(    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyR_   ^   s
    (   R1   R2   R3   R   R_   (    (    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyRV   S   s   	s   setup.pyc      
   C` s  d  } t j j t j j t  d  } t j j |  j j d  } t | |  t	 |   } d | d <t j j
 |  j j  r8|  j j | |  j j | g }	 | r | s t d   |	 j d  |	 j d | g  n  | r |	 j d  n  t |	 d | t t j j |  j j d	    }
 t j |
  } Wd  QXn y1 t j | d
 | d | d |  j j d | } Wn` t t f k
 rnJ t k
 r} | rt t  } | j d  qt d j |    n Xt t j j |  j j d   | r| Si  S(   Ns   _load_setup_py_data.pyt   RENDERt   CONDA_BUILD_STATEs1   recipe_dir must be set if from_recipe_dir is Trues   --from-recipe-dirs   --recipe-dirs   --permit-undefined-jinjat   envs    conda_build_loaded_setup_py.jsont   from_recipe_dirt
   recipe_dirt   work_dirt   permit_undefined_jinjas   Reading setup.py failed due to missing modules.  This is probably OK, since it may succeed in later passes.  Watch for incomplete recipe info, though.sT   Could not render recipe - need modules installed in root env.  Import error was "{}"(   R4   t   ost   patht   joint   dirnamet   __file__RY   Rl   R   t   get_environt   isfilet   build_pythont   AssertionErrorR+   t   extendR   t   opent   jsont   loadR   t   load_setup_py_datat	   TypeErrort   OSErrort   ImportErrorR   R1   t   debugR   t   formatR   (   t   mt
   setup_fileRj   Rk   Rm   t   _setuptools_datat   origin_setup_scriptt   dest_setup_scriptRi   R   t   ft   et   log(    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyR{   g   sB    !
$	c      
   C` s;   t  t  } | j d  t |  d | d | d | d | S(   Ns   Deprecation notice: the load_setuptools function has been renamed to load_setup_py_data.  load_setuptools will be removed in a future release.R   Rj   Rk   Rm   (   R   R1   t   warnR{   (   R   R   Rj   Rk   Rm   R   (    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyt   load_setuptools   s    c          C` sP   t  r i d d 6d d 6n
 i d d 6}  t d |    } t j |  SWd  QXd  S(   Nt   rt   modes   utf-8t   encodingt   rbs   package.json(   R   Rx   Ry   Rz   (   t	   mode_dictt   pkg(    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyt   load_npm   s    'c         C` sh  t  } t t  } t  } | rH | rH t j j t j j | |   } n t j j |  j  r t	 } t j
   }	 t j |  j  t j j |  s t j j |  j |  } q n2 d j |  }
 | r | j |
  i  St |
   t j j |  r&t | d   } t j | | j    } Wd  QXn | sDt d j |    n  | rZt j |	  n  | rd| Sd  S(   NsS   Did not find {} file in manually specified location, and source not downloaded yet.R   s!   {} is not a file that can be read(   R)   R   R1   Rn   Ro   t   abspathRp   t   existsRl   t   Truet   getcwdt   chdirt   isabsR   R   t   RuntimeErrorRt   Rx   t   ret   searcht   readR|   R4   (   RY   t	   load_filet   regex_patternRj   Rk   Rm   t   matchR   t
   cd_to_workt   cwdt   messaget   lfile(    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyt   load_file_regex   s2    $	!s   x.x.x.x.x.xt   xc	         C` sX  d }	 | r| r|  j    t |  j j  f }
 |
 t k rK t |
 } n |  j r |  j r t |  d |  j j  \ } } } n[ t |  d |  j j  \ } } } |  j r t |  d |  j j  \ } } } | j |  n  | t |
 <d   | D } | r| r(| j	 |  r(d j
 | |  }	 q| p:| j	 |  } | rt | d  rot | t  ro| d } n t |  } | r| s| rd t |  d	 }	 n  |	 d
 j d |  7}	 qt | | |  }	 qqn  |	 r5| r5| r5t j d j |   } | j |  j    r5t d j |    q5n  |	 d k	 rTd j
 | |	 f  S| S(   sU  dynamically pin based on currently installed version.

    only mandatory input is package_name.
    upper_bound is the authoritative upper bound, if provided.  The lower bound is the the
        currently installed version.
    pin expressions are of the form 'x.x' - the number of pins is the number of x's separated
        by ``.``.
    R!   t   hostt   buildc         S` s3   i  |  ]) } | j  d   d | j  d   d  q S(   t    i   i    (   t   split(   t   .0t   p(    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pys
   <dictcomp>   s   	 R   t   __iter__i    s   >=t   ,s   <{upper_bound}t   upper_bounds   pin_compatible\s*\(\s*["]{}["]s]   Could not get compatibility information for {} package.  Is it one of your host dependencies?N(   R   R	   RY   Ra   t   cached_env_dependenciest   is_crosst   build_is_hostR   Rw   t   getRp   t   hasattrt
   isinstanceR
   R(   R   R   R   t   compileR   t   extract_requirements_textR   R4   (   R   t   package_namet   lower_boundR   t   min_pint   max_pinRm   t   exactt   bypass_env_checkt   compatibilityt   keyt   pinst   _t	   host_pinst   versionst   versiont   check(    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyt   pin_compatible   s@    $!	!
	c         ` s~  d  } | rzt |  d k r+ | d }	 n t |  d k r d  }	 xu | D]j \ }
  t  j    t   j j j    @} | s t    f d   | D  rJ |
  f }	 PqJ qJ Wn  |	 | k ri| |	 d } | r | j   r d  } qw| r<d j | j	   | j   | s!| j
   n t | j    g  } qwd j | j	   t | j   | |   } qz| d d } n  | S(   Ni   i    c         3` s)   |  ] }  |   j  j | k Vq d  S(   N(   RY   Ra   (   R   t   sv(   R^   Ra   (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pys	   <genexpr>  s   R   s   {0} {1}(   R4   t   lent   sett   keysRY   Ra   t   allR   Rp   R   t   build_idR(   t   build_numberR   R   (   R^   t   matching_package_keyst   outputsR   R   R   Rm   t   skip_build_idt   pinR   t   pkg_namet   shared_varst   sp_m(    (   R^   Ra   s8   lib/python2.7/site-packages/conda_build/jinja_context.pyt   pin_subpackage_against_outputs  s0    (	-c      
   C` s   d } t |  d  s3 | r$ | } q t d   ne t |  j j    }	 g  |	 D] }
 |
 d | k rO |
 ^ qO } t |  | |  j | | | | d | } | s | } | r | r t d j |    q n  | S(   s  allow people to specify pinnings based on subpackages that are defined in the recipe.

    For example, given a compiler package, allow it to specify either a compatible or exact
    pinning on the runtime package that is also created by the compiler package recipe
    t   other_outputsso   Bug in conda-build: we need to have info about other outputs in order to allow pinning to them.  It's not here.i    R   s   Didn't find subpackage version info for '{}', which is used in a pin_subpackage expression.  Is it actually a subpackage?  If not, you want pin_compatible instead.N(   R4   R   t
   ValueErrort   listR   R   R   R   (   R^   t   subpackage_nameR   R   R   Rm   t   allow_no_other_outputsR   R   R   R&   R   (    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyt   pin_subpackage.  s"    	)				c         C` s   |  } xQ | j  | j  j d  d g D]0 } y t | |  } PWq& t k
 rU q& q& Xq& Wt | d  r | j | j j d d  d  } n  | S(   Nt   -i    R   t   pythont   nopet   vs2017(   t   platformR   R   t   KeyErrorR   R   Ra   (   t   languageRY   t   compilerR   (    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyt   native_compilerQ  s    &$c         C` s   t  |  |  } d } | j rs | j j d | j  } d j |   } | j j | |  } | j j | d  } n	 | j } d j | | g  } | r d j | | f  } t | d t } n  | S(   s{  Support configuration of compilers.  This is somewhat platform specific.

    Native compilers never list their host - it is always implied.  Generally, they are
    metapackages, pointing at a package that does specify the host.  These in turn may be
    metapackages, pointing at a package where the host is the same as the target (both being the
    native architecture).
    t   target_platforms   {}_compilert   _versionR   R   R   N(	   R   R4   Ra   R   t   subdirR   Rp   R   R)   (   R   RY   Rm   R   R   R   t   language_compiler_key(    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyR   _  s    			c   	      C` s  d } | j  p | j } | d k s0 | d k r? d } | } n | d k rQ d n d } | j r | j j d |  } | j j d	 |  } n  d
 |  k r |  j d
  d } |  j d
  d } | d | d | d
 d
 j |  } n |  d | d | } | S(   s	  Support configuration of Core Dependency Trees.
    We should define CDTs in a single location. The current
    idea is to emit parts of the following to index.json (the
    bits that the solver could make use of) and parts to
    about.json (the other bits).
    "system": {
      "os": {
        "type": "windows", "linux", "bsd", "darwin",
        "os_distribution": "CentOS", "FreeBSD", "Windows", "osx",
        "os_version": "6.9", "10.12.3",
        "os_kernel_version" : "2.6.32",
        "os_libc_family": "glibc",
        "os_libc_version": "2.12",
      }
      "cpu": {
        # Whichever cpu_architecture/cpu_isa we build-out for:
        # .. armv6 is compatible with and uses all CPU features of a Raspberry PI 1
        # .. armv7a is compatible with and uses all CPU features of a Raspberry PI 2
        # .. aarch64 is compatible with and uses all CPU features of a Raspberry PI 3
        "cpu_architecture": "x86", "x86_64",
                            "armv6", "armv7a", "aarch32", "aarch64",
                            "powerpc", "powerpc64",
                            "s390", "s390x",
        "cpu_isa": "nocona", "armv8.1-a", "armv8.3-a",
        # "?" because the vfpu is specified by cpu_architecture + cpu_isa + rules.
        "vfpu": "?",
        "cpu_endianness": "BE", "LE",
      }
      "gpu ?": {
      }
      "compilerflags": {
        # When put into a CDT these should be the base defaults.
        # Package builds can and will change these frequently.
        "CPPFLAGS": "-D_FORTIFY_SOURCE=2",
        "CFLAGS": "-march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -O2 -pipe",
        "CXXFLAGS": "-fvisibility-inlines-hidden -std=c++17 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -O2 -pipe",
        "LDFLAGS": "-Wl,-O1,--sort-common,--as-needed,-z,relro",
        "FFLAGS": "-fopenmp",
        # These are appended to the non-DEBUG values:
        "DEBUG_CFLAGS": "-Og -g -Wall -Wextra -fcheck=all -fbacktrace -fimplicit-none -fvar-tracking-assignments",
        "DEBUG_CXXFLAGS": "-Og -g -Wall -Wextra -fcheck=all -fbacktrace -fimplicit-none -fvar-tracking-assignments",
        "DEBUG_FFLAGS": "-Og -g -Wall -Wextra -fcheck=all -fbacktrace -fimplicit-none -fvar-tracking-assignments",
      }
    }
    t   cos6t   ppc64let   aarch64t   cos7t   64t   x86_64t   i686t   cdt_namet   cdt_archR   i    i   R   (   t	   host_archt   archRa   R   R   Rp   (	   R   RY   Rm   R   R   R   R   t	   ver_buildt   result(    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyt   cdt}  s    /		*c         C` sW   | d k r t  d   n  g  } | rS | rS t |  | |  j j  \ } } } n  | S(   sE  Returns the final list of packages that are listed in host or build.
    This include all packages (including the indirect dependencies) that will
    be installed in the host or build environment. An example usage of this
    jinja function can be::

        requirements:
          host:
            - curl 7.55.1
          run_constrained:
          {% for package in resolved_packages('host') %}
            - {{ package }}
          {% endfor %}

    which will render to::

        requirements:
            host:
                - ca-certificates 2017.08.26 h1d4fec5_0
                - curl 7.55.1 h78862de_4
                - libgcc-ng 7.2.0 h7cc24e2_2
                - libssh2 1.8.0 h9cfc8f7_4
                - openssl 1.0.2n hb7f436b_0
                - zlib 1.2.11 ha838bed_2
            run_constrained:
                - ca-certificates 2017.08.26 h1d4fec5_0
                - curl 7.55.1 h78862de_4
                - libgcc-ng 7.2.0 h7cc24e2_2
                - libssh2 1.8.0 h9cfc8f7_4
                - openssl 1.0.2n hb7f436b_0
                - zlib 1.2.11 ha838bed_2
    R   R   s/   Only host and build dependencies are supported.(   R   R   (   R   R   RY   Ra   (   R   Ri   Rm   R   t   package_namesR   (    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyt   resolved_packages  s    !$c   
      C` sw  t  d |  d t d | d t d |  } t t j  }	 |	 j t  d |  d |   | j d t t d |  d | d | d	 t t	 d |  d | d | d
 t
 d t t d | d | d | d t t j j | j d   d t t |  d | d | d t t |  d | d | d | d t t d | d | d t t d | d | d t t |  d | d | d t d t d |	  | S(   s   
    Return a dictionary to use as context for jinja templates.

    initial_metadata: Augment the context with values from this MetaData object.
                      Used to bootstrap metadata contents via multiple parsing passes.
    R   t   for_envR   t   escape_backslashRa   R{   Rk   Rm   R   R   R   RY   t	   installeds
   conda-metaR   R   R   R   R   R   R   t   timet   datetimet   environ(   Rs   R)   R   t   dictRn   R   t   updateR   R{   R   R   R   R   Ro   Rp   t   host_prefixR   R   R   R   R   R   R   (
   t   initial_metadataRk   RY   Rm   R   R   R   Ra   t   ctxR   (    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyt   context_processor  s:    								(7   t
   __future__R    R   R   t	   functoolsR   Ry   Rn   R   R   R   R   t   conda_interfaceR   R   R   Rs   t   utilsR   R   R   R	   R
   t   renderR   R   R   R   R   t   variantsR   R7   R   R!   R   R   R   t
   BaseLoaderRV   R)   R4   R   R{   R   R   R   R   R   R   R   R   R   R   R   R  (    (    (    s8   lib/python2.7/site-packages/conda_build/jinja_context.pyt   <module>   sL   ("<	,		%	:&	!	B.	