
    c!                    (   d Z ddlmZ ddlZddlZddlZddlmZ 	 ddlm	Z	 n# e
$ r	 ddlm	Z	 Y nw xY wddlmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z'm(Z( ddl)m*Z* ddl+m,c m-Z- ddl.m/Z/m0Z0 ddl1m2Z2m3Z3 	 	 	 	 	 	 dNdZ4dOdZ5dPdZ6dOdZ7d Z8d Z9dPdZ:dOd Z;d! Z<d" Z= G d# d$e>          Z?ej@        d%             ZAdQd&ZBd' ZCd( ZDd) ZEdQd*ZFdQd+ZGd, ZHd- ZId. ZJd/ ZKd0 ZLd1 ZMd2 ZNd3 ZOd4 ZPd5 ZQd6 ZRd7 ZSd8 ZTd9 ZUdOd:ZVd; ZWdOd<ZXdOd=ZYdOd>ZZdRd?Z[dPd@Z\dA Z]dOdBZ^dOdCZ_dD Z`dQdEZadRdFZbdSdHZcdTdJZdddKdLe                    e3          dfdMZfdS )Uz#High-level operations on a project.    )absolute_importN)NamedTemporaryFile)TemporaryDirectory)ProjectALL_COMMAND_TYPES)archiver)client)prepare)provide)LocalStateFile)_null_frontend)EnvVarRequirement)CondaEnvRequirement)DownloadRequirement)_hash_algorithms)ServiceRequirement)_remove_env_path)SimpleStatus)
parse_specdefault_platforms_with_current)	conda_api)	is_stringis_dict)build_imageDEFAULT_BUILDER_IMAGEFc                    |rLt           j                            |           s-	 t          j        |            n# t          t
          f$ r Y nw xY wt          | d          }|r|j                            ddg           ||j                            d|           ||j                            d|           ||j                            d|           |j        	                                 |*t           j                            |j        j
                   }|r|                                 t          |j                  d	k    r|j                                         |S )
a  Create a project skeleton in the given directory.

    Returns a Project instance even if creation fails or the directory
    doesn't exist, but in those cases the ``problems`` attribute
    of the Project will describe the problem.

    If the anaconda-project.yml already exists, this simply loads it.

    This will not prepare the project (create environments, etc.),
    use the separate prepare calls if you want to do that.

    Args:
        directory_path (str): directory to contain anaconda-project.yml
        make_directory (bool): True to create the directory if it doesn't exist
        with_anaconda_package (bool): True to add the 'anaconda' package
        name (str): Name of the new project or None to leave unset (uses directory name)
        icon (str): Icon for the new project or None to leave unset (uses no icon)
        description (str): Description for the new project or None to leave unset
        fix_problems (bool): True to always fix problems even if project file existed

    Returns:
        a Project instance
    F)scan_parentspackagesanacondaNnameicondescriptionr   )ospathexistsmakedirsIOErrorOSErrorr   project_file	set_valueuse_changes_without_savingfilenamefix_problems_and_suggestionslenproblemssave)directory_pathmake_directorywith_anaconda_packager    r!   r"   fix_problemsprojects           <lib/python3.11/site-packages/anaconda_project/project_ops.pycreater7   *   s   <  bgnn^<< 	K''''! 	 	 	D	 n5999G A&&zJ<@@@ 5&&vt444 5&&vt444 C&&}kBBB 33555
  I7>>'*>*GHHH /,,...
7! $ 	!!###Ns   8 AAc                 ~    |                      |          }|$|j        D ]}| j                            |           |S )Nr"   )problems_statuserrorsfrontenderror)r5   r"   failedr=   s       r6   _check_problemsr?   n   sP    $$$==F *] 	* 	*E""5))))M    c                 
   t          |           }||S || j                            d|           || j                            d|           || j                            d|           | j                                         t	          | j                  dk    r*| j                                         t          dd          S t          d	d
t          | j                            }| j        	                                 |S )a^  Set simple properties on a project.

    This doesn't support properties which require prepare()
    actions to check their effects; see other calls such as
    ``add_packages()`` for those.

    This will fail if project.problems is non-empty.

    Args:
        project (``Project``): the project instance
        name (str): Name of the project or None to leave unmodified
        icon (str): Icon for the project or None to leave unmodified
        description (str): description for the project or None to leave unmodified

    Returns:
        a ``Status`` instance indicating success or failure
    Nr    r!   r"   r   TzProject properties updated.successr"   Fz!Failed to set project properties.rC   r"   r;   )
r?   r)   r*   r+   r.   r/   r0   r   listload)r5   r    r!   r"   r>   statuss         r6   set_propertiesrH   v   s   $ W%%F  5&&vt444 5&&vt444 C&&}kBBB33555
7! 
!!###D6STTTT e*M%)'*:%;%;= = = 	!!###r@   c                     |                                   t          f}||vr||fz   }t          j        | ||          }|                    |          }|t          |           }|J |S N)provide_whitelistenv_spec_name)r+   r   r
   prepare_without_interaction
status_forr?   )r5   env_var_or_classrL   rK   resultrG   s         r6   _try_requirement_without_commitrQ      s    &&(((,/00 E-1A0DD0CT?LN N NF /00F " !)) !!!Mr@   c                 ~    t          | ||          }|s|                                  n|                                  |S N)rQ   rF   r0   )r5   rO   rL   rG   s       r6   _commit_requirement_if_it_worksrT      s?    ,W6FVVF  	Mr@   c                    | j                                          t          j        | t          f|          }|                    t                    }|t          |           }|J | j                                          |S rJ   )	lock_filer+   r
   rM   r   rN   r?   rF   )r5   rL   rP   rG   s       r6   _apply_lock_file_then_revertrW      s    002220DWCZ?LN N NF 233F " !)) !!! Mr@   c                    |r|s||J t          |           }||S t          ||          }| j                            |          }	|	t	          |	t
                    si }	| j                            ||	           ||	d<   |r||	d<   |r%t          D ]}
|	                    |
d           ||	|<   t          | ||          S )a  Attempt to download the URL; if successful, add it as a download to the project.

    The returned ``Status`` should be a ``RequirementStatus`` for
    the download requirement if it evaluates to True (on success),
    but may be another subtype of ``Status`` on failure. A False
    status will have an ``errors`` property with a list of error
    strings.

    Args:
        project (Project): the project
        env_spec_name (str): environment spec name or None for all environment specs
        env_var (str): env var to store the local filename
        url (str): url to download
        filename (optional, str): Name to give file or directory after downloading
        hash_algorithm (optional, str): Name of the algorithm to use for checksum verification
                                       must be present if hash_value is entered
        hash_value (optional, str): Checksum value to use for verification
                                       must be present if hash_algorithm is entered
    Returns:
        ``Status`` instance
    Nurlr,   rL   )
r?   _path_to_downloadr)   	get_value
isinstancedictr*   r   poprT   )r5   rL   env_varrY   r,   hash_algorithm
hash_valuer>   r$   requirement_hashs              r6   add_downloadre      s    , _
__:___W%%F ]G44D&0066K :*[$"?"? :&&t[999K +"*J 1% 	) 	)EOOE4((((&0N#*7G=YYYYr@   c                 V   t          |           }||S |                     ||t                    }|s$t          dd                    |                    S t          |          dk    sJ |d         }|#t          j        | |f|t          j	                  }||j
        |k    sJ t          j        | ||g	          }|rg| j                            t          ||                     | j                                         | j        g k    sJ | j                                         |S )
a.  Remove file or directory referenced by ``env_var`` from file system and the project.

    The returned ``Status`` will be an instance of ``SimpleStatus``. A False
    status will have an ``errors`` property with a list of error
    strings.

    Args:
        project (Project): the project
        env_spec_name (str): environment spec name or None for all environment specs
        env_var (str): env var to store the local filename
        prepare_result (PrepareResult): result of a previous prepare or None

    Returns:
        ``Status`` instance
    NklassFz#Download requirement: {} not found.rB      r   rK   rL   mode	whitelist)r?   find_requirementsr   r   formatr.   r
   rM   r   PROVIDE_MODE_CHECKrL   	unpreparer)   unset_valuer[   r+   r/   r0   )r5   rL   r`   prepare_resultr>   rc   rG   s          r6   remove_downloadrt     s]     W%%F  ++M7J]+^^K nE7\7c7cdk7l7lmmmm{q    a.K ^ <WP[KXBIB\^ ^ ^
 QN$@M$QQQQw7)LLLF $(():=')R)RSSS779992%%%%!!###Mr@   c                     d}|t          |          k     r/ | ||                   r|dz  }n||= |t          |          k     -d S d S Nr   ri   r.   )	predicateitemsis      r6   _filter_inplacer{   9  si    	A
c%jj. 9U1X 	FAAa	 c%jj.     r@   c                     d}|t          |          k     r. | ||                   ||<   |dz  }|t          |          k     ,d S d S rv   rw   )fry   rz   s      r6   _map_inplacer~   B  s_    	A
c%jj. 1U1X;;a	Q c%jj.     r@   c                       e Zd Zd ZdS )_StatusHolderc                     d | _         d S rS   )rG   )selfs    r6   __init__z_StatusHolder.__init__J  s    r@   N)__name__
__module____qualname__r    r@   r6   r   r   I  s#            r@   r   c              #     K   | j         g k    sJ t                      }| j                                        D ]}|j        ||j        <   t                      }|V  | j                                         t          |           }|	||_
        d S g }| j                                        D ];}|                    |j        d           |j        k    r|                    |           <g }|                                D ] }|| j        vr|                    |           !d | j                                        D             }t          j        | j                  }	|D ]}|j        j        r	 |	                    |j        |j        |j                  }
