
    e`a                         d dl mZ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	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 ddlmZmZmZmZ ddlmZmZ dd	lmZ d
Z G d de          ZdZerdndZ ej!        "                    e#          Z$erqej!        %                    e$ddd          ej!        %                    e d          fej!        %                    e$ddd          ej!        %                    e d          fgZ&npej!        %                    e$ddd          ej!        %                    e d          fej!        %                    e$ddd          ej!        %                    e d          fgZ& G d de'          Z( e(            Z) G d de'          Z* G d de'          Z+	 	 	 	 	 	 	 	 d8d"Z,d# Z-d$ Z.d9d%Z/d& Z0d' Z1d( Z2	 	 d:d)Z3d* Z4d+Z5d,6                    e5          Z7d-Z8	 	 d;d/Z9d0 Z:d1 Z;d2Z<d3Z=d4Z>d5 Z? G d6 d7e'          Z@dS )<    )absolute_importprint_functionN)contextmanager)datetime)fnmatch   )on_windefault_encodingfind_py_sourceis_32bit)SHEBANG_REGEXreplace_prefix)progressbar)CondaPackExceptionCondaEnvFilepackc                       e Zd ZdZdS )r   z$Internal exception to report to userN)__name__
__module____qualname____doc__     /lib/python3.11/site-packages/conda_pack/core.pyr   r      s        ..Dr   r   z /opt/anaconda1anaconda2anaconda3Scriptsbinscriptswindowsactivate.batdeactivate.batposixactivate
deactivatec                   0    e Zd Zd Zd Zed             ZdS )_Contextc                     d| _         d S )NFis_cliselfs    r   __init__z_Context.__init__3   s    r   c                 |    | j         r t          |dz   t          j                   d S t	          j        |           d S )N
)file)r)   printsysstderrwarningswarn)r+   msgs     r   r4   z_Context.warn6   sA    ; 	#*3:......M#r   c              #   V   K   | j         }	 d| _         d V  || _         d S # || _         w xY w)NTr(   )r+   olds     r   set_cliz_Context.set_cli<   s@      k	DKEEEDKKK#DKs    	(N)r   r   r   r,   r4   r   r8   r   r   r   r&   r&   2   sM               ^  r   r&   c                       e Zd ZdZddZd Zd Zd Zed             Z	e
d             Ze
d	             Ze
d
             Zd Zd ZddZd Z	 	 	 	 	 	 	 ddZdS )r   a  A Conda environment for packaging.

    Use :func:`CondaEnv.from_prefix`, :func:`CondaEnv.from_name`, or
    :func:`CondaEnv.from_default` instead of the default constructor.

    Attributes
    ----------
    prefix : str
        The path to the conda environment.
    files : list of File
        A list of :class:`File` objects representing all files in conda
        environment.

    Examples
    --------
    Package the environment ``foo`` into a zip archive:

    >>> (CondaEnv.from_name("foo")
    ...          .pack(output="foo.zip"))
    "/full/path/to/foo.zip"

    Package the environment ``foo`` into a parcel:

    >>> (CondaEnv.from_prefix("/path/to/envs/foo")
    ...          .pack(format="parcel", parcel_version="2020.09.01"))
    "/full/path/to/foo-2020.09.01.parcel"

    Package the current environment into a ``tar.gz`` archive:

    >>> (CondaEnv.from_default()
    ...          .pack(output="output.tar.gz"))
    "/full/path/to/output.tar.gz"

    Create a CondaEnv object from the current environment, excluding all
    ``*.pyx`` files, except those from ``cytoolz``.

    >>> env = (CondaEnv.from_default()
    ...                .exclude("*.pyx")
    ...                .include("lib/python3.6/site-packages/cytoolz/*.pyx"))
    CondaEnv<'~/miniconda/envs/example', 1234 files>
    Nc                 4    || _         || _        |pg | _        d S N)prefixfiles_excluded_files)r+   r<   r=   excluded_filess       r   r,   zCondaEnv.__init__s   s#    
-3r   c                 4    d| j         t          |           fz  S )NzCondaEnv<%r, %d files>)r<   lenr*   s    r   __repr__zCondaEnv.__repr__x   s    '4;D		*BBBr   c                 *    t          | j                  S r;   )rA   r=   r*   s    r   __len__zCondaEnv.__len__{   s    4:r   c                 *    t          | j                  S r;   )iterr=   r*   s    r   __iter__zCondaEnv.__iter__~   s    DJr   c                 J    t           j                            | j                  S )zThe name of the environment)ospathbasenamer<   r*   s    r   namezCondaEnv.name   s     w,,,r   c                 8     | j         t          |          fi |S )zCreate a ``CondaEnv`` from a named environment.

        Parameters
        ----------
        name : str
            The name of the conda environment.

        Returns
        -------
        env : CondaEnv
        from_prefixname_to_prefix)clsrL   kwargss      r   	from_namezCondaEnv.from_name   s&     s~d33>>v>>>r   c                 r    t           j                            |          }t          |fi |} | ||          S )zCreate a ``CondaEnv`` from a given prefix.

        Parameters
        ----------
        prefix : str
            The path to the conda environment.

        Returns
        -------
        env : CondaEnv
        )rI   rJ   abspathload_environment)rQ   r<   rR   r=   s       r   rO   zCondaEnv.from_prefix   s>     (( 22622s65!!!r   c                 6     | j         t                      fi |S )ztCreate a ``CondaEnv`` from the current environment.

        Returns
        -------
        env : CondaEnv
        rN   )rQ   rR   s     r   from_defaultzCondaEnv.from_default   s$     s~//::6:::r   c                     g }t          | j                  }|j        }|j        }| j        D ].}t	          |j        |          r ||           # ||           /t          | j        ||          S )a  Exclude all files that match ``pattern`` from being packaged.

        This can be useful to remove functionality that isn't needed in the
        archive but is part of the original conda package.

        Parameters
        ----------
        pattern : str
            A file pattern. May include shell-style wildcards a-la ``glob``.

        Returns
        -------
        env : CondaEnv
            A new env with any matching files excluded.
        )listr>   appendr=   r   targetr   r<   r+   patternr=   excludedincludeexcludefs          r   ra   zCondaEnv.exclude   s~      ,--,/ 	 	Aqx)) 







UH555r   c                     t          | j                  }g }|j        }|j        }| j        D ].}t	          |j        |          r ||           # ||           /t          | j        ||          S )a`  Re-add all excluded files that match ``pattern``

        Parameters
        ----------
        pattern : str
            A file pattern. May include shell-style wildcards a-la ``glob``.

        Returns
        -------
        env : CondaEnv
            A new env with any matching files that were previously excluded
            re-included.
        )rZ   r=   r[   r>   r   r\   r   r<   r]   s          r   r`   zCondaEnv.include   s~     TZ  ,/% 	 	Aqx)) 







UH555r   inferc                 z   |	|dk    rd}n|dk    r|                     d          rd}n|                     d          rd}n|                     d          s|                     d          rd}n|                     d	          s|                     d
          rd}no|                     d          rd}nWt          d|z            |dvrt          d|z            |-|                     d          r|dvrt          d|z            d}|,|dk    r&t          j                            | j        |g          }||fS )Nrd   tar.gz.parcelparcelz.zipzipz.tar.gzz.tgzz.tar.bz2z.tbz2tar.bz2z.tartarzUnknown file extension %r>   rk   tgzri   tbz2rh   rf   rj   zUnknown format %r)rf   rl   zInvalid format for parcel %r)endswithr   rI   extsepjoinrL   )r+   outputformats      r   _output_and_formatzCondaEnv._output_and_format   s|   >f//FFwy)) O!(( 	O++ Ovv/F/F O!,, O0H0H O"(( O()Dv)MNNNWWW$%86%ABBBFOOI$>$>...()G&)PQQQF >f00Y^^TY$788Fv~r   c                 8   |pd}|p| j         }|p&t          j                                        d          }|pd}d|v rt	          d|z            d|v rt	          d|z            |dz   |z   }|dz   |z   }t
          j                            ||          }|||fS )Nz/opt/cloudera/parcelsz%Y.%m.%d)rr   el7-z$Parcel names may not have dashes: %sz,Parcel distributions may not have dashes: %s)rL   r   todaystrftimer   rI   rJ   rp   )r+   parcel_rootparcel_nameparcel_versionparcel_distroarcroottripledest_prefixs           r   _parcel_outputzCondaEnv._parcel_output  s    !<%<!.TY'W8>+;+;+D+DJ+D+W+W%.+$%Kk%YZZZ-$%SVc%cddd#n43.gll;88GV++r    F   r   Tc                    ddl m} |                     ||          \  }}|dk    r7|s|rt          d          |                     ||||          \  }}}||dz   }n*d}|r$|                    t          j        j                  nd}t          j        	                    |          r|
st          d|z            |	rt          d	| j        d
|           t          j                    \  }}	 t          j        |d          5 }t          | j        |	          5 } ||||||||          5 }t#          | j        |||          }|D ]}|                    |           |                                 ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   t)          j        ||           n## t,          $ r t          j        |            w xY w|S )a  Package the conda environment into an archive file.

        Parameters
        ----------
        output : str, optional
            The path of the output file. The basename of the output file defaults
            to the basename of the ``dest_prefix`` value, if supplied; otherwise to
            the basename of the environment. The suffix will be determined by the
            output format (e.g. ``my_env.tar.gz``).
        format : {'infer', 'zip', 'tar.gz', 'tgz', 'tar.bz2', 'tbz2', 'tar', 'parcel'}
            The archival format to use. By default this is inferred from the
            output file extension, and defaults to ``tar.gz`` if this is not supplied.
        arcroot : str, optional
            The relative path in the archive to the conda environment.
            Defaults to ''.
        dest_prefix : str, optional
            If present, prefixes will be rewritten to this path before
            packaging. In this case the ``conda-unpack`` script will not be
            generated.
        parcel_root, parcel_name, parcel_version, parcel_distro : str, optional
            (Parcels only) the root directory, name, version, and target distribution
            of the parcel. The name and version will be embedded into parcel metadata.
            The default values are:

            - ``parcel_root``: ``/opt/cloudera/parcels``
            - ``parcel_name``: the base name of the environment directory
            - ``parcel_version``: the current date in ``YYYY.MM.DD`` format.
            - ``parcel_distro``: ``el7``

            It is important that ``parcel_root`` match the directory into which all
            parcels are unpacked on your cluster. Neither ``parcel_name`` nor
            ``parcel_version`` may contain dashes. The final destination of the parcel
            is assumed to be ``parcel_root/parcel_name-parcel_version``, and both
            ``arcroot`` and ``dest_prefix`` are set accordingly. The default filename
            will be ``parcel_name-parcel_version-parcel_distro.parcel``.
        verbose : bool, optional
            If True, progress is reported to stdout. Default is False.
        force : bool, optional
            Whether to overwrite any existing archive at the output path.
            Default is False.
        compress_level : int, optional
            The compression level to use, from 0 to 9. Higher numbers decrease
            output file size at the expense of compression time. Ignored for
            ``format='zip'``. Default is 4.
        n_threads : int, optional
            The number of threads to use. Set to -1 to use the number of cpus
            on this machine. If a file format doesn't support threaded
            packaging, this option will be ignored. Default is 1.
        zip_symlinks : bool, optional
            (``zip`` format only) Symbolic links aren't supported by the Zip standard,
            but are supported by *many* common Zip implementations. If ``True``, symbolic
            links will be stored in the archive. If ``False``, a copy of the linked file
            will be included instead. Choosing ``True`` can avoid storing multiple copies
            of the same file, but the archive *may silently fail* on decompression if the
            ``unzip`` implementation does not support symbolic links. For that reason,
            the default is ``False``.
        zip_64 : bool, optional
            (``zip`` format only) Whether to enable ZIP64 extensions. Default is True.

        Returns
        -------
        out_path : str
            The path to the archived environment.
        r   )archiverh   z2Cannot specify 'dest_prefix'/'arcroot' for parcelsNrg   r   zFile %r already existszPacking environment at z to wb)enabled)compress_levelzip_symlinkszip_64	n_threads)formatsr   rs   r   r   striprI   rJ   sepexistsr0   r<   tempfilemkstempfdopenr   r=   Packeraddfinishshutilmove	Exceptionremove)r+   rq   rr   r}   r   ry   rz   r{   r|   verboseforcer   r   r   r   r   rh   fd	temp_path	temp_filer=   arcpackerrb   s                           r   r   zCondaEnv.pack  s   N 	%$$$$$ 00@@X _g _()]^^^+/+>+>{K?M},^ ,^(K&~)+F4;CgmmBGK000G7>>&!! 	H% 	H$%=%FGGG 	MEt{{{FFKLLL (**I	+2t$$ 
(	 W=== 	( GV0>.:(.+4	6 6 6 ( :=!'S+v!N!N!& * *A"JJqMMMM( ( ( ( ( ( ( ( ( ( ( ( ( ( (	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(
( 
( 
( 
( 
( 
( 
( 
( 
( 
( 
( 
( 
( 
( 
($ K	6****  	 	 	Ii   	 sy   -G F,F,AE>2F>FFFF	F,F	F,F	F, G ,F00G 3F04G  G-r;   )Nrd   )Nrd   r   NNNNNFFr   r   FT)r   r   r   r   r,   rB   rD   rG   propertyrL   classmethodrS   rO   rX   ra   r`   rs   r   r   r   r   r   r   r   I   sA       ( (R4 4 4 4
C C C        - - X- ? ? [? " " ["  ; ; [;6 6 666 6 62   :, , , (/%)+/04"')*(,u u u u u ur   r   c                   (    e Zd ZdZdZ	 	 ddZd ZdS )r   a  A single archive record.

    Parameters
    ----------
    source : str
        Absolute path to the source.
    target : str
        Relative path from the target prefix (e.g. ``lib/foo/bar.py``).
    is_conda : bool, optional
        Whether the file was installed by conda, or comes from somewhere else.
    file_mode : {None, 'text', 'binary', 'unknown'}, optional
        The type of record.
    prefix_placeholder : None or str, optional
        The prefix placeholder in the file (if any)
    sourcer\   is_conda	file_modeprefix_placeholderTNc                 L    || _         || _        || _        || _        || _        d S r;   r   )r+   r   r\   r   r   r   s         r   r,   zFile.__init__  s,     ""4r   c                 (    d| j         d| j        dS )NzFile<z, is_conda=>)r\   r   r*   s    r   rB   zFile.__repr__  s     *.+++t}}}EEr   )TNN)r   r   r   r   	__slots__r,   rB   r   r   r   r   r     sW         'I AE$(5 5 5 5F F F F Fr   r   rd   r   Fr   Tc                    | r|rt          d          |
