
S]c           @@  s  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l 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! j" Z" d d l# m$ Z$ m% Z% d d l& j' j( Z( d d l) m* Z* d j+   Z, d   Z- e. e. d d d d d  Z0 d d  Z1 d d d d  Z2 d d  Z3 d   Z4 d   Z5 d d d d  Z6 d d  Z7 d   Z8 d   Z9 d  e: f d!     YZ; e j< d"    Z= d#   Z> d$   Z? d%   Z@ d&   ZA d'   ZB d(   ZC d)   ZD d*   ZE d+   ZF d,   ZG d-   ZH d.   ZI d/   ZJ d0   ZK d1   ZL d2   ZM d3   ZN d4   ZO d5   ZP d6   ZQ d d7  ZR d8   ZS d d9  ZT d d:  ZU d d;  ZV d d d<  ZW d d d d=  ZX d>   ZY d d?  ZZ d d@  Z[ dA   Z\ dB   Z] d d dC  Z^ d d d d d dD  Z_ d S(E   s#   High-level operations on a project.i    (   t   absolute_importN(   t   Projectt   ALL_COMMAND_TYPES(   t   archiver(   t   client(   t   prepare(   t   provide(   t   LocalStateFile(   t   _null_frontend(   t   EnvVarRequirement(   t   CondaEnvRequirement(   t   DownloadRequirement(   t   _hash_algorithms(   t   ServiceRequirement(   t   _remove_env_path(   t   SimpleStatus(   t
   parse_spect   default_platforms_with_current(   t	   is_strings   
# project-local contains your personal configuration choices and state
/anaconda-project-local.yml

# Files autocreated by Python
__pycache__/
*.pyc
*.pyo
*.pyd

# Notebook stuff
.ipynb_checkpoints/

# Spyder stuff
/.spyderproject
c         C@  sq   t  j j |  d  } t  j j |  sm y/ t j | d d   } | j t  Wd  QXWqm t k
 ri qm Xn  d  S(   Ns   .projectignoret   ws   utf-8(	   t   ost   patht   joint   existst   codecst   opent   writet   _default_projectignoret   IOError(   t   project_directoryt   filenamet   f(    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   _add_projectignore_if_none6   s    c         C@  sP  | rG t  j j |   rG y t  j |   WqG t t f k
 rC qG Xn  t |   t |   } | ry | j j	 d g   n  | d k	 r | j j	 d |  n  | d k	 r | j j	 d |  n  | d k	 r | j j	 d |  n  | j j   | d k rt  j j | j j  } n  | r'| j   n  t | j  d k rL| j j   n  | S(   s  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
        empty_environment (bool): True to create an empty base environment
        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
    t   packagest   namet   icont   descriptioni    N(   R   R   R   t   makedirsR   t   OSErrorR    R   t   project_filet	   set_valuet   Nonet   use_changes_without_savingR   t   fix_problems_and_suggestionst   lent   problemst   save(   t   directory_patht   make_directoryt   empty_environmentR"   R#   R$   t   fix_problemst   project(    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   create@   s.    
c         C@  sI   |  j  d |  } | d  k	 rE x$ | j D] } |  j j |  q( Wn  | S(   NR$   (   t   problems_statusR)   t   errorst   frontendt   error(   R3   R$   t   failedR8   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   _check_problems   s
    c         C@  s   t  |   } | d	 k	 r | S| d	 k	 r> |  j j d |  n  | d	 k	 r` |  j j d |  n  | d	 k	 r |  j j d |  n  |  j j   t |  j  d k r |  j j   t d t	 d d  St d t
 d d d t |  j   } |  j j   | Sd	 S(
   s^  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
    R"   R#   R$   i    t   successs   Project properties updated.s!   Failed to set project properties.R6   N(   R:   R)   R'   R(   R*   R,   R-   R.   R   t   Truet   Falset   listt   load(   R3   R"   R#   R$   R9   t   status(    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   set_properties   s"    c         C@  s   |  j    t f } | | k r/ | | f } n  t j |  d | d | } | j |  } | d  k r t |   } | d  k	 s t  n  | S(   Nt   provide_whitelistt   env_spec_name(   R*   R
   R   t   prepare_without_interactiont
   status_forR)   R:   t   AssertionError(   R3   t   env_var_or_classRC   RB   t   resultR@   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   _try_requirement_without_commit   s    
	c         C@  s3   t  |  | |  } | s% |  j   n
 |  j   | S(   N(   RI   R?   R.   (   R3   RG   RC   R@   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   _commit_requirement_if_it_works   s
    
c         C@  sx   |  j  j   t j |  d t f d | } | j t  } | d  k rg t |   } | d  k	 sg t  n  |  j  j	   | S(   NRB   RC   (
   t	   lock_fileR*   R   RD   R
   RE   R)   R:   RF   R?   (   R3   RC   RH   R@   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   _apply_lock_file_then_revert   s    c         C@  s  | r | s* | d k r$ | d k s* t  t |   } | d k	 rF | St | |  } |  j j |  }	 |	 d k s t |	 t  r i  }	 |  j j | |	  n  | |	 d <| r | |	 d <n  | r x t	 D] }
 |	 j
 |
 d  q W| |	 | <n  t |  | d | S(   s  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
    t   urlR   RC   N(   R)   RF   R:   t   _path_to_downloadR'   t	   get_valuet
   isinstancet   dictR(   R   t   popRJ   (   R3   RC   t   env_varRM   R   t   hash_algorithmt
   hash_valueR9   R   t   requirementt   _hash(    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   add_download   s"    *
c         C@  s?  t  |   } | d k	 r | S|  j | | d t } | sV t d t d d j |   St |  d k sn t  | d } | d k r t	 j
 |  d | f d | d	 t j } n  | d k s | j | k s t  t	 j |  | d
 | g } | r;|  j j t | |   |  j j   |  j g  k s+t  |  j j   n  | S(   s.  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
    t   klassR;   R$   s#   Download requirement: {} not found.i   i    RB   RC   t   modet	   whitelistN(   R:   R)   t   find_requirementsR   R   R=   t   formatR,   RF   R   RD   R   t   PROVIDE_MODE_CHECKRC   t	   unprepareR'   t   unset_valueRN   R*   R-   R.   (   R3   RC   RS   t   prepare_resultR9   RV   R@   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   remove_download  s&    
$!c         C@  sG   d } x: | t  |  k  rB |  | |  r8 | d 7} q	 | | =q	 Wd  S(   Ni    i   (   R,   (   t	   predicatet   itemst   i(    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   _filter_inplaceM  s
    c         C@  sA   d } x4 | t  |  k  r< |  | |  | | <| d 7} q	 Wd  S(   Ni    i   (   R,   (   R   Rd   Re   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   _map_inplaceV  s    t   _StatusHolderc           B@  s   e  Z d    Z RS(   c         C@  s   d  |  _ d  S(   N(   R)   R@   (   t   self(    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   __init__^  s    (   t   __name__t
   __module__Rj   (    (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyRh   ]  s   c      	   c@  sT  |  j  g  k s t  t   } x' |  j j   D] } | j | | j <q. Wt   } | V|  j j	   t
 |   } | d  k	 r | | _ d  Sg  } xE |  j j   D]4 } | j | j d   | j k r | j |  q q Wg  } x3 | j   D]% } | |  j k r | j |  q q Wg  |  j j   D] } | j ^ q"}	 t j d |  j  }
 x | D] } | j j rSy. |
 j | j | j | j  } | j | _ WnB t j k
 r} t d t d d | j t |  f  | _ d  SX|  j j | j | |	  qSqSWx$ | D] } |  j j  d | g  qW|  j j	   t
 |   } | d  k	 rP| | _ n  d  S(   NR7   R;   R$   s(   Error resolving dependencies for %s: %s.t	   env_specs(!   R-   RF   RQ   Rm   t   valuest   logical_hashR"   Rh   R'   R*   R:   R)   R@   t   gett   appendt   keyst   conda_managert   new_conda_managerR7   t   lock_sett   enabledt   resolve_dependenciest   conda_packagest   channelst	   platformst   env_spec_hasht   CondaManagerErrorR   R=   t   strRK   t   _set_lock_setR`   (   R3   t   old_logical_hashest   envt   status_holderR9   t   changed_or_added_envst   removed_env_namesR"   t   env_spect   all_env_namest   condaRu   t   e(    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   _updating_project_lock_fileb  sJ    			%% c         @  s  t  |   } | d  k	 r | S| d  k r1 g  } n  | d  k rF g  } n  | r | d  k	 r | |  j k r d j |  } t d t d |  Sn  t |   3} | d  k r |  j j } n} |  j j	 d | g  } | d  k r4t
   } t |  j j	 d g g    d k rt   | d <n  |  j j d | g |  n  | j d g   }	 t d   |	 D  }
 g  } g    g  } x} | D]u } | |	 k rqun  t |  } | d  k r| j |  qu| j |
 k r  j | j | f  qu| j |  quWt |  d k r/d	 j |  } t d t d d
 d d | g  S  f d   } t | |	  x | D] } |	 j |  qRW|	 | d <| j d g   } t |  } x* | D]" } | | k r| j |  qqW| | d <Wd  QX| j d  k rt |  t d | } n |  j   | j } | S(   Ns"   Environment spec {} doesn't exist.R;   R$   Rm   Rz   i    R!   c         s@  s*   |  ]  } t  |  r t |  j Vq d  S(   N(   R   R   R"   (   t   .0t   dep(    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pys	   <genexpr>  s    s   , s   Could not add packages.R6   s   Bad package specifications: %s.c         @  sJ   t  |   s |  St |   j } x$   D] \ } } | | k r& | Sq& W|  S(   N(   R   R   R"   (   t   oldR"   t   replaced_namet   new_spec(   t   updated_specs(    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   replace_spec  s    Ry   RC   (   R:   R)   Rm   R]   R   R=   R   R'   t   rootRO   RQ   R,   R   R(   Rp   t   setR   Rq   R"   R   Rg   R@   RJ   R
   R?   (   R3   R"   R!   Ry   R4   R9   t   problemR   t   env_dictt   old_packagest   old_packages_sett	   bad_specst	   new_specsR   t   parsedt   bad_specs_stringR   t   addedt   new_channelst   old_channels_sett   channelR@   (    (   R   s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   _update_env_spec  sp    			$


	c         C@  s7   | d k	 s t  | j   } t |  | | | d t S(   s  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
    R4   N(   R)   RF   t   stripR   R<   (   R3   R"   R!   Ry   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   add_env_spec  s    c         C@  s7  | d k	 s t  t |   } | d k	 r. | S| |  j k r_ d j |  } t d t d |  St |  j  d k r d j |  } t d t d |  S|  j | j |  j	  } t
 |  } | r3t |    } |  j j d | g  Wd QX| j d k r|  j g  k st  |  j   q3|  j   | j } n  | S(   sf  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
    s"   Environment spec {} doesn't exist.R;   R$   i   sE   At least one environment spec is required; '{}' is the only one left.Rm   N(   R)   RF   R:   Rm   R]   R   R=   R,   R   R/   R   R   R'   R`   R@   R-   R.   R?   (   R3   R"   R9   R   t   env_pathR@   R   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   remove_env_spec  s*    
c         C@  s   t  |   } | d k	 r | S| d k r4 |  j } n  | d k	 sF t  | |  j k rw d j |  } t d t d |  S|  j | } y | j |  Wn5 t	 k
 r } t d t d d j | t
 |    SXt d t d d j | |   S(   s  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
    s"   Environment spec {} doesn't exist.R;   R$   s   Failed to save {}: {}.s#   Exported environment spec {} to {}.N(   R:   R)   t   default_env_spec_nameRF   Rm   R]   R   R=   t   save_environment_ymlt	   ExceptionR}   R<   (   R3   R"   R   R9   R   t   specR   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   export_env_specE  s    &c         C@  s   t  |  | | | d t S(   sT  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
    R4   (   R   R=   (   R3   RC   R!   Ry   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   add_packagesj  s    c         @  s  t     } | d
 k	 r | S| d
 k	 s. t  t |  d k sF t  | d
 k rj   j j   } g  } n   j j | d
  } | d
 k r d j |  } t d t	 d |  S| g } t
   j j    } | j |  t |  t   j  d k s t  t |  d k st  t j d   j  } x` | D]X } | j   j  }	 y) t j j |	  rq| j |	 |  n  Wq1t j k
 rq1Xq1Wt    .}
   f d   } | |  } | j   j j  | |  } t |  d k st  t   j j j d g    } xL | D]D } | j d g   } t |   t  f d	   |  | | d <qWt   j j j d g    } | | } x= | D]5 } | j d g   } | j t
 |   | | d <qWWd
 QX|
 j d
 k	 r  j   |
 j St   t d | } | S(   s  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

    Returns:
        ``Status`` instance
    i    s"   Environment spec {} doesn't exist.R;   R$   i   R7   c         @  sR   g  } xE |  D]= }   j  j d | j g  } | d  k	 r | j |  q q W| S(   NRm   (   R'   RO   R"   R)   Rq   (   t   envst	   env_dictsR   R   (   R3   (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   envs_to_their_dicts  s    R!   c         @  s   t  |   o |    k S(   N(   R   (   R   (   t   removed_set(    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   <lambda>  t    NRC   (    R:   R)   RF   R,   Rm   Rn   Rp   R]   R   R=   R>   t   removeRs   Rt   R7   R   R/   R   t   isdirt   remove_packagesR|   R   Rq   R'   R   R   Rf   t   extendR@   R?   RJ   R
   (   R3   RC   R!   R9   R   t   unaffected_envsR   R   R   t   prefixR   R   R   t   unaffected_env_dictst   previous_global_depsR   R   t   new_global_depst   removed_from_globalR@   (    (   R3   R   s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyR     s`    )		%