|j        |
_        nM# t          j        $ r;}t3          dd|j        dt5          |          d          |_
        Y d }~ d S d }~ww xY w| j                            |j        |
|           |D ]}| j                            d|g           | j                                         t          |           }|	||_
        d S d S )	Nc                     g | ]	}|j         
S r   r    .0env_specs     r6   
<listcomp>z/_updating_project_lock_file.<locals>.<listcomp>j      NNNxX]NNNr@   r<   F!Error resolving dependencies for : .rB   	env_specs)r/   r^   r   valueslogical_hashr    r   r)   r+   r?   rG   getappendkeysconda_managernew_conda_managerr<   lock_setenabledresolve_dependenciesconda_packageschannels	platformsenv_spec_hashCondaManagerErrorr   strrV   _set_lock_setrr   )r5   old_logical_hashesenvstatus_holderr>   changed_or_added_envsremoved_env_namesr    all_env_namescondar   es               r6   _updating_project_lock_filer   N  s     r!!!! '')) 8 8'*'738$$!OOM
33555W%%F % '')) . .!!#(D11S5EE 	.!((---"'')) + +w(( 	+$$T***NN73D3K3K3M3MNNNM+W5EFFFE$ O O < 
	O 55c6H#,X[Xeff),)9&& 2   '3EE58XXXs1vvvvAG(H (H (H$ 	 ++CHhNNN! ; ;%%{D&9::::33555W%%F &  && &s   *2FG',/G""G'c                     t          |           }||S |g }|g }|s1|/|| j        vr&d                    |          }t          d|          S t	          |           5 }|| j        j        }	n| j                            d|g          }	|	it                      }	t          | j                            dgg                     dk    rt                      |	d<   | j                            d|g|	           |	                    dg           }
|rd }t          |
          D ]>\  }}t          |          r*t          |                                          dgk    r|} n?|t#                      }nMt#          d	 |
|                             dg           D                       }nt#          d
 |
D                       }g }g g }|D ]i}||
v rt%          |          }||                    |           .|j        |v r                    |j        |f           T|                    |           jt          |          dk    r7d                    |          }t          ddd|z  g          cd d d            S fd}t-          ||
           |r<||
                    d|i           n7|
|         d                             |           n|
                    |           |
|	d<   |	                    dg           }t#          |          }|D ]}||vr|                    |           ||	d<   d d d            n# 1 swxY w Y   |j        t3          | t4          |          }n|                                  |j        }|S )N"Environment spec {} doesn't exist.FrB   r   r   r   r   pipc              3   \   K   | ]'}t          |          t          |          j        V  (d S rS   r   r   r    )r   ds     r6   	<genexpr>z#_update_env_spec.<locals>.<genexpr>  s:      &x&xaktuvkwkw&xz!}}'9&x&x&x&x&x&xr@   c              3   \   K   | ]'}t          |          t          |          j        V  (d S rS   r   r   deps     r6   r   z#_update_env_spec.<locals>.<genexpr>  s:      "b"bCS\]`SaSa"b:c??#7"b"b"b"b"b"br@   , zCould not add packages.zBad package specifications: %s.rD   c                 v    t          |           s| S t          |           j        }D ]\  }}||k    r|c S | S rS   r   )oldr    replaced_namenew_specupdated_specss       r6   replace_specz&_update_env_spec.<locals>.replace_spec  sX    S>> 
c??'D-: $ $) D( $#OOO$Jr@   r   rZ   )r?   r   ro   r   r   r)   rootr\   r^   r.   r   r*   r   	enumerater   rE   r   setr   r   r    joinr~   extendrG   rT   r   rF   )r5   r    r   r   r7   r   r>   problemr   env_dictold_packagespip_idxidxr   old_packages_set	bad_specs	new_specsparsedbad_specs_stringr   new_channelsold_channels_setchannelrG   r   s                           @r6   _update_env_specr     s   W%%F    Dt Dw(( 	D:AA$GGG7CCCC	$W	-	- Q, 
	N+0HH+55{D6IJJH N66 w+55{mRHHIIQN M,J,L,LH[)$..T/BHMMM  ||J33 	cG%l33  S3<< D$4$4$? !GE y#&55  #&&x&x<PWCXC\C\]bdfCgCg&x&x&x#x#x  ""b"b<"b"b"bbb		 	* 	*Cl" __F *  %%%%;"22 *!((&+s);<<<<$$S))))y>>A 	a#yy33,E)JM])]'_a a a_Q, Q, Q, Q, Q, Q, Q, Q,h	 	 	 	 	 	\<000 	+ ?##UI$67777W%e,33I>>>>	***+  ||J33|,, 	- 	-G.. -##G,,,+cQ, Q, Q, Q, Q, Q, Q, Q, Q, Q, Q, Q, Q, Q, Q,f  &0:M]abbb%Ms   HL98B5L99L= L=c                 Z    |J |                                 }t          | |||d          S )a  Attempt to create the environment spec and add it to anaconda-project.yml.

    The returned ``Status`` should be a ``RequirementStatus`` for
    the environment requirement if it evaluates to True (on success),
    but may be another subtype of ``Status`` on failure. A False
    status will have an ``errors`` property with a list of error
    strings.

    Args:
        project (Project): the project
        name (str): environment spec name
        packages (list of str): packages (with optional version info, as for conda install)
        channels (list of str): channels (as they should be passed to conda --channel)

    Returns:
        ``Status`` instance
    NT)r7   )stripr   )r5   r    r   r   s       r6   add_env_specr     s6    $ ::<<DGT8XdKKKKr@   c                    |J t          |           }||S || j        vr&d                    |          }t          d|          S t	          | j                  dk    r&d                    |          }t          d|          S | j        |                             | j                  }t          || j                  }|rt          |           5 }| j	        
                    d|g           ddd           n# 1 swxY w Y   |j        "| j        g k    sJ |                                  n|                                  |j        }|S )af  Remove the environment spec from project directory and remove from anaconda-project.yml.

    Returns a ``Status`` subtype (it won't be a
    ``RequirementStatus`` as with some other functions, just a
    plain status).

    Args:
        project (Project): the project
        name (str): environment spec name

    Returns:
        ``Status`` instance
    Nr   FrB   ri   zEAt least one environment spec is required; '{}' is the only one left.r   )r?   r   ro   r   r.   r$   r1   r   r   r)   rr   rG   r/   r0   rF   )r5   r    r>   r   env_pathrG   r   s          r6   remove_env_specr     s    W%%F 7$$ @6==dCCEw????