rt          d           |rt                              |||          }n<| rt                              | ||          }nt                              ||          }|Q|D ]N\  }}|dk    r|                    |          }!|dk    r|                    |          }=t          d|z            |                    ||||||||	|
|||||          S )	a  Package an existing conda environment into an archive file.

    Parameters
    ----------
    name : str, optional
        The name of the conda environment to pack.
    prefix : str, optional
        A path to a conda environment to pack.
        Only one of ``name`` and ``prefix`` should be supplied.
    output : str, optional
        The path of the output file. Defaults to the environment name with a
        suffix determined by the format; e.g. ``my_env.tar.gz``.
    format : {'infer', 'zip', 'tar.gz', 'tgz', 'tar.bz2', 'tbz2', 'tar', 'parcel'}, optional
        The archival format to use. By default, this is inferred from the output
        file extension, and defaults to ``tar.gz`` if ``output`` is not supplied.
    arcroot : str, optional
        The relative path in the archive to the conda environment.
        Defaults to ''.
    dest_prefix : str, optional
        If present, prefixes will be rewritten to this path before packaging.
        In this case the ``conda-unpack`` script will not be generated.
    parcel_root, parcel_name, parcel_version, parcel_distro : str, optional
        (Parcels only) the root directory, name, version, and target
        distribution of the parcel. The name and version will be embedded
        into parcel metadata. The default values are:

        - ``parcel_root``: ``/opt/cloudera/parcels``
        - ``parcel_name``: the base name of the environment directory
        - ``parcel_version``: the current date in ``YYYY.MM.DD`` format.
        - ``parcel_distro``: ``el7``

        It is important that ``parcel_root`` match the directory into which all
        parcels are unpacked on your cluster. Neither ``parcel_name`` nor
        ``parcel_version`` may contain dashes. The final destination of the parcel
        is assumed to be ``parcel_root/parcel_name-parcel_version``, and both
        ``arcroot`` and ``dest_prefix`` are set accordingly. The default filename
        will be ``parcel_name-parcel_version-parcel_distro.parcel``.
    verbose : bool, optional
        If True, progress is reported to stdout. Default is False.
    force : bool, optional
        Whether to overwrite any existing archive at the output path. Default
        is False.
    compress_level : int, optional
        The compression level to use, from 0 to 9. Higher numbers decrease
        output file size at the expense of compression time. Ignored for
        ``format='zip'``. Default is 4.
    zip_symlinks : bool, optional
        (``zip`` format only) Symbolic links aren't supported by the Zip standard,
        but are supported by *many* common Zip implementations. If ``True``, symbolic
        links will be stored in the archive. If ``False``, a copy of the linked file
        will be included instead. Choosing ``True`` can avoid storing multiple copies
        of the same file, but the archive *may silently fail* on decompression if the
        ``unzip`` implementation does not support symbolic links. For that reason,
        the default is ``False``.
    n_threads : int, optional
        The number of threads to use. Set to -1 to use the number of cpus on
        this machine. If a file format doesn't support threaded packaging, this
        option will be ignored. Default is 1.
    zip_64 : bool, optional
        (``zip`` format only) Whether to enable ZIP64 extensions. Default is True.
    filters : list, optional
        A list of filters to apply to the files. Each filter is a tuple of
        ``(kind, pattern)``, where ``kind`` is either ``'exclude'`` or
        ``'include'`` and ``pattern`` is a file pattern. Filters are applied in
        the order specified.
    ignore_editable_packages : bool, optional
        By default conda-pack will error in the presence of editable packages.
        Set to True to skip these checks.
    ignore_missing_files : bool, optional
        Ignore that files are missing that should be present in the conda
        environment as specified by the conda metadata.

    Returns
    -------
    out_path : str
        The path to the archived environment.
    z'Cannot specify both 'name' and 'prefix'zCollecting packages...)ignore_editable_packagesignore_missing_filesNra   r`   zUnknown filter of kind %r)rq   rr   r}   r   ry   rz   r{   r|   r   r   r   r   r   r   )	r   r0   r   rO   rS   rX   ra   r`   r   )rL   r<   rq   rr   r}   r   ry   rz   r{   r|   r   r   r   r   r   r   filtersr   r   envkindr^   s                         r   r   r     sj   j  L L !JKKK (&''' 