c      	   @  se  t     } | d  k	 r | S| d  k rI t   j j   d d   } nL   j j | d   } | d  k r d j |  } t d t d |  S| g } g    j j   D] } | j	 ^ q } t }	 | st }
 g    j j   D]! } t
 | j  d k r | ^ q } d   } t
 |  t
   j  k r]  j j d t    t }
   j j d	 |    nq xn | D]f } t
 | j  d k rd  j j d
 | j	 d g t    t }
   j j d | j	 |   f  qdqdW|
 r  j     j st  t t   f d   |   } t }	 qn  t j d   j  } x| D]} | sX| j j sX| j j ryE   j j d | j	  | j | j | j | j  } | j | _  Wn9 t j! k
 r} t d t d d | j	 t" |  f  SX| j j# |  } | j j  d  k	 o| j j  | j  k } | s | r  j$ j% | j	 | |  | r| j j rt&   | j	  } | r}  j j d | j	  n    j | j	 j j skt  n | r  j j d | j	  | j' | j  } x* | j( d  D] }   j j |  qWn  t)   t* | j	  } | rkt }	 | rE  j j d | j	   j$ j+ f  qk  j j d | j	   j$ j+ f  n  | s  j,   | Sq&| r| j  d  k	 st    j$ j- | j	 | j     j j d | j	 | j    j$ j+ f  t }	 q&  j j d | j	  q4| st    j j d | j	  q4W|	 r=  j.   n  | rLd } n d } t d t d |  S(   Nt   keyc         S@  s   |  j  S(   N(   R"   (   R   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyR     R   s"   Environment spec {} doesn't exist.R;   R$   i    c           S@  s   d j  t    S(   Ns   , (   R   R   (    (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   all_platforms_string  s    Rz   s    Set project platforms list to %sRm   s   Set platforms for %s to %sc         @  s     j  |  j S(   N(   Rm   R"   (   R   (   R3   (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyR   -  R   R7   s/   Updating locked dependencies for env spec %s...s(   Error resolving dependencies for %s: %s.s&   Updated installed dependencies for %s.s&   Changes to locked dependencies for %s:s   
s2   Updated locked dependencies for env spec %s in %s.s0   Added locked dependencies for env spec %s to %s.s)   Updated hash for env spec %s to %s in %s.s;   Locked dependencies for env spec %s are already up to date.s   Env spec %s is already locked.s   Update complete.s    Project dependencies are locked.(/   R:   R)   t   sortedRm   Rn   Rp   R]   R   R=   R"   R,   Rz   R'   R(   R   R<   R7   t   infoR*   R-   RF   R>   t   mapRs   Rt   Ru   t   disabledt   missingRw   Rx   Ry   Ro   R{   R|   R}   t   equivalent_toRK   R~   RL   t	   diff_fromt   splitRI   R
   t   basenameR?   t   _set_lock_set_hashR.   (   R3   RC   t   updateR9   R   R   R   R   R   t	   need_savet   fixed_platformst   no_platforms_specsR   R   Ru   R   t   lock_set_changedt   hash_changedR@   t   diff_stringt   lineR$   (    (   R3   s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   _update_and_lock  s    !	%7	
'
!
		c         C@  s   t  |  | d t S(   sM  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
    R   (   R   R=   (   R3   RC   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   lock  s    c         C@  s   t  |  | d t S(   s  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
    R   (   R   R<   (   R3   RC   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyR     s    c         C@  s   t  |   } | d k	 r | S| d k	 rn |  j j | d  } | d k rn d j |  } t d t d |  Sn  |  j j |  t	 |  t
 |  } | r | d k r d } n
 d | } t d t d |  S| Sd S(   sQ  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
    s"   Environment spec {} doesn't exist.R;   R$   s#   Dependency locking is now disabled.s3   Dependency locking is now disabled for env spec %s.N(   R:   R)   Rm   Rp   R]   R   R=   RK   t   _disable_lockingRJ   R
   R<   (   R3   RC   R9   R   R   R@   R$   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   unlock  s     	
c         C@  sE   | d  k	 r= | |  j k r= d j |  } t d t d |  Sd  Sd  S(   Ns"   Environment spec {} doesn't exist.R;   R$   (   R)   Rm   R]   R   R=   (   R3   R"   R   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   _check_env_spec_name  s    c         @  s:  t  |   } | d  k r* t |  |  } n  | d  k	 r: | St |    } | d  k rd |  j j } n* |  j j d | g  } | d  k	 s t  | j | g   } x- | D]% }	 |	 | k r q q | j	 |	  q W  f d   }
 t
 |
 |  | | | <Wd  QX| j d  k r#t |  t d | } n |  j   | j } | S(   NRm   c         @  s   t  |   o |    k S(   N(   R   (   t   p(   t   removals(    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   should_keep  s    RC   (   R:   R)   R   R   R'   R   RO   RF   Rp   Rq   Rf   R@   RJ   R
   R?   (   R3   R"   t   fieldt	   additionsR   R9   R   R   t
   old_valuest   valueR   R@   (    (   R   s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   _modify_inherited_field  s.    

	c         C@  s   t  |  | d | |  S(   NRz   (   R   (   R3   R"   R   R   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   _modify_platforms	  s    c         C@  s   t  |  | d | d g  S(   s  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   (   R   (   R3   RC   Rz   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   add_platforms  s    c         C@  s   t  |  | d g  d | S(   s  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
    R   R   (   R   (   R3   RC   Rz   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   remove_platforms%  s    c         C@  s   t  |   } | d  k r* t |  |  } n  | d  k	 r@ d  | f Sd  } | d  k	 r^ | j } n  | d  k r t j |  d t f d | d | } | j t  } | d  k	 s t  | r | j	 | j
 j } q | t j k r d Sd  | f Sn  | d  f S(   NRB   RC   RZ   (   NN(   R:   R)   R   t
   env_prefixR   RD   R
   RE   RF   t   environRV   RS   R   R^   (   R3   RC   Ra   RZ   R9   R   RH   R@   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   _prepare_env_prefix=  s&    
c         C@  s*   |  d  k r | | g Sd |  | | g Sd  S(   NRm   (   R)   (   RC   t
   thing_namet   varname(    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   _path_to_per_env_spec_thing[  s    
c         C@  s   t  |  d |  S(   Nt	   variables(   R   (   RC   R   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   _path_to_variableb  s    c         C@  s   t  |  d |  S(   Nt	   downloads(   R   (   RC   R   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyRN   f  s    c         C@  s   t  |  d |  S(   Nt   services(   R   (   RC   R   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   _path_to_servicej  s    c   
      C@  s?  t  |   } | d k r* t |  |  } n  | d k	 r: | S| d k rR t   } n  d   |  j |  D } x | D] } t | |  } | | k r | j |  } |  j j |  }	 |	 d k s t	 |	 t  r | }	 n
 | |	 d <|  j j
 | |	  qr | | k rr |  j j
 | d  qr qr W|  j j   t d t d d  S(   s  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
    c         S@  s(   h  |  ] } t  | t  r | j  q S(    (   RP   R	   RS   (   R   t   req(    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pys	   <setcomp>  s   	 t   defaultR;   R$   s$   Variables added to the project file.N(   R:   R)   R   RQ   t   requirementsR   Rp   R'   RO   RP   R(   R.   R   R<   (
   R3   RC   t   vars_to_addt   defaultsR9   t   present_varsR   t   path_to_variablet   new_defaultt   variable_value(    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   add_variablesn  s*    	
c         C@  sw   |  j  | d | } t |  d k rs | d } | j r] d d l m } | j | |  qs | j d | g  n  d  S(   NRS   i    (   t   keyringR   (   R\   R,   t	   encryptedt   anaconda_project.internalR   t   unsetR`   (   R3   RC   R   R   t   local_statet   reqsR   R   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   _unset_variable  s    
	c   	      C@  s   t  |  | | d t j \ } } | d k	 r8 | r8 | St j |  j  } xx | D]p } t | |  } | d k	 r t |  | | | |  n  t | |  } |  j	 j
 |  |  j	 j   | j   qQ Wt d t d d  S(   s)  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
    RZ   R;   R$   s(   Variables removed from the project file.N(   R   R   R^   R)   R   t   load_for_directoryR/   R   R   R'   R`   R.   R   R<   (	   R3   RC   t   vars_to_removeRa   R   R@   R   R   R   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   remove_variables  s    !c         C@  s  t  |  | | d t j \ } } | d k r1 | St j |  j  } t   } x* |  j | d t	 D] } | | | j
 <qb Wt | j    }	 g  }
 d } d } x | D] \ } } | |	 k r| | j r d d l m } | j | | |  | d } q-| j d | g |  | d } q |
 j d |  q W|
 rPt d t d	 d
 d |
  S| d k ri| j   n  | d k rd | j } n+ | d k rd } n d | | j | f } t d t d	 |  Sd S(   s  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
    RZ   RY   i    (   R   i   R   s*   Variable %s does not exist in the project.R;   R$   s   Could not set variables.R6   s   Values saved in %s.s$   Values saved in the system keychain.s>   %d values saved in %s, %d values saved in the system keychain.N(   R   R   t   PROVIDE_MODE_DEVELOPMENTR)   R   R   R/   RQ   R\   R	   RS   R   Rr   R   R   R   R(   Rq   R   R=   R.   R   R<   (   R3   RC   t   vars_and_valuesRa   R   R@   R   t   var_reqsR   R   R6   t   local_state_countt   keyring_countR   R   R   R$   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   set_variables  s@    		c         C@  s   t  |  | | d t j \ } } | d k r1 | St j |  j  } x$ | D] } t |  | | | |  qJ W| j   t	 d t
 d d  S(   s  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
    RZ   R;   R$   s   Variables were unset.N(   R   R   R^   R)   R   R   R/   R   R.   R   R<   (   R3   RC   t   vars_to_unsetRa   R   R@   R   R   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   unset_variables  s    !
c         C@  s  | t  k r- t d | d t t     n  | j   } t |   } | d k	 rU | S|  j j d | g  } | d k r t   } |  j j	 d | g |  n  | | | <| d k r d | k r |  j
 | d <q n
 | | d <| d k	 rt | t  s t  | | d <n  | d k rt j j |  j |  } g  }	 t j j |  r\t j | |	  }
 n i  }
 t |	  d k rt d t d	 d
 d |	  } | S| j |
  n  |  j j   t |  d	 d
 } | d k	 r|  j j   | S|  j j   t d t d	 d  Sd S(   sY  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
    s   Invalid command type s    choose from t   commandsR   t   supports_http_optionst   notebooki    R;   R$   s   Unable to add the command.R6   s   Command added to project file.N(   R   t
   ValueErrort   reprR   R:   R)   R'   RO   RQ   R(   R   RP   t   boolRF   R   R   R   R/   t   isfilet   notebook_analyzert   extrasR,   R   R=   R   R*   R?   R.   R<   (   R3   R"   t   command_typet   commandRC   R  R9   t   command_dictt   notebook_fileR6   R  (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   add_command'  sF    !	

c   
      C@  s7  | d k r/ | d k r/ t d t d d |  S| t t  d g k ri t d | d t t    n  | d k r | d k	 r t d   n  t |   } | d k	 r | S| |  j k r t d t	 d d d d	 | g  S|  j
 j d
 | g  } | d k	 st  | r=|  j
 j d
 | g  |  j
 j d
 | g |  n  t | j    } | t | g  } | d k r| t d g  } n" | d k r| t d g  } n  | d k	 rx | D] }	 | |	 =qW| | | <n  |  j
 j   t |  d d } | d k	 r|  j
 j   | S|  j
 j   t d t d d  Sd S(   s  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
    R;   R$   s"   Nothing to change about command %ss   Invalid command type s    choose from s=   If specifying the command_type, must also specify the commands   Failed to update command.R6   s   No command '%s' found.R  t   unixt   windowss   Unable to add the command.s    Command updated in project file.N(   R)   R   R<   R>   R   R  R  R:   R  R=   R'   RO   RF   R`   R(   R   Rr   R*   R?   R.   (
   R3   R"   R  R  t   new_nameR9   R  t   existing_typest   conflicting_typest   conflicting(    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   update_commandp  sD    !c         C@  s/  t  |   } | d	 k	 r | S| |  j k rG t d t d d j |   S|  j | } | j d	 k	 r |  j j d d g d g  } t	 | t
  r | j | k r | j | j  |  j j d d g |  q n  |  j j d | g  |  j j   |  j g  k st  |  j j   t d t d d j |   S(
   sG  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
    R;   R$   s(   Command: '{}' not found in project file.t   skip_importst	   notebooksR   R  s(   Command: '{}' removed from project file.N(   R:   R)   R  R   R=   R]   R  R'   RO   RP   R>   Rq   R(   R`   R*   R-   RF   R.   R<   (   R3   R"   R9   R  t   skipped_notebooks(    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   remove_command  s"    c         C@  s  t  |   } | d k	 r | S|  j j   } d } x' | D] } | j | k r8 | } Pq8 q8 W| d k r t d t d d d g  d d | d j t d   |   f g  S| d k r | j	 } n  t
 |  d	 k s t  t } |  j |  j d
 | }	 t
 |	  d k rh|	 d }
 t |
 t  r?|
 j | k s6t  t } qht d t d d d g  d d | g  Sn  | s|  j j t | |  |  n  t |  | d | S(   sl  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
    R;   R$   s   Unable to add service.t   logsR6   s,   Unknown service type '%s', we know about: %ss   , c         S@  s   |  j  S(   N(   R"   (   t   s(    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyR     R   i   RS   i    s   Variable %s is already in use.RC   N(   R:   R)   t   plugin_registryt   list_service_typesR"   R   R=   R   R   t   default_variableR,   RF   R\   R   RP   R   t   service_typeR<   R'   R(   R   RJ   (   R3   RC   R"  t   variable_nameR9   t   known_typest   foundt   knownt   requirement_already_existst   existing_requirementsRV   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   add_service  sD    
		c   	      C@  s  t  |   } | d k	 r | Sg  |  j | d t D]* } | j | k sV | j | k r2 | ^ q2 } | s t d t d d j |   St	 |  d k r t d t d d j t	 |    S| d k r t
 j |  d | d f d	 | d
 t j } n  | d k s| j | k st  | d j } t
 j |  | d | g } | sE| S|  j j t | |   |  j j   |  j g  k st  |  j j   t d t d d j |   S(   s  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
    RY   R;   R$   s+   Service '{}' not found in the project file.i   se   Conflicting results, found {} matches, use list-services to identify which service you want to removeRB   i    RC   RZ   R[   s+   Removed service '{}' from the project file.N(   R:   R)   R\   R   R"  RS   R   R=   R]   R,   R   RD   R   R^   RC   RF   R_   R'   R`   R   R*   R-   R.   R<   (	   R3   RC   R#  Ra   R9   R   R   RS   R@   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   remove_service'  s:    *!c         @  s  t  j  |  } t | j    | r=  j j | j  n&   j | j g   j j | j     f d   } | t	 j
 j  j d   t	 j j d t	 j
 j  j d   } | |  | r t    d k r t d t d d d	    St d t d d
 d	    Sd S(   s#  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         @  sq   t  j j |   rm  j j d |   y t j |   Wqm t k
 ri }   j d |  t	 |  f  qm Xn  d  S(   Ns   Removing %s.s   Error removing %s: %s.(
   R   R   R   R7   R   t   shutilt   rmtreeR   Rq   R}   (   t   dirnameR   (   R6   R3   (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   cleanup_dir  s    R   t   ANACONDA_PROJECT_ENVS_PATHR   i    R;   R$   s   Cleaned.R6   s   Failed to clean everything up.N(   R   R_   R>   R6   R7   R   t   status_descriptionR   R8   R   R   R   R/   R   Rp   R,   R   R<   R=   (   R3   Ra   R@   R.  t	   envs_path(    (   R6   R3   s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   cleana  s    '
c         C@  s   t  j |  |  S(   s   Make 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   t   _archive_project(   R3   R   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   archive  s    
c         C@  s7   | d k r t   } n  t j |  d | d | d | S(   s  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.

    t   project_dirt
   parent_dirR7   N(   R)   R   R   t   _unarchive_project(   R   R5  R6  R7   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt	   unarchive  s    c   
      C@  s   t  |   } | d k	 r | Sd } t j d t d d d |  } | j   zd t |  | j  }	 |	 si |	 St j	 |  | j d |  j | d | d | d	 | d
 | d | }	 |	 SWd t
 j | j  Xd S(   s  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
        log_level (str): Anaconda log level

    Returns:
        a ``Status``, if failed has ``errors``
    s   .tar.bz2t   deleteR   t   anaconda_upload_t   suffixt   uploaded_basenamet   privatet   sitet   usernamet   tokent	   log_levelN(   R:   R)   t   tempfilet   NamedTemporaryFileR=   t   closeR4  R"   R   t   _uploadR   R   (
   R3   R=  R>  R?  R@  RA  R9   R;  t   tmp_tarfileR@   (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   upload  s*    
		(`   t   __doc__t
   __future__R    R   t
   contextlibR   R+  RB  t   anaconda_project.projectR   R   t   anaconda_projectR   R   R   R   t!   anaconda_project.local_state_fileR   t   anaconda_project.frontendR   t2   anaconda_project.requirements_registry.requirementR	   t=   anaconda_project.requirements_registry.requirements.conda_envR
   t<   anaconda_project.requirements_registry.requirements.downloadR   R   t;   anaconda_project.requirements_registry.requirements.serviceR   t:   anaconda_project.requirements_registry.providers.conda_envR   t'   anaconda_project.internal.simple_statusR   t   anaconda_project.conda_managerRs   t#   anaconda_project.internal.conda_apiR   R   t+   anaconda_project.internal.notebook_analyzert   internalR  t$   anaconda_project.internal.py2_compatR   t   lstripR   R    R=   R)   R4   R:   RA   RI   RJ   RL   RX   Rb   Rf   Rg   t   objectRh   t   contextmanagerR   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   RN   R   R   R   R   R  R  R  R  R  R)  R*  R2  R4  R8  RG  (    (    (    s;   lib/python2.7/site-packages/anaconda_project/project_ops.pyt   <module>   s   	A-		,/			=	\		3	%		y				&	
	6								0	$;IF	)H:	2	