7" @Y``aeffEw???? &++G,BCCH h(>??F 	*(11 	B] ,,k4-@AAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B  	*#r))))LLNNNNLLNNN")FMs   C99C= C=c           
         t          |           }||S || j        }|J || j        vr&d                    |          }t	          d|          S | j        |         }	 |                    |           nI# t          $ r<}t	          dd                    |t          |                              cY d}~S d}~ww xY wt	          dd                    ||                    S )a  Export the environment spec as an environment.yml-type file.

    Returns a ``Status`` subtype (it won't be a
    ``RequirementStatus`` as with some other functions, just a
    plain status).

    Args:
        project (Project): the project
        name (str): environment spec name or None for default
        filename (str): file to export to

    Returns:
        ``Status`` instance
    Nr   FrB   zFailed to save {}: {}.Tz#Exported environment spec {} to {}.)r?   default_env_spec_namer   ro   r   save_environment_yml	Exceptionr   )r5   r    r,   r>   r   specr   s          r6   export_env_specr   A  s$    W%%F  -,7$$ @6==dCCEw????T"Dj!!(++++ j j jE7O7V7VW_adefagag7h7hiiiiiiiiij 2W2^2^_cem2n2noooos   A4 4
B:>1B5/B:5B:c                 ,    t          | |||d|          S )aT  Attempt to install packages then add them to anaconda-project.yml.

    If the env_spec_name is None rather than an env name,
    packages are added in the global packages section (to
    all environment specs).

    The returned ``Status`` should be a ``RequirementStatus`` for
    the environment requirement if it evaluates to True (on success),
    but may be another subtype of ``Status`` on failure. A False
    status will have an ``errors`` property with a list of error
    strings.

    Args:
        project (Project): the project
        env_spec_name (str): environment spec name or None for all environment specs
        packages (list of str): packages (with optional version info, as for conda install)
        channels (list of str): channels (as they should be passed to conda --channel)

    Returns:
        ``Status`` instance
    F)r7   r   )r   )r5   rL   r   r   r   s        r6   add_packagesr   f  s     , G]HhuZ]^^^^r@   c                     t                     }||S |J t          |          dk    sJ | j                                        }g }n j                            |d          }|&d                    |          }t          d|          S |g}t           j                                                  }|                    |           t          |          t           j                  dz
  k    sJ t          |          dk    sJ t          j
         j                  }	|D ]i}|                     j                  }
	 t          j                            |
          r|	                    |
||           U# t          j        $ r Y fw xY wt%                     5 } fd	} ||          }|                     j        j                    ||          }t          |          dk    sJ dd
}t-           | j        j        |                    }|D ]}|                    dg           }t-          |          |rd}t/          |          D ]\  }}t1          |          rd|v r|}|6t          |          r|d                             dg i           dg ig|d<   |                    |          d         }t5          fd|           |d                             d|i           t5          fd|           ||d<   t-           | j        j        |                    }||z
  }|D ]}|                    dg           }|rd}t/          |          D ]\  }}t1          |          rd|v r|}|%|                    dt          |          i           nQ||         d                             t          |                     n"|                    t          |                     ||d<   	 ddd           n# 1 swxY w Y   |j                                          |j        S t=           t>          |          }|S )a$  Attempt to remove packages from an environment in anaconda-project.yml.

    If the env_spec_name is None rather than an env name,
    packages are removed from the global packages section
    (from all environments).

    The returned ``Status`` should be a ``RequirementStatus`` for
    the environment requirement if it evaluates to True (on success),
    but may be another subtype of ``Status`` on failure. A False
    status will have an ``errors`` property with a list of error
    strings.

    Args:
        project (Project): the project
        env_spec_name (str): environment spec name or None for all environment specs
        packages (list of str): packages to remove
        pip (bool): Remove packages from pip installed collection if True

    Returns:
        ``Status`` instance
    Nr   r   FrB   ri   r   r   c                     g }| D ]:}j                             d|j        g          }||                    |           ;|S Nr   )r)   r\   r    r   )envs	env_dictsr   r   r5   s       r6   envs_to_their_dictsz,remove_packages.<locals>.envs_to_their_dicts  sW    I / /"/99;:QRR /$$X...r@   c                     |                      dg           }|r7d |D             }t          |          dk    s