O""6<T8L # N N 
 O  :R6J ! L L ##=U9M $ O O $ 	M 	MMD'y  kk'**""kk'**()Dt)KLLL886&# +#1#5#1Y!-f  > > >r   c                    g }t          j         t          j                            | dd                    D ]^}t	          |          5 }t          j        |          }d d d            n# 1 swxY w Y   |d         dk    r|                    |           _t          |          dk    rt          d| z            |sd S t          rdS |d         d	         }|d d
         }d|z  S )N
conda-metazpython-*.jsonrL   pythonr   zBUnexpected failure, multiple versions of python found in prefix %rzLib/site-packagesr   version   zlib/python%s/site-packages)globrI   rJ   rp   openjsonloadr[   rA   r   r	   )r<   pythonsfnfilmetapython_versionmajor_minors          r   find_site_packagesr     s9   GiV\?KKLL ! !"XX 	"9S>>D	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"<8##NN4   
7||a  "=?E"F G G 	G  t  #""QZ	*N !$K'+55s   A((A,	/A,	c           	         t          j         t          j                            | |d                    }t	                      }|D ]}t          j                            |          }t          |          5 }|D ]}|                                }|r*|                    d          s|                    d          rCt          j        	                    t          j                            ||                    }|                    |           s|
                    |           	 d d d            n# 1 swxY w Y   |r>dd                    d t          |          D                       z  }	t          |	          d S )Nz*.pth#importzCannot pack an environment with editable packages