J d            |d         d         S d |D             S )Nr   c                 8    g | ]}t          |          d |v |S r   )r   r   s     r6   r   z6remove_packages.<locals>._get_deps.<locals>.<listcomp>  s,    SSSSWS\\SeslSSSSSr@   ri   z!There should only be one pip: keyr   r   c                 0    g | ]}t          |          |S r   r   r   s     r6   r   z6remove_packages.<locals>._get_deps.<locals>.<listcomp>  s#    ???	#????r@   )r   r.   )r   r   _pkgs	pip_dictss       r6   	_get_depsz"remove_packages.<locals>._get_deps  st    LLR00E @SSESSS	9~~*OO,OOOO |E**??u????r@   r   r   c                 ,    t          |           o| v  S rS   r   r   removed_sets    r6   <lambda>z!remove_packages.<locals>.<lambda>  s    Ys^^5Z{HZ0[ r@   c                 ,    t          |           o| v  S rS   r   r   s    r6   r   z!remove_packages.<locals>.<lambda>  s    31VC;DV,W r@   rZ   F) r?   r.   r   r   r   ro   r   rE   remover   r   r<   r$   r1   r#   isdirremove_packagesr   r   r   r)   r   r   r   r   r_   r{   r   rG   rF   rT   r   )r5   rL   r   r   r>   r   unaffected_envsr   r   r   prefixr   r   r   unaffected_env_dictsr   previous_global_depsr   r   r   r   r   pip_packagesnew_global_depsremoved_from_globalrG   r   s   `                         @r6   r   r     st   T W%%F x==1 H ''))##M488 	H:AA-PPG7CCCC5D"7#4#;#;#=#=>>O""3'''''C0A,B,BQ,FGGGGt99q=+W5EFFFE  '011	w}}V$$ A%%fhC%@@@. 	 	 	D	 
%W	-	- H0	 	 	 	 	 ('--	-233322?CC9~~!!!!	@ 	@ 	@ 	@  #99W-A-FC#P#P#PQQ! 	4 	4H $<<
B77Lh--K 4 ), 7 7 & &HCs|| & &"% G<(( = ,33UBK@@@@16},,#/#3#3G#<#<U#CL#$[$[$[$[]ijjjZ(//0EFFFF W W W WYefff'3$$ ii(<(AsKKKLL3oE, 	0 	0H $<<
B77L 
? ), 7 7 & &HCs|| & &"% S ''5H0I0I(JKKKK )%077=P8Q8QRRRR##D)<$=$=>>>#/HZ  	0sH0 H0 H0 H0 H0 H0 H0 H0 H0 H0 H0 H0 H0 H0 H0T  $##,W6IYfgggFMs%   7E>>FF"IP

PPc                     t                     }||S |*t           j                                        d           }nF j                            |d           }|&d                    |          }t          d|          S |g}d  j                                        D             }d}|sXd}	d  j                                        D             }
d }t          |
          t           j                  k    rO j        	                    d	t                                 d
}	 j                            d |            z             n{|D ]x}t          |j                  dk    r^ j        	                    d|j        d	gt                                 d
}	 j                            d|j        d |                       y|	r?                                   j        rJ t#          t%           fd|                    }d
}t'          j         j                  }|D ]}|s|j        j        s|j        j        rW	  j                            d|j        z             |                    |j        |j        |j                  }|j        |_        nH# t&          j        $ r6}t          dd|j        dt=          |          d          cY d }~c S d }~ww xY w|j                            |           }|j        j        d uo|j        j        |j        k    }|s|s j         !                    |j        ||           |re|j        j        rYtE           |j                  }|r" j                            d|j        z              j        |j                 j        j        sJ nB|rn j                            d|j        z             |#                    |j                  }|$                    d          D ]} j                            |           tK           tL          |j                  }|'                     j(                  }tS          j*        |          }|r  j         +                    |j        |           |red
}|r1 j                            d|j        d j         j,        d           n0 j                            d|j        d j         j,        d           |s -                                 |c S |rj|j        J  j         .                    |j        |j                    j                            d|j        d|j        d j         j,        d           d
}Q j                            d|j        z             u|rJ  j                            d|j        z             |r /                                 |rd}nd }t          d
|          S )!Nc                     | j         S rS   r   )r   s    r6   r   z"_update_and_lock.<locals>.<lambda>#  s    #( r@   )keyr   FrB   c                     g | ]	}|j         
S r   r   r   s     r6   r   z$_update_and_lock.<locals>.<listcomp>,  r   r@   c                 B    g | ]}t          |j                  d k    |S )r   )r.   r   r   s     r6   r   z$_update_and_lock.<locals>.<listcomp>3  s0    rrr8UXYaYkUlUlpqUqrhrrrr@   c                  D    d                     t                                S )Nr   )r   r   r   r@   r6   all_platforms_stringz._update_and_lock.<locals>.all_platforms_string5  s    99;==>>>r@   r   Tz Set project platforms list to %sr   r   zSet platforms for z to c                 (    j         | j                 S rS   )r   r    )r   r5   s    r6   r   z"_update_and_lock.<locals>.<lambda>N  s    ):49)E r@   r   z/Updating locked dependencies for env spec %s...r   r   r   z&Updated installed dependencies for %s.z&Changes to locked dependencies for %s:
z)Updated locked dependencies for env spec z in z'Added locked dependencies for env spec zUpdated hash for env spec z;Locked dependencies for env spec %s are already up to date.zEnv spec %s is already locked.zUpdate complete.z Project dependencies are locked.)0r?   sortedr   r   r   ro   r   r.   r)   r*   r   r<   infor   r    r+   r/   rE   mapr   r   r   disabledmissingr   r   r   r   r   r   r   equivalent_torV   r   rW   	diff_fromsplitrQ   r   r$   r1   r   installed_pip_add_pip_packagesbasenamerF   _set_lock_set_hashr0   )r5   rL   updater>   r   r   r   r   	need_savefixed_platformsno_platforms_specsr  r   r   r   lock_set_changedhash_changedrG   diff_stringliner   pip_pkgsr"   s   `                      r6   _update_and_lockr    s(   W%%F  g'..006J6JKKK##M488 	:AA-PPG7CCCC5DNN73D3K3K3M3MNNNMI   rrw7H7O7O7Q7Qrrr	? 	? 	? !""c'*;&<&<< 	m **;8V8X8XYYY"O!!"DG[G[G]G]"]^^^^  m ms}%%* m(22K;3W3Q3S3SU U U&*O$)))#(((ThThTjTjTj*klll 
	..000 '''' EEEEtLLMMD I+W5EFFFE  CO CO B	OS\* B	Ocl.B B	Oq %%&WZ]Zb&bccc 55c6H#,X[Xeff),)9&& 2 q q q#EE^a^f^f^fhklmhnhnhnhn0oq q q q q q q q q q qq $'<#=#=h#G#GG<5TA E*h.DD    1pv 1p!//(MRRR !Zcl3 !Z :'38LLF e(--.VZ]Zb.cddd",SX6?HHHHH ( 8(--.VY\Ya.abbb&.&8&8&F&F$/$5$5d$;$; 8 8D#,11$7777<WFY[^[cddF !XXg&<==F(6v>>H P);;CHhOOO Z$(	! Z#,11136888W=N=W=W=W3Y Z Z Z Z $,11136888W=N=W=W=W3Y Z Z Z  "LLNNN!MMM"  p-999!44SXx?UVVV %%%'*xxx1G1G1GIZIcIcIc'e f f f 		 %%&cfifn&noooo!!"BSX"MNNNN   9(8+>>>>s   AJK&)KKKc                 &    t          | |d          S )aM  Attempt to freeze dependency versions in anaconda-project-lock.yml.

    If the env_spec_name is None rather than a name,
    all env specs are frozen.

    Args:
        project (Project): the project
        env_spec_name (str): environment spec name or None for all environment specs

    Returns:
        ``Status`` instance
    Fr  r  r5   rL   s     r6   lockr"    s     G]5AAAAr@   c                 &    t          | |d          S )a  Attempt to update frozen dependency versions in anaconda-project-lock.yml.

    If the env_spec_name is None rather than a name,
    all env specs are updated.

    If an env is not locked, this updates the installed dependencies but
    doesn't change anything about project configuration (does not save
    the lock file).

    Args:
        project (Project): the project
        env_spec_name (str): environment spec name or None for all environment specs

    Returns:
        ``Status`` instance
    Tr  r   r!  s     r6   r  r    s    " G]4@@@@r@   c                 P   t          |           }||S |C| j                            |d          }|&d                    |          }t	          d|          S | j                            |           t          | t          |          }|r|d}nd|z  }t	          d|          S |S )aQ  Attempt to unfreeze dependency versions in anaconda-project-lock.yml.

    If the env_spec_name is None rather than a name,
    all env specs are unfrozen.

    Args:
        project (Project): the project
        env_spec_name (str): environment spec name or None for all environment specs

    Returns:
        ``Status`` instance
    Nr   FrB   z#Dependency locking is now disabled.z3Dependency locking is now disabled for env spec %s.T)	r?   r   r   ro   r   rV   _disable_lockingrT   r   )r5   rL   r>   r   r   rG   r"   s          r6   unlockr&    s     W%%F  D##M488 	D:AA-PPG7CCCC &&}555,W6I=YYF  	`?KKOR__KDkBBBBr@   c                 h    |/|| j         vr&d                    |          }t          d|          S d S )Nr   FrB   )r   ro   r   )r5   r    r   s      r6   _check_env_spec_namer(    sD     D(99 6==dCCEw????tr@   c                    t          |           }|t          | |          }||S t          |           5 }|| j        j        }n | j                            d|g          }|J |                    |g           }|D ]}	|	|v r|                    |	           fd}
t          |
|           |||<   d d d            n# 1 swxY w Y   |j	        t          | t          |          }n|                                  |j	        }|S )Nr   c                 ,    t          |           o| v  S rS   r   )premovalss    r6   should_keepz,_modify_inherited_field.<locals>.should_keep!  s    !!6h77r@   rZ   )r?   r(  r   r)   r   r\   r   r   r{   rG   rT   r   rF   )r5   r    field	additionsr,  r>   r   r   
old_valuesvaluer-  rG   s       `       r6   _modify_inherited_fieldr2    s    W%%F 5%gt44 
 
%W	-	- % 	(+0HH+55{D6IJJH''' \\%,,
 	) 	)E
" )!!%((((	8 	8 	8 	8 	8 	Z000$/% % % % % % % % % % % % % % %2  &0:M]abbb%Ms   A?CCCc                 (    t          | |d||          S )Nr   )r2  )r5   r    r/  r,  s       r6   _modify_platformsr4  1  s    "7D+y(SSSr@   c                 (    t          | ||g           S )a  Attempt to add platforms the project supports.

    If the env_spec_name is None rather than an env name,
    packages are added in the global platforms section (to
    all environment specs).

    The returned ``Status`` should be a ``RequirementStatus`` for
    the environment requirement if it evaluates to True (on success),
    but may be another subtype of ``Status`` on failure. A False
    status will have an ``errors`` property with a list of error
    strings.

    Args:
        project (Project): the project
        env_spec_name (str): environment spec name or None for all environment specs
        platforms (list of str): platforms to add

    Returns:
        ``Status`` instance
    r/  r,  r4  r5   rL   r   s      r6   add_platformsr9  5  s    * WmySUVVVVr@   c                 (    t          | |g |          S )a  Attempt to remove platforms the project supports.

    If the env_spec_name is None rather than an env name,
    packages are added in the global platforms section (to
    all environment specs).

    The returned ``Status`` should be a ``RequirementStatus`` for
    the environment requirement if it evaluates to True (on success),
    but may be another subtype of ``Status`` on failure. A False
    status will have an ``errors`` property with a list of error
    strings.

    Args:
        project (Project): the project
        env_spec_name (str): environment spec name or None for all environment specs
        platforms (list of str): platforms to remove

    Returns:
        ``Status`` instance
    r6  r7  r8  s      r6   remove_platformsr;  M  s    * WmrIVVVVr@   c                 J   t          |           }|t          | |          }|d |fS d }||j        }|lt          j        | t
          f||          }|                    t
                    }|J |r|j        |j        j	                 }n|t          j        k    rdS d |fS |d fS )Nrj   NN)r?   r(  
env_prefixr
   rM   r   rN   environrc   r`   r   rp   )r5   rL   rs   rk   r>   r>  rP   rG   s           r6   _prepare_env_prefixr@  e  s    W%%F >%g}== f~ J /#.
 &4WH[G^CP:>@ @ @ ""#677!!! 	&(:(BCJJ w11 &#|f~%r@   c                     | ||gS d| ||gS r   r   )rL   
thing_namevarnames      r6   _path_to_per_env_spec_thingrD    s%     AG$$]J@@r@   c                 $    t          | d|          S )N	variablesrD  rL   rC  s     r6   _path_to_variablerI        &}k7KKKr@   c                 $    t          | d|          S )N	downloadsrG  rH  s     r6   r[   r[     rJ  r@   c                 $    t          | d|          S )NservicesrG  rH  s     r6   _path_to_servicerO    s    &}j'JJJr@   c                 B   t          |           }|t          | |          }||S |t                      }d |                     |          D             }|D ]}t	          ||          }||v rj|                    |          }| j                            |          }	|	t          |	t                    s|}	n||	d<   | j        	                    ||	           ||vr| j        	                    |d           | j        
                                 t          dd          S )a  Add variables in anaconda-project.yml, optionally setting their defaults.

    Returns a ``Status`` instance which evaluates to True on
    success and has an ``errors`` property (with a list of error
    strings) on failure.

    Args:
        project (Project): the project
        env_spec_name (str): environment spec name or None for all environment specs
        vars_to_add (list of str): variable names
        defaults (dict): dictionary from keys to defaults, can be empty

    Returns:
        ``Status`` instance
    Nc                 F    h | ]}t          |t                    |j        S r   )r]   r   r`   )r   reqs     r6   	<setcomp>z add_variables.<locals>.<setcomp>  s,    uuuCR\]`bsRtRtuCKuuur@   defaultTz$Variables added to the project file.rB   )r?   r(  r^   requirementsrI  r   r)   r\   r]   r*   r0   r   )
r5   rL   vars_to_adddefaultsr>   present_varsrC  path_to_variablenew_defaultvariable_values
             r6   add_variablesr\    sY     W%%F >%g}==  66uu7+?+?+N+NuuuL C C,]GDDh 	C",,w//K$1;;<LMMN 8Z-M-M 8!,,7y) **+;^LLLLL( 	C  **+;TBBB2XYYYYr@   c                     |                      ||          }t          |          dk    rF|d         }|j        rddlm} |                    ||           d S |                    d|g           d S d S )Nr`   r   keyringrF  )rn   r.   	encryptedanaconda_project.internalr`  unsetrr   )r5   rL   r>  rC  local_statereqsrR  r`  s           r6   _unset_variablerf    s    $$]G$DDD