installed (e.g. from `python setup.py develop` or
 `pip install -e`). Editable packages found:

%sr.   c              3       K   | ]	}d |z  V  
dS )z- %sNr   .0ps     r   	<genexpr>z-check_no_editable_packages.<locals>.<genexpr>O  s&       O O! O O O O O Or   )r   rI   rJ   rp   setdirnamer   rstrip
startswithnormpathr   sortedr   )
r<   site_packages	pth_fileseditable_packagespth_filr   pthlinelocationr5   s
             r   check_no_editable_packagesr   :  s   	"',,v}gFFGGI 0 0'//'**']] 	0c 
0 
0{{}}  ts33 tx7P7P 7++BGLL$,G,GHH**622 0%))$///
0	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0  & yy O OV<M5N5N O O OOOP !%%%& &s   4B.D//D3	6D3	c                 
   	 t           j                            dd          }t          j        d                    |          dt          j                                      t                    }n:# t          j	        $ r(}| dnd| z  }t          d|d	|j                  d }~ww xY wt          j        |          }| r<d
 |d         D             }	 ||          }n(# t          $ r t          d| z            w xY w|d         }|S )N	CONDA_EXEcondaz{} info --jsonT)shellr2   zcurrent environmentzenvironment: %rzFailed to determine path to zM. This may be due to conda not being on your PATH. The full error is below:

c                 N    i | ]"}t           j                            |          |#S r   )rI   rJ   rK   )r   es     r   
<dictcomp>z"name_to_prefix.<locals>.<dictcomp>c  s*    @@@Q"'""1%%q@@@r   envsz!Environment name %r doesn't existdefault_prefix)rI   environget
subprocesscheck_outputrr   PIPEdecoder
   CalledProcessErrorr   rq   r   loadsKeyError)rL   	conda_exeinfoexcr   info2env_lkr<   s           r   rP   rP   S  sL   <JNN;88	'(8(?(?	(J(J.2:?L L L!6"233 	 ( < < <)-%%&- 	   *.szz"; < < 	<< JtE )@@%-@@@	QD\FF 	Q 	Q 	Q$%H4%OPPP	Q '(Ms$   A,A/ /B&>#B!!B&C C8c                 L   dD ]}t           j                            | d|          }t           j                            |          r^t	          |          5 }t          j        |          }d d d            n# 1 swxY w Y   	 |d         d         c S # t          $ r Y  d S w xY wd S )N)z	link.jsonzpackage_metadata.jsonr   noarchtype)rI   rJ   rp   r   r   r   r   r   )pkg	file_namerJ   r   r   s        r   read_noarch_typer   n  s    ;  	w||C337>>$ 	d &sy~~& & & & & & & & & & & & & & &H~f----   ttt	 4s$   A55A9	<A9	B
B B c           	      t   i }t          |           5 }|D ]}t          d t          j        |d          D                       }t	          |          dk    rt
          df||d         <   Ut	          |          dk    r|d d         ||d         <   |t          d	          	 d d d            n# 1 swxY w Y   |S )