4yy1} 	<1g= 	< :99999MM*g.....##['$:;;;;;	< 	<r@   c                    t          | ||t          j                  \  }}||s|S t          j        | j                  }|D ]~}t          ||          }|t          | ||||           t          ||          }| j        	                    |           | j        
                                 |
                                 t          dd          S )a)  Remove variables from anaconda-project.yml and unset their values in local project state.

    Returns a ``Status`` instance which evaluates to True on
    success and has an ``errors`` property (with a list of error
    strings) on failure.

    Args:
        project (Project): the project
        env_spec_name (str): environment spec name or None for all environment specs
        vars_to_remove (list of str): variable names
        prepare_result (PrepareResult): result of a previous prepare or None

    Returns:
        ``Status`` instance
    rk   NTz(Variables removed from the project file.rB   )r@  r   rp   r   load_for_directoryr1   rI  rf  r)   rr   r0   r   )	r5   rL   vars_to_removers   r>  rG   rd  rC  rY  s	            r6   remove_variablesrk    s      /w~\c\vwwwZ  &  3G4JKKK!  ,]GDD 	VG]JUUU,]GDD(()9:::!!###2\]]]]r@   c                    t          | ||t          j                  \  }}||S t          j        | j                  }t                      }|                     |t                    D ]}|||j	        <   t          |                                          }	g }
d}d}|D ]o\  }}||	v rN||         j        r#ddlm} |
                    |||           |dz   }9|                    d|g|           |dz   }W|
                    d|z             p|
rt#          d	d
|
          S |dk    r|                                 |dk    rd|j        z  }n|dk    rd}nd||j        |fz  }t#          d|          S )a  Set variables' values in anaconda-project-local.yml.

    Returns a ``Status`` instance which evaluates to True on
    success and has an ``errors`` property (with a list of error
    strings) on failure.

    Args:
        project (Project): the project
        env_spec_name (str): name of env spec to use or None for all
        vars_and_values (list of tuple): key-value pairs
        prepare_result (PrepareResult): result of a previous prepare or None

    Returns:
        ``Status`` instance
    rh  Nrg   r   r_  ri   rF  z*Variable %s does not exist in the project.FzCould not set variables.rD   zValues saved in %s.z$Values saved in the system keychain.z>%d values saved in %s, %d values saved in the system keychain.TrB   )r@  r   PROVIDE_MODE_DEVELOPMENTr   ri  r1   r^   rn   r   r`   r   r   ra  rb  r`  r*   r   r   r0   r,   )r5   rL   vars_and_valuesrs   r>  rG   rd  var_reqsrR  rX  r;   local_state_countkeyring_countrC  r1  r`  r"   s                    r6   set_variablesrr    s     /w/</=4;4TV V VZ   3G4JKKKvvH((>O(PP $ $ #x}}''LFM) R Rl" 	R * 	: >=====J777 - 1%%{G&<eDDD$5$9!!MMFPQQQQ CE7QZ`aaaaq  	A 	U0;3GGKK!# 	UAKK[-{/C]STKDkBBBBr@   c                     t          | ||t          j                  \  }}||S t          j        | j                  }|D ]}t          | ||||           |                                 t          dd          S )a  Unset variables' values in anaconda-project-local.yml.

    Returns a ``Status`` instance which evaluates to True on
    success and has an ``errors`` property (with a list of error
    strings) on failure.

    Args:
        project (Project): the project
        env_spec_name (str): name of env spec to use or None for all
        vars_to_unset (list of str): variable names
        prepare_result (PrepareResult): result of a previous prepare or None

    Returns:
        ``Status`` instance
    rh  NTzVariables were unset.rB   )	r@  r   rp   r   ri  r1   rf  r0   r   )r5   rL   vars_to_unsetrs   r>  rG   rd  rC  s           r6   unset_variablesru  7  s      /w~\c\vwwwZ  3G4JKKK  R R
G[QQQQ3JLLLLr@   c                    |t           vr*t          d|z   dz   t          t                     z             |                                }t	          |           }||S | j                            d|g          }|+t                      }| j                            d|g|           |||<   |d|vr
| j	        |d<   n||d<   |t          |t                    sJ ||d<   |dk    rt          j                            | j        |          }g }	t          j                            |          rt#          j        ||	          }
ni }
t'          |	          dk    rt)          d	d
|	          }|S |                    |
           | j                                         t	          | d
          }|| j                                         |S | j                                         t)          dd          S )aY  Add a command to anaconda-project.yml.

    Returns a ``Status`` subtype (it won't be a
    ``RequirementStatus`` as with some other functions, just a
    plain status).

    Args:
       project (Project): the project
       name (str): name of the command
       command_type (str): choice of `bokeh_app`, `notebook`, `unix` or `windows` command
       command (str): the command line or filename itself
       env_spec_name (str): env spec to use with this command
       supports_http_options (bool): None for leave it alone, otherwise true or false

    Returns:
       a ``Status`` instance
    Invalid command type  choose from Ncommandsr   supports_http_optionsnotebookr   FUnable to add the command.rD   r9   TzCommand added to project file.rB   )r   
ValueErrorreprr   r?   r)   r\   r^   r*   r   r]   boolr#   r$   r   r1   isfilenotebook_analyzerextrasr.   r   r  r+   rF   r0   )r5   r    command_typecommandrL   rz  r>   command_dictnotebook_filer;   r  s              r6   add_commandr  S  s    $ ,, m0<?/QTXYjTkTkklll::<<DW%%F '11:t2DEEL Ivv&&
D'9<HHH!(L 1\) 	E'.'DL$
 $1Z  F/666660E,-z! $W%;WEE7>>-(( 	&-mVDDFFFv;;? 	!%=YbhiiiFMF###33555W2NOOOF X!!###!!###D6VWWWWr@   c                    ||t          dd|z            S |t          t                    dgz   vr*t          d|z   dz   t	          t                    z             ||t          d          t          |           }||S || j        vrt          dd	d
|z  g          S | j                            d|g          }|J |r9| j        	                    d|g           | j        
                    d|g|           t          |                                          }|t          |g          z
  }|dk    r|t          dg          z
  }n|dk    r|t          dg          z
  }||D ]}	||	= |||<   | j                                         t          | d          }|| j                                         |S | j                                         t          dd          S )a  Update attributes of a command in anaconda-project.yml.

    Returns a ``Status`` subtype (it won't be a
    ``RequirementStatus`` as with some other functions, just a
    plain status).

    Args:
       project (Project): the project
       name (str): name of the command
       command_type (str or None): choice of `bokeh_app`, `notebook`, `unix` or `windows` command
       command (str or None): the command line or filename itself; command_type must also be specified

    Returns:
       a ``Status`` instance
    NTz"Nothing to change about command %srB   rw  rx  z=If specifying the command_type, must also specify the commandFzFailed to update command.zNo command '%s' found.rD   ry  unixwindowsr|  r9   z Command updated in project file.)r   rE   r   r}  r~  r?   ry  r)   r\   rr   r*   r   r   r+   rF   r0   )