Nc              3   @   K   | ]}|                     d           V  dS )z"'Nr   )r   xs     r   r   z"read_has_prefix.<locals>.<genexpr>  s,      OO1OOOOOOr   F)r"   r   textr   r      zFailed to parse has_prefix file)r   tupleshlexsplitrA   PREFIX_PLACEHOLDER
ValueError)rJ   outr   r   recs        r   read_has_prefixr  {  s   
C	d Ds 	D 	DDOOD0N0N0NOOOOOC3xx1}}16:CFSQ!"1"gCF !BCCC	DD D D D D D D D D D D D D D D Js   BB--B14B1c           	         ddl m}mm}m} h d}t                      }t          j        |           D ]-}||v s*|                    d          s|                    d          r2 | | |                    r|	                    |           ] | | |                    r|	                    |           t          j
         | |                    D ]\  }}}	 |||           |                    fd|	D                        |D ]6}
 | ||
                    r|	                     |
                     7|s|	s|	                               /|S )Nr   )relpathrp   isfileislink>   .index.unionfs	conda-bld
python.app.conda_lockLauncher.appconda-recipesr   pkgsusers	.nonadmin~z	.DS_STOREc              3   0   K   | ]} |          V  d S r;   r   )r   fn2rp   root2s     r   r   zload_files.<locals>.<genexpr>  s/      ==44s++======r   )os.pathr  rp   r  r  r   rI   listdirrn   r   walkupdate)r<   r  r  r  ignoreresr   rootdirsr=   drp   r  s              @@r   
load_filesr    s   555555555555  F %%Cj   # #<<2;;s++<r{{;/G/G<VDD$$%% 	#GGBKKKKVDD$$%% 	#GGBKKKK%'WTT&"-=-=%>%> # #!dEf--

=====u====== 0 0Avdd4mm,, 0UA/// #E #GGENNN# Jr   c                 
   | rN|                     d          r||dd          z   }n-|                     d          rt          |dd          z   }n|}n|}t          t          j                            ||          |d||          S )Nzsite-packages/   zpython-scripts/   Tr   r   r   )r   BIN_DIRr   rI   rJ   rp   )	is_noarchr   r   _pathr   r   ignoredr\   s           r   managed_filer'    s     ,-- 	"U233Z/FF/00 	uRSSz)FFFFS%((#5#	% % % %r   c                    | d         d         t                    }|dk    rt          d| d         d|d          t          j                            dd	          }t          j                            |          rRt          |          5 }t          j        |          }d d d            n# 1 swxY w Y   fd
|d         D             }nt          t          j                            dd                    5 }d |D             }d d d            n# 1 swxY w Y   t          j                            dd          }	t          j                            |	          r!t          |	          fd|D             }nfd|D             }rd |D             }
| d         D ]}t          j        
                    |          }||