r5   r    r  r  new_namer>   r  existing_typesconflicting_typesconflictings
             r6   update_commandr    sj   (  e eD7[^b7bddddD!233tf<= m0<?/QTXYjTkTkklll Z< ZXYYYW%%F 7## HE(C%=%D#FH H H 	H '11:t2DEEL### M((*d);<<<&&
H'=|LLL**,,--N&l^)<)<<v >-YK0@0@@		" >-VH= -, 	* 	*K[))%,\"33555W2NOOOF Z!!###!!###D6XYYYYr@   c                    t          |           }||S || j        vr$t          dd                    |                    S | j        |         }|j        s| j                            ddgg           }t          |t                    r@|j        |vr7|	                    |j                   | j        
                    ddg|           | j                            d|g           | j                                         | j        g k    sJ | j                                         t          d	d
                    |                    S )aG  Remove a command from anaconda-project.yml.

    Returns a ``Status`` subtype (it won't be a
    ``RequirementStatus`` as with some other functions, just a
    plain status).

    Args:
       project (Project): the project
       name (string): name of the command to be removed

    Returns:
       a ``Status`` instance
    NFz(Command: '{}' not found in project file.rB   skip_imports	notebooks)rT  ry  Tz(Command: '{}' removed from project file.)r?   ry  r   ro   r{  r)   r\   r]   rE   r   r*   rr   r+   r/   r0   )r5   r    r>   r  skipped_notebookss        r6   remove_commandr    sh    W%%F 7## pE7a7h7him7n7noooot$G  ]#0::NK;Xbd:ee'.. 	]#44	]$$W%5666 **NK+HJ[\\\$$j$%788833555r!!!!2\2c2cdh2i2ijjjjr@   c                    t          |           }||S | j                                        }d}|D ]}|j        |k    r|} n|;t	          ddd|dd                    t          d |                    g          S ||j        }t          |          d	k    sJ d}| 	                    | j
        |
          }	t          |	          dk    rC|	d         }
t          |
t                    r|
j        |k    sJ d}nt	          ddd|z  g          S |s)| j                            t!          ||          |           t#          | ||          S )al  Add a service to anaconda-project.yml.

    The returned ``Status`` should be a ``RequirementStatus`` for
    the service requirement if it evaluates to True (on success),
    but may be another subtype of ``Status`` on failure. A False
    status will have an ``errors`` property with a list of error
    strings.

    Args:
        project (Project): the project
        env_spec_name (str): environment spec name or None for all environment specs
        service_type (str): which kind of service
        variable_name (str): environment variable name (None for default)

    Returns:
        ``Status`` instance
    NFzUnable to add service.zUnknown service type 'z', we know about: r   c                     | j         S rS   r   )ss    r6   r   zadd_service.<locals>.<lambda>.  s    qv r@   rD   ri   r^  r   TzVariable %s is already in use.rZ   )r?   plugin_registrylist_service_typesr    r   r   r
  default_variabler.   rn   r   r]   r   service_typer)   r*   rO  rT   )r5   rL   r  variable_namer>   known_typesfoundknownrequirement_already_existsexisting_requirementsrc   s              r6   add_servicer    s   $ W%%F )<<>>KE  :% 	EE	  E(@(@ ".tyy=M=M{9[9[/\/\/\!^$   	  /.{q    !&#55g6S]j5kk
 !!A% [+A.k#566 	[+|;;;; *.&&,D(H=(X'Y[ [ [ [ & e&&'7}'U'UWcddd*7MQ^____r@   c                 *   t          |           }||S fd|                     |t                    D             }|s$t          dd                                        S t          |          dk    r1t          dd                    t          |                              S |)t          j        | |d	         f|t          j	        
          }||j
        |k    sJ |d	         j        }t          j        | ||g          }|s|S | j                            t          ||                     | j                                         | j        g k    sJ | j                                         t          dd                                        S )a  Remove a service to anaconda-project.yml.

    Returns a ``Status`` instance which evaluates to True on
    success and has an ``errors`` property (with a list of error
    strings) on failure.

    Args:
        project (Project): the project
        env_spec_name (str): environment spec name or None for all environment specs
        variable_name (str): environment variable name for the service requirement
        prepare_result (PrepareResult): result of a previous prepare or None

    Returns:
        ``Status`` instance
    Nc                 @    g | ]}|j         k    s|j        k    |S r   )r  r`   )r   rR  r  s     r6   r   z"remove_service.<locals>.<listcomp>e  sF       },03}0L  r@   rg   Fz+Service '{}' not found in the project file.rB   ri   zeConflicting results, found {} matches, use list-services to identify which service you want to remover   rj   rl   Tz+Removed service '{}' from the project file.)r?   rn   r   r   ro   r.   r
   rM   r   rp   rL   r`   rq   r)   rr   rO  r+   r/   r0   )r5   rL   r  rs   r>   rU  r`   rG   s     `     r6   remove_servicer  P  s     W%%F    00FX0YY  L  mE(U(\(\]j(k(km m m 	m <1 uE*YZ`Z`adeqararZsZsu u u 	u  ^ <WP\]^P_ObKXBIB\^ ^ ^
 QN$@M$QQQQ1o%Gw7)LLLF $$%5mW%M%MNNN33555r!!!!2_2f2fgt2u2uvvvvr@   c                     t          j         |          }t          |j                  |r  j                            |j                   n:                    |j        g            j                            |j                    fd} |t          j
                             j        d                      j        }t          j                            dd                              t          j                  D ]}|rt          j
                            |          nd}t          j
                            t          j
                            ||                    }||k    r                    d           ~|                    |t          j        z             r ||                               d|z             |r%t-                    dk    rt/          d	d
          S t/          dd          S )a#  Blow away auto-provided state for the project.

    This should not remove any potential "user data" such as
    anaconda-project-local.yml.

    This includes a call to ``anaconda_project.prepare.unprepare``
    but also removes the entire services/ and envs/ directories
    even if they contain leftovers that we didn't prepare in the
    most recent prepare() call.

    Args:
        project (Project): the project instance
        prepare_result (PrepareResult): result of a previous prepare

    Returns:
        a ``Status`` instance

    c           	      0   t           j                            |           ruj                            d| z             	 t          j        |            d S # t          $ r4}                    d| dt          |          d           Y d }~d S d }~ww xY wd S )NzRemoving %s.zError removing r   r   )
r#   r$   r   r<   r	  shutilrmtreer   r   r   )dirnamer   r;   r5   s     r6   cleanup_dirzclean.<locals>.cleanup_dir  s    7==!! 	L!!.7":;;;Lg&&&&& L L L'''3q6666JKKKKKKKKKL		L 	Ls   A 
B)BBrN  ANACONDA_PROJECT_ENVS_PATH r   z*Not removing the project directory itself.z/Not removing external environment directory: %sr   TzCleaned.rD   FzFailed to clean everything up.)r
   rq   rE   r;   r<   r	  status_descriptionr   r=   r#   r$   r   r1   r?  r   r  pathsep