vr|dk    s~|                    d          r||vse|                    t                    rdnd }t          t          j                            ||          |dd |          }|                    |           |S )Nlinkr   r   z"noarch: python package installed (rL   z(), but Python not found in environment ()r   z
paths.jsonc                 .    g | ]}t          fi |S r   r'  )r   rr$  r   r   s     r   
<listcomp>z(load_managed_package.<locals>.<listcomp>  s=     * * * iAAqAA * * *r   pathsr=   c                 6    g | ]}|                                 S r   r   r   rb   s     r   r.  z(load_managed_package.<locals>.<listcomp>  s     ,,,1QWWYY,,,r   
has_prefixc           	      X    g | ]&}t          |g                    |d           R  'S )r   )r'  r   )r   r   r$  r   prefixesr   s     r   r.  z(load_managed_package.<locals>.<listcomp>  s\     H H H<= ")]C 8#+<<2#6#68 8 8 H H Hr   c                 4    g | ]}t          |          S r   r,  )r   r   r$  r   r   s     r   r.  z(load_managed_package.<locals>.<listcomp>  s7     % % % ")]CCC % % %r   c                 V    h | ]&}t           j                            |j                  'S r   rI   rJ   normcaser\   r   is     r   	<setcomp>z'load_managed_package.<locals>.<setcomp>  s*    :::q  **:::r   r  z.pycunknownTr"  )r   r   rI   rJ   rp   r   r   r   r   r  r8  rn   r   r#  r   r[   )r   r<   r   	all_filesnoarch_type
paths_jsonr   r/  r=   r2  seen
fil_normedr   rb   r$  r   r4  s     `           @@@r   load_managed_packagerB    sN   
v,x
 C"3''Kx'I 9]*  "&v,,,"8 9 9 	9 c6<88J	w~~j!! %* 	#IcNNE	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#* * * * * *.* * * "',,sFG4455 	-,,,,,E	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- W\\#v|<<
7>>*%% 	%&z22HH H H H H H HAFH H HEE% % % % % %#% % %E   ::E:::= 	  	 C ))#..J$&& K// ))&11 06@	6Q6Q),)@)@JIId	fc22C$,0IG G GQLs$   B88B<?B<D!!D%(D%z
Conda-managed packages were found without entries in the package cache. This
is usually due to `conda clean -p` being unaware of symlinked or copied
packages. Uncached packages:

{0}z{0}

Continuing with packing, treating these packages as if they were unmanaged
files (e.g. from `pip`). This is usually fine, but may cause issues as
prefixes aren't being handled as robustly.a  
Files managed by conda were found to have been deleted/overwritten in the
following packages:

{0}

This is usually due to `pip` uninstalling or clobbering conda managed files,
resulting in an inconsistent environment. Please check your environment for
conda/pip conflicts using `conda list`, and fix the environment by ensuring
only one version of each package is installed (conda preferred).r4   c           
      F
    t           j                                       st          d z            t           j                             d          }t           j                            |          st          d z            t                     }||st           |           d t                     D             }g }t                      g }i }	t          j	        |          D ]}
|

                    d          rt          t           j                            ||
                    5 }t          j        |          }d d d            n# 1 swxY w Y   |d         d         }t           j                            |          s? fd|d	         D             }|                    |d
         |d         |d         f           nt          | ||          }d |D             }|                    |          }|r||	|d
         |d         f<                       |           |                    |                               t           j                            d|
                     |                    t)          t           j                            ||
          t           j                            d|
          dd d                                          t           j                            dd                     |                    t)          t           j                            |d          t           j                            dd          dd d                      |	r|sg }|	                                D ]\  }}|                    d|z             t-          |          }t/          |          dk    r!|d d         dt/          |          dz
  z  gz   }|                    d |D                        d                    |          }t          t0                              |                    fd|                                D             }d}t4          r|dz   }|d |D             z  }|                     fd|D                        |r|dv rd                    d |D                       }|dk    r3t6                              t:                              |                     n't          t<                              |                    |S )Nz!Environment path %r doesn't existr   z"Path %r is not a conda environmentc                 N    i | ]"}t           j                            |          |#S r   )rI   rJ   r8  r   s     r   r   z$load_environment.<locals>.<dictcomp>  s*    DDDA!!!$$aDDDr   z.jsonr)  r   c           	          g | ]:}|d k    t          t          j                            |          |ddd          ;S )r  TNr<  r"  )r   rI   rJ   rp   )r   rb   r<   s     r   r.  z$load_environment.<locals>.<listcomp>-  s]     I I I!"qK7G7G ""',,vq"9"91t59YP P P7G7G7Gr   r=   rL   r   urlc                 V    h | ]&}t           j                            |j                  'S r   r7  r1  s     r   r;  z#load_environment.<locals>.<setcomp>5  s*    EEEarw''11EEEr   Tr"  historyz- %s %s:r   r   z+ %d othersc              3       K   | ]	}d |z   V  
dS )z    Nr   r   s     r   r   z#load_environment.<locals>.<genexpr>V  s&      661FQJ666666r   r.   c                 "    h | ]\  }}|v	|S r   r   )r   fn_lr   manageds      r   r;  z#load_environment.<locals>.<setcomp>[  s'    MMMbW9L9L9L9L9Lr   )r   r#   r$   )z	conda.batr    r!   c                 X    h | ]'}t           j                            t          |          (S r   )rI   rJ   rp   r#  r1  s     r   r;  z#load_environment.<locals>.<setcomp>b  s(    ;;;q"',,w**;;;r   c              3      K   | ]G}t          |          vt          t          j                            |          |d dd          V  HdS )FNr<  r"  )r   r   rI   rJ   rp   )r   r   rL  r<   s     r   r   z#load_environment.<locals>.<genexpr>d  sw       I I
 >!+<+<+G+G bgll61--$)- )	+ + +
 ,H+G+G+GI Ir   )r4   raisec              3       K   | ]	}d |z  V  
dS )z- %s=%r   %sNr   r9  s     r   r   z#load_environment.<locals>.<genexpr>l  s'      BBA^a/BBBBBBr   r4   )rI   rJ   r   r   rp   r   r   r  r   r  rn   r   r   r   r[   rB  
differencer  extendr   r   itemsr   rA   _missing_files_errorrr   r	   contextr4   _uncached_warning_uncached_error)r<   on_missing_cacher   r   
conda_metar   r=  r=   uncachedmissing_filesrJ   r   r   r   	new_filestargetsnew_missingpackageskeyvalue	unmanagedfnamesrL  s   `                     @r   rV   rV   
  s    7>>&!! O !Dv!MNNNfl33J7>>*%% P !E!NOOO 'v..M )A "6=999
 EDF1C1CDDDIEeeGHM