expanduserabspathr   
startswithsepr.   r   )r5   rs   rG   r  our_rootbaseapathr;   s   `      @r6   cleanr    s   & w77F&-  F :f78888v01222v8999L L L L L L KW3Z@@AAA %H
;R@@FFrzRR T T+/;rw!!$'''VXt < <==H 	TMMFGGGGh/00 	TKMMKdRSSSS h#f++" hDjPPPPE7W`fggggr@   c                 .    t          j        | ||          S )zMake an archive of the non-ignored files in the project.

    Args:
        project (``Project``): the project
        filename (str): name of a zip, tar.gz, or tar.bz2 archive file

    Returns:
        a ``Status``, if failed has ``errors``
    )r   _archive_project)r5   r,   	pack_envss      r6   archiver    s     $Wh	BBBr@   c                 R    |t                      }t          j        | |||          S )a  Unpack an archive of the project.

    The archive can be untrusted (we will safely defeat attempts
    to put evil links in it, for example), but this function
    doesn't load or validate the unpacked project.

    The target directory must not exist or it's an error.

    project_dir can be None to auto-choose one.

    If parent_dir is non-None, place the project_dir in it. This is most useful
    if project_dir is None.

    Args:
        filename (str): name of a zip, tar.gz, or tar.bz2 archive file
        project_dir (str): the directory to place the project inside
        parent_dir (str): directory to place project_dir within

    Returns:
        a ``Status``, if failed has ``errors``, on success has ``project_dir`` property.

    N)project_dir
parent_dirr<   )r   r   _unarchive_project)r,   r  r  r<   s       r6   	unarchiver    s3    .  $!##&x[U_jrssssr@   .tar.bz2c           
         t          |           }||S t          dd|          }|                                 	 t          | |j                  }	|	s|	t          j        |j                   S t          j        | |j        | j        |z   |||||          }	|	t          j        |j                   S # t          j        |j                   w xY w)a  Upload the project to the Anaconda server.

    The returned status; if successful, has a 'url' attribute with the project URL.

    Args:
        project (``Project``): the project
        private (bool): make project private
        site (str): site alias from Anaconda config
        username (str): Anaconda username
        token (str): Anaconda auth token
        suffix (str): project archive suffix
        log_level (str): Anaconda log level

    Returns:
        a ``Status``, if failed has ``errors``
    NFanaconda_upload_)deleter   suffix)uploaded_basenameprivatesiteusernametoken	log_level)	r?   r   closer  r    r#   r   r	   _upload)
r5   r  r  r  r  r  r  r>   tmp_tarfilerG   s
             r6   uploadr    s    " W%%F  %E:LU[\\\K$+"233 	 		+"####  + 03:<&3H(/%))1&+*35 5 5 
	+"####	+"####s   B1 -*B1 1CTc                     t          j        | |||||          }|r/|r-t          |j        ||          }|rt	          |j                   |S )zwDownload project from Anaconda Server.

    Args:
        project: The project in format <username>/<project_name>
    )r  r  r  r  r  )r  r  )r	   	_downloadr  r,   printr  )	r5   unpackr  r  r  r  r  download_statusunpack_statuss	            r6   downloadr    st     &w3>2<,008-24 4 4O  4/ 4!/":`jkkk 	4-2333r@   rT  	{}:latestc                 D   | j         sd}t          d|          S |dk    r| j        j        }nv|| j         vrmd}|d                    |          z  }|dz  }| j                                         D ]#\  }}|d                    ||j                  z  }$t          d|          S |B| j                            d
d                                          }d                    |          }t                      5 }	t          d           t          j                            |	d          }
t          | |
           t          j                            |	d          }t          |
|           t          d           t!          |||||          }d	d	d	           n# 1 swxY w Y   |S )a7  Build docker image from project.

    Args:
        tag: str Version tag for the docker image (default: latest)
        command: str [Optional] Append the Dockerfile with a RUN statement for the chosen anaconda-project command
        build_args: dict [Optional] Additional arguments passed to docker build
    z_No known run command for this project; try adding a 'commands:' section to anaconda-project.ymlFrB   rT  z"Error setting Docker run command.
z6The command {} is not one of the configured commands.
zAvailable commands are:z
{:>15s}: {}N r  r  z)Archiving project to temporary directory.zproject.tar.gzr5   z5
Starting image build. This may take several minutes.)tagr  builder_image
build_args)ry  r   default_commandr    ro   ry   r"   replacelowerr   r  r#   r$   r   r  r  r   )r5   r  r  r  r  msgkvr    tempdirproject_archiver  build_statuss                r6   	dockerizer  )  s     <oEs;;;;) <).	(	( <3HOOPWXXX(($**,, 	< 	<DAq?))!Q];;;CCEs;;;;
 '|##C,,2244  &&			 :9:::',,w0@AA)))gll7I66/;///FGGG";'*+21>.8	: : :: : : : : : : : : : : : : : :  s   6BFFF)FFNNNNrS   )NNNr   r=  )NNNNr  N)TNNNNN)g__doc__
__future__r   
contextlibr#   r  tempfiler   backports.tempfiler   ImportErroranaconda_project.projectr   r   anaconda_projectr   r	   r
   r   !anaconda_project.local_state_filer   anaconda_project.frontendr   2anaconda_project.requirements_registry.requirementr   =anaconda_project.requirements_registry.requirements.conda_envr   <anaconda_project.requirements_registry.requirements.downloadr   r   ;anaconda_project.requirements_registry.requirements.servicer   :anaconda_project.requirements_registry.providers.conda_envr   'anaconda_project.internal.simple_statusr   anaconda_project.conda_managerr   #anaconda_project.internal.conda_apir   r   rb  r   +anaconda_project.internal.notebook_analyzerinternalr  $anaconda_project.internal.py2_compatr   r   anaconda_project.dockerr   r   r7   r?   rH   rQ   rT   rW   re   rt   r{   r~   objectr   contextmanagerr   r   r   r   r   r   r   r  r"  r  r&  r(  r2  r4  r9  r;  r@  rD  rI  r[   rO  r\  rf  rk  rr  ru  r  r  r  r  r  r  r  r  r  r  ro   r  r   r@   r6   <module>r     sU   * ) & & & & & &     				  ' ' ' ' ' ',5555555 , , ,++++++++, @ ? ? ? ? ? ? ? % % % % % % # # # # # # $ $ $ $ $ $ $ $ $ $ $ $ < < < < < < 4 4 4 4 4 4 P P P P P P ] ] ] ] ] ] \ \ \ \ \ \ Y Y Y Y Y Y Z Z Z Z Z Z W W W W W W @ @ @ @ @ @ 6 6 6 6 6 6 \ \ \ \ \ \ \ \ / / / / / / G G G G G G G G G C C C C C C C C F F F F F F F F  !&A A A AH   + + + +\   ,	 	 	  ,)Z )Z )Z )ZX+ + + +b        F   
 :& :& :&zh h h hVL L L.0 0 0f"p "p "pJ_ _ _ _2[ [ [ [|G? G? G?TB B B A A A(# # #L  3 3 3lT T TW W W0W W W0  @A A AL L LL L LK K K-Z -Z -Z -Z`< < <!^ !^ !^ !^H:C :C :C :CzM M M M8FX FX FX FXRDZ DZ DZ DZN&k &k &kRA` A` A` A`H5w 5w 5w 5wp8h 8h 8hv
C 
C 
C 
Ct t t t8'$ '$ '$ '$T   ( '../DEE	/ / / / / /s   # 11