:&& "/ "/==!! !	/bgll:t4455 &y~~& & & & & & & & & & & & & & & v,x(C7>>#&& 	<I I I I&*7mI I I	 ftIU LMMMM0v}1:< <	 FE9EEEG!,,Y77K M BMtF|T)_=>NN7###LL###KK\488999LLbgll:t<< gll<>>'+15(,	. . . / / / KK\955666	LLbgll:y99gll<;;#)- $	& & & ' ' '  	H1 	H'--// 	7 	7JCOOJ,---5MME5zzA~~bqb	]c%jj1n%E$FFOO66666666699X&& !5!<!<X!F!FGGG NMMMIOO$5$5MMMI 1F JII;;F;;;;I	LL I I I I I
 $I I I I I I  G$(99999BBBBBBBv%%LL*11(;;<<<<$_%;%;H%E%EFFFLs   /EE	E	c                     t          j        t          | t           j                  }|                    d          }|r|                     |          dk    r| dfS |                                \  }}}|                    |          ru|                    d          	                    d          d         }d||                    d          }	| 
                    ||	                    d                    } | dfS | dfS )zRewrite a shebang header to ``#!usr/bin/env program...``.

    Returns
    -------
    data : bytes
    fixed : bool
        Whether the file was successfully fixed in the rewrite.
    utf-8r   F/z#!/usr/bin/env T)rematchr   	MULTILINEencodecountgroupsr   r   r   replace)
datar\   r<   shebang_matchprefix_bshebang
executableoptionsexecutable_namenew_shebangs
             r   rewrite_shebangrw  u  s     H]D",??M}}W%%H ::h!##;'4';';'='=$W  ** 	(//88>>sCCBGOO3B?3:>>'3J3J3JLK<<););G)D)DEED:;r   c                 J   t          | d          5 }|                                }ddd           n# 1 swxY w Y   t          j        |          }dD ]}||v rd||<   d|v rd|d         v rd|d         d<   t          j        |dd          }|                                |fS )	zRemove absolute paths in conda-meta that reference local install.

    These are unnecessary for install/uninstall on the destination machine.r-  N)extracted_package_dirpackage_tarball_full_pathr   r)  r   T)indent	sort_keys)r   readr   r   dumpsrk  )r   rb   originalro  fieldr   s         r   rewrite_conda_metar    s     
fc		 a6688               :hDG  D==DK~~(d6l22!#VX
*T$$
7
7
7C::<<s   266a;  {{
  "components": [
    {{
      "name": "{parcel_name}",
      "pkg_version": "{parcel_version}",
      "version": "{parcel_version}"
    }}
  ],
  "extraVersionInfo": {{
    "baseVersion": "{parcel_version}",
    "fullVersion": "{parcel_version}-{parcel_distro}",
    "patchCount": "0"
  }},
  "groups": [],
  "name": "{parcel_name}",
  "packages": [
{parcel_packages}
  ],
  "provides": [
    "spark-plugin"
  ],
  "schema_version": 1,
  "scripts": {{
    "defines": "conda_env.sh"
  }},
  "setActiveSymlink": true,
  "users": {{}},
  "version": "{parcel_version}"
}}zJ    {{
      "name": "{name}",
      "version": "{version}-{build}"
    }}a  {shebang}
{prefixes_py}

_prefix_records = [
{prefix_records}
]

if __name__ == '__main__':
    import os
    import argparse
    parser = argparse.ArgumentParser(
            prog='conda-unpack',
            description=('Finish unpacking the environment after unarchiving.'
                         'Cleans up absolute prefixes in any remaining files'))
    parser.add_argument('--version',
                        action='store_true',
                        help='Show version then exit')
    args = parser.parse_args()
    # Manually handle version printing to output to stdout in python < 3.4
    if args.version:
        print('conda-unpack {version}')
    else:
        script_dir = os.path.dirname(__file__)
        new_prefix = os.path.abspath(os.path.dirname(script_dir))
        for path, placeholder, mode in _prefix_records:
            update_prefix(os.path.join(new_prefix, path), new_prefix,
                          placeholder, mode=mode)
c                 T    	 |                      d           dS # t          $ r Y dS w xY w)Nre  FT)r   UnicodeDecodeError)ro  s    r   is_binary_filer    s@    Gu   tts    
''c                   *    e Zd ZddZd ZddZd ZdS )	r   Nc                 l    || _         || _        || _        |d u| _        || _        g | _        g | _        d S r;   )r<   r   desthas_destrh   r4  r_  )r+   r<   r   r   rh   s        r   r,   zPacker.__init__  s<    	#4/r   c                    |j         t          |j        d          rXt          |j                  \  }}| j                            |           | j                            |j        ||j                   n%| j        	                    |j        |j                   d S |j         dvrt          d|j         z            t          j                            |j                  s$t          j                            |j                  r'| j        	                    |j        |j                   d S |j         }|j        }| j        s+|dk    s%|dk    ra|j                            t$                    rBt'          |j        d          5 }|                                }d d d            n# 1 swxY w Y   nI| j        	                    |j        |j                   | j                            |j        ||f           d S |dk    r"| j        }t/          |          r
t0          rd}nd}|dk    r| j        rt3          |||| j                  }ne|dk    r9|j                            t$                    rt7          ||j        |          \  }}nd}|s"| j                            |j        ||f           | j                            |j        ||j                   d S )	Nzconda-meta/*.json)r   binaryr<  zunknown file_mode: %rr<  r   rbr  F)r   r   r\   r  r   r_  r[   r   	add_bytesr   r   rI   rJ   isdirr  r   r  r   r#  r   r}  r4  r<   r  r	   r   r  rw  )r+   r/   r   ro  r   placeholderr   fixeds           r   r   z
Packer.add  s   $ >!t{$788 ;.t{;;	T$$T***&&t{CEEEE  dk:::F^#@@@4t~EFFFW]]4;'' 	27>>$++F+F 	LT[$+666FN	-] 
	)##&  T[%;%;G%D%D dk4(( "Cxxzz" " " " " " " " " " " " " " " LT[$+666M  $+{I!FGGGF	!!+Kd## # )
 !)I"		!!} P%dI{DINN&&4;+A+A'+J+J&"1$["Q"QKD%%!E PM(($+{I)NOOOt{D$+>>>>>s    F!!F%(F%Fc                    t          j        dd          }	 |                    |           |                                 t	          j        |j                  }|r"t	          j        |j        |j        dz             | j	        
                    |j        |           t	          j        |j                   d S # t	          j        |j                   w xY w)NwF)modedeleteI   )r   NamedTemporaryFilewritecloserI   statrL   chmodst_moder   r   unlink)r+   fpathftextrs  r   sts         r   _write_text_filezPacker._write_text_fileI  s    )s5AAA	 IIeIIKKK""B 72:#5666LSXu---IchBIchs   BB9 9Cc                     ddl m} | j        rt          j                            t          ddd          }t          j                            dd          }| j                            ||           | j        	                    dd          \  }}|
                    dd          \  }}d	                    d
 | j        D                       }t                              ||||          }	t          j                            dd          }|                     ||	d           d S t          d | j        D                       }
| j        r|
s(t"          D ] \  }}| j                            ||           !| j        rd S t$          rd}t'          j        t*          dz             nd}t'          j        t*          dz             d	                    fd| j        D                       }t/          t          j                            t          d                    5 }|                                }d d d            n# 1 swxY w Y   t2                              ||||          }t$          rdnd}|                     t          j                            t*          |          |d           t$          r`t4          rdnd}t7          j        d|          }| j                            |t          j                            t*          d                     d S d S )Nr   )__version__r   r"   rh   r   zconda_env.shrv   z,
c              3   8   K   | ]}t          j        di |V  d S )Nr   )_parcel_package_templaterr   r   s     r   r   z Packer.finish.<locals>.<genexpr>_  sP       )A )A-. *B)H)M)M1)M)M )A )A )A )A )A )Ar   )rz   r{   parcel_packagesr|   zparcel.jsonFc              3   .   K   | ]}|d          dk    V  dS )rL   r   Nr   )r   r  s     r   r   z Packer.finish.<locals>.<genexpr>j  s+      DD&	W,DDDDDDr   z#!python.exez\\python\d.\dz#!/usr/bin/env pythonz/pythonc              3   l   K   | ].}                     |d                    t          |          V  /dS )r   N)ri  repr)r   r   python_patterns     r   r   z Packer.finish.<locals>.<genexpr>~  s\       $G $G+9+?+?!+E+E$GDGG $G $G $G $G $G $Gr   zprefixes.py)rr  prefix_recordsprefixes_pyr   zconda-unpack-script.pyzconda-unpackTz
cli-32.exez
cli-64.exe
setuptoolszconda-unpack.exe)r   r  rh   rI   rJ   rp   _current_dirr   r   r   rsplitr_  _parcel_json_templaterr   r  anyr  _scriptsr	   rh  compiler#  r4  r   r}  _conda_unpack_templater   pkg_resourcesresource_filename)r+   r  srcdstrz   	parcel_vdr{   r|   r  parcel_json	has_condar   r\   rr  r  r   r  scriptscript_nameexecli_exer  s                        @r   r   zPacker.finishU  sj   !!!!!! ; 	',,|YJJC',,v~66CLS#&&&%)[%6%6sA%>%>"K,5,<,<S!,D,D)NM#jj )A )A26-)A )A )A A AO/66;FTGVER 7 T TK ',,v}55C!!#{E:::F DDdmDDDDD	 	1) 	1"* 1 1  0000 = 	F 	=$G  Z2B(BCCNN-GZ)(;<<N  $G $G $G $GT] $G $G $G G G "',,|];;<< 	%((**K	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% (..w>L;F7B / D D
 39L..nbgll7K@@&$OOO 	Q"*<,,C#5lCHHGLWbgll7<N&O&OPPPPP	Q 	Qs   H99H= H=NN)F)r   r   r   r,   r   r  r   r   r   r   r   r     sc           H? H? H?T
  
  
  
 :Q :Q :Q :Q :Qr   r   )NNNrd   r   NNNNNFFr   r   FTNFFr;   r  )r4   FF)A
__future__r   r   r   r   rI   r  rh  r   r   r   r1   r   r3   
contextlibr   r   r   compatr	   r
   r   r   r4  r   r   	_progressr   __all__r   r   r   r#  rJ   r   __file__r  rp   r  objectr&   rU  r   r   r   r   r   rP   r   r  r  r'  rB  rW  rr   rV  rT  rV   rw  r  r  r  r  r  r   r   r   r   <module>r     su   6 6 6 6 6 6 6 6   				     				       



   % % % % % %             F F F F F F F F F F F F 3 3 3 3 3 3 3 3 " " " " " " =	 	 	 	 	 	 	 	"  
())5wx((	 	7lIy.QQg~668lIyBRSSg'788:;HH
 lIw
KKgz224lIwMMg|4467H    v   ( (**{ { { { {v { { {|	F F F F F6 F F F> 6=!%'+,0#CG05#v> v> v> v>r6 6 66& & &2   6
 
 
    B KO% % % %&/ / /d.
 /5f_.E.E 	D  PU*/h h h hV  >  & >
  B  ZQ ZQ ZQ ZQ ZQV ZQ ZQ ZQ ZQ ZQr   