U
    bm&                 
   @   s  d dl mZmZmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlZd dlmZmZmZmZmZmZmZ d dlZd dlZd dlZd dlmZ d d	lmZ d dlZd
dlmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 ddl4m5Z6 ddl7m8Z8 ddl9m:Z: ddl;m<Z< ddl=m>Z> ddl?m@Z@ ddlAmBZBmCZCmDZD ddlEmFZFmGZGmHZH ddlImJZJmKZKmLZLmMZMmNZNmOZOmPZP ddlQmRZR ddlSmTZTmUZU ddlVmWZWmXZXmYZY ddlZm[Z[ ddl4m\Z\ ze]  W nD e^e_fk
r4 Z` z e`jekr"eaejb n W 5 dZ`[`X Y nX eecZdddddddZed d!d"d#d$d%d&hZfd'd(d)Zgeed*Zheejbd+Zid,d- Zjd.d/ Zkd0d1 Zld2d3 Zmd4d5 ZnG d6d7 d7eJZod8d9 Zpe-dfd:d;Zqede-dfd<d=ZrG d>d? d?esZtG d@dA dAesZueu Zve-dfdBdCZwd]dDdEZxde-dfdFdGZyd^dHdIZzezZ{e
ddJdKdL Z|dMdN Z}d_dOdPZ~d`eeoedRdSdTZdadUdVZdWdX ZdbdYdZZzeod[daW n@ eKk
r Z` z eee`ejd\ ed
 W 5 dZ`[`X Y nX dS )c    )absolute_importdivisionprint_functionunicode_literals)OrderedDict)ENOENT)	lru_cache)	getLoggerN)abspathbasename
expanduserisdirisfilejoinsplit)contextmanager)datetime   )APP_NAMEChannelPriorityDEFAULTS_CHANNEL_NAMEREPODATA_FN"DEFAULT_AGGRESSIVE_UPDATE_PACKAGESDEFAULT_CHANNELSDEFAULT_CHANNEL_ALIASDEFAULT_CUSTOM_CHANNELSDepsModifierERROR_UPLOAD_URLKNOWN_SUBDIRSPREFIX_MAGIC_FILEPathConflictROOT_ENV_NAMESEARCH_PATHSafetyChecksSatSolverChoiceExperimentalSolverChoiceUpdateModifierCONDA_LOGS_DIRPREFIX_NAME_DISALLOWED_CHARS   __version__)user_data_dir)memoizedproperty)dals)
IndexedSet)
frozendict)concatconcatvunique)NoneTypeodicton_win)ConfigurationConfigurationLoadErrorMapParameterParameterLoaderPrimitiveParameterSequenceParameterValidationErrorlinux_get_libc_version)expandpaths_equal)
has_schemepath_to_urlsplit_scheme_auth_token)env_override)CONDA_SOURCE_ROOTlinuxZosxwinzos)Zlinux2rG   darwinZwin32rI   Zarmv6lZarmv7lZaarch64Zarm64Zppc64Zppc64leZs390xZx86Zx86_64)    @   z
~/.condarcz.condarcc                 C   sh   | rt |dt dddf}nt dddt |df}trL|t tttdf7 }ttdd t||D S )Nenvs~.condac                 s   s   | ]}t |V  qd S Nr@   .0p rU   1lib/python3.8/site-packages/conda/base/context.py	<genexpr>o   s     z-mockable_context_envs_dirs.<locals>.<genexpr>)r   r6   r,   r   tupler/   r2   )root_writableroot_prefix
_envs_dirs
fixed_dirsrU   rU   rV   mockable_context_envs_dirsb   s    

r]   c                 C   s   | rt | sd|  S dS )Nz3channel_alias value '%s' must have scheme/protocol.T)rB   valuerU   rU   rV   channel_alias_validationr   s    r`   c                  C   s   t j} d| j| jf S )Nz%d.%d)sysversion_infomajorminor)ZverrU   rU   rV   default_python_defaultx   s    re   c                 C   sj   | r^t | dkrb| d dkrbz*t| } d|   kr:dk rDn nW dS W qb tk
rZ   Y qbX ndS d|  S )N   r   .g       @g      @TzBdefault_python value '%s' not of the form '[23].[0-9][0-9]?' or '')lenfloat
ValueErrorr^   rU   rU   rV   default_python_validation}   s    
rk   c                 C   s&   t | tr"t| s"t| s"d|  S dS )Nzssl_verify value '%s' must be a boolean, a path to a certificate bundle file, or a path to a directory containing certificates of trusted CAs.T)
isinstancestrr   r   r^   rU   rU   rV   ssl_verify_validation   s    
rn   c                       s	  e Zd ZeedZeedZeedZeedZeedddZ	eedZ
eedZeedZeedZeedZeedZeeededZeee eefed	ZeedZeedZeedZeedZeedZeededd
dZeededddZeededddZeededddZ eeedede!ddZ"eee#j$Z%eedZ&eedeefdddZ'eee(jZ)eeededddZ*eeededddddZ+eedZ,eeededZ-eedZ.eedZ/eedddZ0eeedede1j2ddddZ3eeededddZ4eedddZ5eeededdZ6eede7efdZ8eedee7fe9d	dddZ:eedeefddddZ;eedeefddddZ<ee=edeefddZ>eedZ?eed Z@eed!ZAeedZBeedd"dZCeedZDeeeEeFd#d$ddZGeeeHjIZJeeededeKfd%d&ddZLee=ededeMd'ddZNee=eededd(ddZOeeededePd)ddZQeeededd*dZRee=ededddZSeedZTeede7efdZUeedZVeeededd+ddZWeedZXeeededd,eYfZZeede7efdd-dZ[eedd.dZ\eedd/dZ]eede7efdd0dZ^eedZ_eedZ`eedZaeeebZceedZdeedZeeedZfeedZgeedZheede7efdZieedZjeed1edZkeededd2dZleeemjnZoeeepjqZreeesjtZueedZveeewjxewdZyeedZzeedZ{eedZ|eedZ}eed3Z~eedZeede7efdd4dZeedd5dZee=ededd6dZd fd7d8	Zd9d: Zed;d< Zed=d> Zed?d@ ZedAdB ZedCdD ZedEdF ZedGdH ZedIdJ ZedKdL ZedMdN ZedOdP ZedQdR ZedSdT ZedUdV ZedWdX ZedYdZ Zed[d\ Zed]d^ Zed_d` Zedadb Zedcdd Zededf Zedgdh Zedidj Zedkdl Zedmdn Zedodp Zedqdr Zedsdt Zedudv Zedwdx Zedydz Zed{d| Zed}d~ Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zeeddddd Zedd Zdd Zedd Z  ZS )ContextTF)Zself_update)aliasesr   z({default_env})  )element_type)rr   
validation)default_threads)repodata_threads)verify_threads)execute_threads)aggressive_update_packagesN)signing_metadata_url_base&)Zstring_delimiter)Zdisallow)root_dirrZ   )	envs_dirsZ	envs_path)rp   
expandvars)	pkgs_dirs)subdir)subdirsr   )Z
verify_ssl)Zclient_cert)Zclient_cert_key)r}   gL"@g      N@rf   )Zadd_binstar_token)rs   )channel_alias)default)channelschannel)custom_channels)custom_multichannels)default_channels)migrated_channel_aliases)Zwhitelist_channelszcurrent_repodata.json)use_only_tar_bz2)Zsoftlink)copy)Zyes   )verbose	verbosityr)   )binstar_uploadcroot)zconda-buildconda_buildc                    s   |d krt }|rd|kr|jp dddd }|dkrd|krR|jrR|jtjd< n2d	|kr|jrtt|}|tj	krtt|tjd< t
t| j|t|d
 d S )Nfuncrq   rg   r   )ZcreateZinstallupdateremoveZ	uninstallZupgradeprefixCONDA_PREFIXname)search_pathZapp_nameargparse_args)r"   r   rsplitr   osenvironr   determine_target_prefixcontextrZ   superro   __init__r   )selfr   r   Z	func_nametarget_prefix	__class__rU   rV   r   k  s     


zContext.__init__c                 C   sT   g }| j r*| js*td| jdd}|| | jrP| jrPtd| jdd}|| |S )Nclient_ssl_certz
<<merged>>zC'client_ssl_cert' is required when 'client_ssl_cert_key' is definedalways_copyzZ'always_copy' and 'always_softlink' are mutually exclusive. Only one can be set to 'True'.)client_ssl_cert_keyr   r=   appendr   always_softlink)r   errorserrorrU   rU   rV   post_build_validation  s    



zContext.post_build_validationc              
   C   s>   t tdd dd | j| j| jdt| jddfD D S )Nc                 s   s   | ]}t |r|V  qd S rP   )r   )rS   	full_pathrU   rU   rV   rW     s    z2Context.conda_build_local_paths.<locals>.<genexpr>c                 s   s   | ]}|rt |V  qd S rP   rQ   )rS   drU   rU   rV   rW     s   root-dir	conda-bld~/conda-bld)rX   r3   _crootbld_pathr   getr   rZ   r   rU   rU   rV   conda_build_local_paths  s    

zContext.conda_build_local_pathsc                 C   s   t dd | jD S )Nc                 s   s   | ]}t |V  qd S rP   )rC   rR   rU   rU   rV   rW     s     z1Context.conda_build_local_urls.<locals>.<genexpr>)rX   r   r   rU   rU   rV   conda_build_local_urls  s    zContext.conda_build_local_urlsc                 C   sb   | j rtt| j S | jr(tt| jS d| jkrDtt| jd S | jrVt| jdS tdS dS )z1This is where source caches and work folders liver   r   r   N)	r   r
   r   r   r   rY   r   rZ   r@   r   rU   rU   rV   r     s    
zContext.crootc                 C   s   | j S rP   r   r   rU   rU   rV   local_build_root  s    zContext.local_build_rootc                 C   s6   z| j W S  tk
r0   t| j | _ }| Y S X d S rP   )_Context__conda_buildAttributeErrordict_conda_build)r   r   rU   rU   rV   r     s
    zContext.conda_buildc                 C   s"   t  }|tkr|S t| j S d S rP   )platformmachinenon_x86_machines_arch_namesbitsr   mrU   rU   rV   	arch_name  s    zContext.arch_namec                 C   s   t  S rP   )conda_in_private_envr   rU   rU   rV   conda_private  s    zContext.conda_privatec                 C   s   t tjdS )Nunknown)_platform_mapr   ra   r   r   rU   rU   rV   r     s    zContext.platformc                 C   s   | j r| j S d S rP   )_default_threadsr   rU   rU   rV   rt     s    zContext.default_threadsc                 C   s   | j r| j S | jS rP   )_repodata_threadsrt   r   rU   rU   rV   ru     s    zContext.repodata_threadsc                 C   s$   | j r| j }n| jr| j}nd}|S Nr   )_verify_threadsrt   r   ZthreadsrU   rU   rV   rv     s    zContext.verify_threadsc                 C   s$   | j r| j }n| jr| j}nd}|S r   )_execute_threadsrt   r   rU   rU   rV   rw     s    zContext.execute_threadsc                 C   sL   | j r| j S t }|tkr*d| j|f S | jdkr8dS d| j| jf S d S )Nz%s-%srI   zzos-zz%s-%d)_subdirr   r   r   r   r   rU   rU   rV   r     s    
zContext.subdirc                 C   s   | j r| j S | jdfS )NZnoarch)_subdirsr   r   rU   rU   rV   r     s    zContext.subdirsc                 C   s   t tt| jS rP   )	frozensetr2   r   r   r   rU   rU   rV   known_subdirs  s    zContext.known_subdirsc                 C   s   | j r
dS dtd S d S )NrK      P)force_32bitstructZcalcsizer   rU   rU   rV   r     s    zContext.bitsc                 C   s   | j S rP   )rZ   r   rU   rU   rV   r{     s    zContext.root_dirc              
   C   sj   t | jt}t|rfzt|d}W n6 ttfk
rX } zt| W Y dS d }~X Y nX |	  dS dS )Nza+FT)
r   rZ   r   r   openIOErrorOSErrorlogdebugclose)r   pathZfherU   rU   rV   rY     s    
zContext.root_writablec                 C   s   t | j| j| jS rP   )r]   rY   rZ   r[   r   rU   rU   rV   r|     s    zContext.envs_dirsc                    sn   | j rttdd | j D S tjr(dnd | jtddf}trP|tt	t	f7 }tt fdd|D S d S )Nc                 s   s   | ]}t |V  qd S rP   rQ   rR   rU   rU   rV   rW     s     z$Context.pkgs_dirs.<locals>.<genexpr>Zpkgs32ZpkgsrN   rO   c                 3   s   | ]}t t| V  qd S rP   )r@   r   rR   Zcache_dir_namerU   rV   rW   (  s     )

_pkgs_dirsrX   r/   r   r   rZ   r   r6   r,   r   )r   r\   rU   r   rV   r~     s    zContext.pkgs_dirsc                 C   s8   ddl m} | j}t|d}ddlm} || |S )Nr)   PackageCacheDataz.trashmkdir_p)core.package_cache_datar   first_writablepkgs_dirr   gateways.disk.creater   )r   r   r   	trash_dirr   rU   rU   rV   r   *  s    

zContext.trash_dirc                 C   sV   ddl m} | j}t|t}ddlm} || t	 
d}tj|| dS )Nr)   r   r   z%Y%m%d-%H%M%S-%fz.log)r   r   r   r   r   r'   r   r   r   Zutcnowstrftimer   r   )r   r   r   Zlogsr   Z	timestamprU   rU   rV   _logfile_path4  s    

zContext._logfile_pathc                 C   sr   | j r| j S td}|d tdfkr*| jS tj|kr<t|S | jD ]}t||}t	|rB|  S qBt| jd |S )NZCONDA_DEFAULT_ENVrootr   )
active_prefixr   getenvr!   rZ   sepr
   r|   r   r   )r   Z_default_envenvs_dirdefault_prefixrU   rU   rV   r   C  s    




zContext.default_prefixc                 C   s
   t dS )Nr   )r   r   r   rU   rU   rV   r   S  s    zContext.active_prefixc                 C   s   t tddS )NZCONDA_SHLVLr   )intr   r   r   rU   rU   rV   shlvlW  s    zContext.shlvlc                    s$   ddl m  t fdd| jD S )Nr)   	MatchSpecc                 3   s   | ]} |V  qd S rP   rU   )rS   sr   rU   rV   rW   ^  s     z5Context.aggressive_update_packages.<locals>.<genexpr>)Zmodels.match_specr   rX   _aggressive_update_packagesr   rU   r   rV   rx   [  s    z"Context.aggressive_update_packagesc                 C   s   t | S rP   )r   r   rU   rU   rV   r   `  s    zContext.target_prefixc                 C   s6   | j rtt| j S t r,tt| jddS | jS d S )Nz..)_root_prefixr
   r   r   r   conda_prefixr   rU   rU   rV   rZ   f  s
    zContext.root_prefixc                 C   s
   t tjS rP   )r
   ra   r   r   rU   rU   rV   r   o  s    zContext.conda_prefixc                 C   s&   t rdnd}t rdnd}t| j||S )NScriptsbin	conda.execonda)r6   r   r   r   Zbin_dirZexerU   rU   rV   	conda_exes  s    zContext.conda_exec                 C   s   t | jddS )zk Directory where critical data for artifact verification (e.g.,
        various public keys) can be found. etcr   )r   r   r   rU   rU   rV   av_data_dirz  s    zContext.av_data_dirc                 C   s   | j r| j S dS dS )zl Base URL where artifact verification signing metadata (*.root.json,
        key_mgr.json) can be obtained. N)_signing_metadata_url_baser   rU   rU   rV   ry     s    z!Context.signing_metadata_url_basec              
   C   s   t jr>tdtjfdtjttj	
ddffdddtjfgS trFdnd}trRd	nd
}tdtjtj||fdddtjfgS dS )zo
        An OrderedDict so the vars can refer to each other if necessary.
        None means unset it.
        Z	CONDA_EXEZ
PYTHONPATHrq   )_CE_Mz-m)	_CE_CONDAr   ZCONDA_PYTHON_EXEr   r   r   r   )r  rq   )r  rq   N)r   devr   ra   
executabler   pathsepr   rF   r   r   r6   r   r   r   rU   rU   rV   conda_exe_vars_dict  s$    zContext.conda_exe_vars_dictc                 C   s.   ddl m} t| j\}}}}|||||dS )Nr)   Channelschemeauthlocationtoken)models.channelr  rD   _channel_alias)r   r  r  r  r  r  rU   rU   rV   r     s    zContext.channel_aliasc                    s.   ddl m  t fdddd | jD D S )Nr)   r
  c                 3   s&   | ]\}}}} ||||d V  qdS )r  NrU   )rS   r  r  r  r  r
  rU   rV   rW     s   
z3Context.migrated_channel_aliases.<locals>.<genexpr>c                 s   s   | ]}t |V  qd S rP   )rD   )rS   crU   rU   rV   rW     s     )r  r  rX   _migrated_channel_aliasesr   rU   r
  rV   r     s    z Context.migrated_channel_aliasesc                 C   s    | j dd k	p| j dd k	S )Nr   r   )_argparse_argsr   r   rU   rU   rV   prefix_specified  s    zContext.prefix_specifiedc                 C   s
   | j t S rP   )r   r   r   rU   rU   rV   r     s    zContext.default_channelsc                    s   ddl m  tj}jr(|dd tt|fdjff}t fdd|	 D }t fddj
	 D }td	d t|	 |	 D }|S )
Nr)   r
  r   z#https://repo.anaconda.com/pkgs/freelocalc                 3   s.   | ]&\}}|t  fd d|D fV  qdS )c                 3   s   | ]}  j|V  qd S rP   Zmake_simple_channelr   rS   urlr  r   rU   rV   rW     s    9Context.custom_multichannels.<locals>.<genexpr>.<genexpr>NrX   rS   r   Zurlsr  rU   rV   rW     s   z/Context.custom_multichannels.<locals>.<genexpr>c                 3   s.   | ]&\}}|t  fd d|D fV  qdS )c                 3   s   | ]}  j|V  qd S rP   r  r  r  rU   rV   rW     s    r  Nr  r  r  rU   rV   rW     s   c                 s   s   | ]\}}||fV  qd S rP   rU   )rS   r   r   rU   rU   rV   rW     s   )r  r  list_default_channelsrestore_free_channelinsertr5   r   r   items_custom_multichannelsr2   )r   r   Zreserved_multichannel_urlsZreserved_multichannelsr   Zall_multichannelsrU   r  rV   r     s*    
zContext.custom_multichannelsc                    sd   ddl m   fddj D }tdd j D }tdd dd t||D D }|S )Nr)   r
  c                 3   s"   | ]\}}  j||V  qd S rP   r  )rS   r   r  r  rU   rV   rW     s   z*Context.custom_channels.<locals>.<genexpr>c                 s   s   | ]
}|V  qd S rP   rU   )rS   r   rU   rU   rV   rW     s     c                 s   s   | ]}|j |fV  qd S rP   )r   )rS   xrU   rU   rV   rW     s     c                 s   s   | ]
}|V  qd S rP   rU   )rS   ZchrU   rU   rV   rW     s     )	r  r  _custom_channelsr#  r1   r   valuesr5   r2   )r   r   Zchannels_from_multichannelsZall_channelsrU   r  rV   r     s    zContext.custom_channelsc                 C   s   | j r
dnd}| jrd| jkr| jd r| jsHddlm} |tdnH| jrbd| jkrb| jd sxddlm} |d	nttt	|| jd S | jrd| jkrt| jd pd}t
d
d | jD }|r|sttt	||tfS ttt	|| jS )N)r  rU   Zoverride_channelsr)   )OperationNotAllowedzH
                Overriding channels has been disabled.
                r   ArgumentErrorzQAt least one -c / --channel flag must be supplied when using --override-channels.c                 s   s    | ]}d t j|  kV  qdS )r   N)r   raw_datakeys)rS   Zrc_filerU   rU   rV   rW     s   z#Context.channels.<locals>.<genexpr>)	use_localr  override_channels_enabled
exceptionsr(  r.   r*  rX   r/   r2   anyconfig_filesr   	_channels)r   Z	local_addr(  r*  Zargparse_channelsZchannel_in_config_filesrU   rU   rV   r     s2    
zContext.channelsc                 C   s   t dd t D S )Nc                 s   s   | ]}|d kr|V  qdS ))ZenvvarsZcmd_lineNrU   )rS   r   rU   rU   rV   rW     s    z'Context.config_files.<locals>.<genexpr>)rX   r   Zcollect_allr   rU   rU   rV   r1    s    zContext.config_filesc                 C   s   ddl m} dd l}d}| jd krtzdd l}||j|dk }W n tk
rT   Y nX | jrtd| jkrt|| jd M }t|j	dr|j	j
 p| jp|S )Nr)   )VersionOrderr   Fz3.18.3r   libarchive_enabled)Zmodels.versionr3  Zconda_package_handling.api_use_only_tar_bz2r   r+   ImportErrorr  hasattrZapir4  )r   r3  Zconda_package_handlingr   r   rU   rU   rV   r     s$    
zContext.use_only_tar_bz2c                 C   s   | j S rP   )anaconda_uploadr   rU   rU   rV   r   -  s    zContext.binstar_uploadc                 C   s   | j r
dS | jS )Nr)   )r   
_verbosityr   rU   rU   rV   r   2  s    zContext.verbosityc              
   C   s   dt | jf g}|d| j  |d| j  |d| j  | jd rZ|d| j  | jjdkrddl	m
} d| jj }z|d|   7 }W n6 tk
r } ztjd	| jj|d
 W 5 d }~X Y nX || d|S )Nzconda/%s requests/%sz%s/%sr   Zclassicr)   )_get_solver_classz	solver/%s z7User agent could not be fetched from solver class '%s'.exc_info)CONDA_VERSIONrequests_versionr   "python_implementation_name_versionplatform_system_releaseos_distribution_name_versionlibc_family_versionexperimental_solverr_   Z
core.solver:  
user_agent	Exceptionr   r   r   )r   Zbuilderr:  Zuser_agent_strexcrU   rU   rV   rE  6  s&    

zContext.user_agentc              
   c   s4   t | |}t| || z
dV  W 5 t| || X dS )a.  
        TODO: This might be broken in some ways. Unsure what happens if the `old`
        value is a property and gets set to a new value. Or if the new value
        overrides the validation logic on the underlying ParameterLoader instance.

        Investigate and implement in a safer way.
        N)getattrsetattr)r   keyr_   oldrU   rU   rV   	_overrideN  s
    	

zContext._overridec                 C   sT   zddl m} W n> tk
rN   zddlm} W n tk
rH   d}Y nX Y nX |S )Nr   r*   r   )Zrequestsr+   r6  Zpip._vendor.requests)r   ZREQUESTS_VERSIONrU   rU   rV   r?  ^  s    zContext.requests_versionc                 C   s   t  t  fS rP   )r   Zpython_implementationZpython_versionr   rU   rU   rV   r@  i  s    z*Context.python_implementation_name_versionc                 C   s   t  t  fS rP   )r   systemreleaser   rU   rU   rV   rA  o  s    	zContext.platform_system_releasec              
   C   s   | j d }|dkrddlm}m} z| |ddf}W n6 tk
rl } ztjd|dd d}W 5 d }~X Y nX |d |d	  }}n*|d
krd}t d }nt	 }t }||fS )Nr   Linux)idversionT)Zbestz%rr<  )rO  r   r   ZDarwinZOSX)
rA  Zconda._vendor.distrorP  rQ  rF  r   r   r   Zmac_verrM  )r   Zplatform_namerP  rQ  Zdistinfor   Zdistribution_nameZdistribution_versionrU   rU   rV   rB  z  s    
z$Context.os_distribution_name_versionc                 C   s   t  \}}||fS rP   r>   )r   Zlibc_familyZlibc_versionrU   rU   rV   rC    s    
zContext.libc_family_versionc                 C   s   t  }|d S )Nflags)_get_cpu_info)r   inforU   rU   rV   	cpu_flags  s    zContext.cpu_flagsZCONDA_OVERRIDE_CUDA)Zconvert_empty_to_nonec                 C   s   ddl m} | S )Nr   )cuda_detect)Zconda.common.cudarV  )r   rV  rU   rU   rV   cuda_version  s    zContext.cuda_versionc              
   C   s   ddddddddd	d
	S )N)r   r   r   r.  allowlist_channelsr   r   r   migrated_custom_channelsadd_anaconda_tokenallow_non_channel_urlsr!  repodata_fnsr   ru   )r|   r~   rt   )
r   r   local_repodata_ttlofflineproxy_serversremote_connect_timeout_secsremote_max_retriesremote_backoff_factorremote_read_timeout_secs
ssl_verify)
rx   auto_update_condachannel_prioritycreate_default_packagesdisallowed_packagesforce_reinstallpinned_packagespip_interop_enabledtrack_featuresrD  )allow_softlinksr   r   path_conflictrollback_enabledsafety_checksextra_safety_checksry   	shortcutsnon_admin_enabledseparate_format_cacherv   rw   )r   r   r8  r   )
always_yesauto_activate_base
auto_stack	changeps1
env_promptjsonnotify_outdated_condaquietreport_errorsshow_channel_urlsr   unsatisfiable_hintsunsatisfiable_hints_check_depthnumber_channel_notices)
deps_modifierupdate_modifierforceforce_removeclobberdry_rundownload_onlyignore_pinneduse_index_cacher-  )allow_cyclesallow_conda_downgradesadd_pip_as_python_dependencyr   r  default_pythonenable_private_envserror_upload_urlr   rZ   
sat_solversolver_ignore_timestampsr   r   target_prefix_override)	zChannel ConfigurationzBasic Conda ConfigurationzNetwork ConfigurationzSolver Configurationz.Package Linking and Install-time ConfigurationzConda-build Configurationz.Output, Prompt, and Flow Control ConfigurationzCLI-onlyzHidden and UndocumentedrU   r   rU   rU   rV   category_map  s    zContext.category_mapc                 C   s   | j S rP   )description_mapr   rU   rU   rV   get_descriptions  s    zContext.get_descriptionsc              I   C   s  t tdtdtdtdtdtdtdtdtd	td
tdtdtdtdtdtdtdtdtdtdtdtdtdtdtdtdtdtdtdtdtdtd td!td"td#td$td%td&td'td(td)td*td+td,td-td.td/td0td1td2td3td4td5td6td7td8td9td:td;td<td=td>td?td@tdAtdBtdCtdDtdEtdFtdGdHGS )INag  
                In conjunction with the anaconda command-line client (installed with
                `conda install anaconda-client`), and following logging into an Anaconda
                Server API site using `anaconda login`, automatically apply a matching
                private token to enable access to private packages and channels.
                z
                A list of packages that, if installed, are always updated to the latest possible
                version.
                zq
                Warn, but do not fail, when conda detects a channel url is not a valid channel.
                a}  
                When allow_softlinks is True, conda uses hard-links when possible, and soft-links
                (symlinks) when hard-links are not possible, such as when installing on a
                different filesystem than the one that the package cache is on. When
                allow_softlinks is False, conda still uses hard-links when possible, but when it
                is not possible, conda copies files. Individual packages can override
                this setting, specifying that certain files should never be soft-linked (see the
                no_link option in the build recipe documentation).
                z
                Register a preference that files be copied into a prefix during install rather
                than hard-linked.
                aU  
                Register a preference that files be soft-linked (symlinked) into a prefix during
                install rather than hard-linked. The link source is the 'pkgs_dir' package cache
                from where the package is being linked. WARNING: Using this option can result in
                corruption of long-lived conda environments. Package caches are *caches*, which
                means there is some churn and invalidation. With this option, the contents of
                environments can be switched out (or erased) via operations on other environments.
                z
                Automatically choose the 'yes' option whenever asked to proceed with a conda
                operation, such as when running `conda install`.
                zg
                Automatically upload packages built with conda build to anaconda.org.
                zj
                Automatically activate the base environment during shell initialization.
                zq
                Automatically update conda when a newer or higher priority version is detected.
                aA  
                Implicitly use --stack when using activate if current level of nesting
                (as indicated by CONDA_SHLVL environment variable) is less than or equal to
                specified value. 0 or false disables automatic stacking, 1 or true enables
                it for one level.
                z
                The location where conda-build will put built packages. Same as 'croot', but
                'croot' takes precedence when both are defined. Also used in construction of the
                'local' multichannel.
                z
                When using activate, change the command prompt ($PS1) to include the
                activated environment.
                z]
                The prepended url location to associate with channel names.
                a,  
                Accepts values of 'strict', 'flexible', and 'disabled'. The default value
                is 'flexible'. With strict channel priority, packages in lower priority channels
                are not considered if a package with the same name appears in a higher
                priority channel. With flexible channel priority, the solver may reach into
                lower priority channels to fulfill dependencies, rather than raising an
                unsatisfiable error. With channel priority disabled, package version takes
                precedence, and the configured priority of channels is used only to break ties.
                In previous versions of conda, this parameter was configured as either True or
                False. True is now an alias to 'flexible'.
                z`
                The list of conda channels to include for relevant operations.
                z
                A path to a single file containing a private key and certificate (e.g. .pem
                file). Alternately, use client_ssl_cert_key in conjunction with client_ssl_cert
                for individual files.
                zc
                Used in conjunction with client_ssl_cert for a matching key file.
                zS
                General configuration parameters for conda-build.
                ze
                Packages that are by default added to a newly created environments.
                z
                The location where conda-build will put built packages. Same as 'bld_path', but
                'croot' takes precedence when both are defined. Also used in construction of the
                'local' multichannel.
                aQ  
                A map of key-value pairs where the key is a channel name and the value is
                a channel location. Channels defined here override the default
                'channel_alias' value. The channel name (key) is not included in the channel
                location (value).  For example, to override the location of the 'conda-forge'
                channel where the url to repodata is
                https://anaconda-repo.dev/packages/conda-forge/linux-64/repodata.json, add an
                entry 'conda-forge: https://anaconda-repo.dev/packages'.
                ah  
                A multichannel is a metachannel composed of multiple channels. The two reserved
                multichannels are 'defaults' and 'local'. The 'defaults' multichannel is
                customized using the 'default_channels' parameter. The 'local'
                multichannel is a list of file:// channel locations where conda-build stashes
                successfully-built packages.  Other multichannels can be defined with
                custom_multichannels, where the key is the multichannel name and the value is
                a list of channel names and/or channel urls.
                zm
                The list of channel names and/or urls used for the 'defaults' multichannel.
                a  
                Threads to use by default for parallel operations.  Default is None,
                which allows operations to choose themselves.  For more specific
                control, see the other *_threads parameters:
                    * repodata_threads - for fetching/loading repodata
                    * verify_threads - for verifying package contents in transactions
                    * execute_threads - for carrying out the unlinking and linking steps
                z
                Package specifications to disallow installing. The default is to allow
                all packages.
                z
                Solve an environment and ensure package caches are populated, but exit
                prior to unlinking and linking packages into the prefix
                z
                The list of directories to search for named environments. When creating a new
                named environment, the environment will be placed in the first writable
                location.
                aY  
                Template for prompt modification based on the active environment. Currently
                supported template variables are '{prefix}', '{name}', and '{default_env}'.
                '{prefix}' is the absolute path to the active environment. '{name}' is the
                basename of the active environment prefix. '{default_env}' holds the value
                of '{name}' if the active environment is a conda named environment ('-n'
                flag), or otherwise holds the value of '{prefix}'. Templating uses python's
                str.format() method.
                z
                Threads to use when performing the unlink/link transaction.  When not set,
                defaults to 1.  This step is pretty strongly I/O limited, and you may not
                see much benefit here.
                z
                Ensure that any user-requested package for the current operation is uninstalled
                and reinstalled, even if that package already exists in the environment.
                zY
                Ensure all output written to stdout is structured json.
                ax  
                For a value of False or 0, always fetch remote repodata (HTTP 304 responses
                respected). For a value of True or 1, respect the HTTP Cache-Control max-age
                header. Any other positive integer values is the number of seconds to locally
                cache repodata before checking the remote server for an update.
                z
                A list of previously-used channel_alias values. Useful when switching between
                different Anaconda Repository instances.
                z
                A map of key-value pairs where the key is a channel name and the value is
                the previous location of the channel.
                z
                Allows completion of conda's create, install, update, and remove operations, for
                non-privileged (non-root or non-administrator) users.
                z
                Notify if a newer version of conda is detected during a create, install, update,
                or remove operation.
                zc
                Restrict conda to cached download content and file:// based urls.
                zY
                Permit use of the --overide-channels command-line flag.
                aj  
                The method by which conda handle's conflicting/overlapping paths during a
                create, install, or update operation. The value must be one of 'clobber',
                'warn', or 'prevent'. The '--clobber' command-line flag or clobber
                configuration parameter overrides path_conflict set to 'prevent'.
                z
                A list of package specs to pin for every environment resolution.
                This parameter is in BETA, and its behavior may change in a future release.
                zn
                Allow the conda solver to interact with non-conda-installed python packages.
                z
                The list of directories where locally-available packages are linked from at
                install time. Packages not locally available are downloaded and extracted
                into the first writable directory.
                a  
                A mapping to enable proxy settings. Keys can be either (1) a scheme://hostname
                form, which will match any request to the given scheme and exact hostname, or
                (2) just a scheme, which will match requests to that scheme. Values are are
                the actual proxy server, and are of the form
                'scheme://[user:password@]host[:port]'. The optional 'user:password' inclusion
                enables HTTP Basic Auth with your proxy.
                zP
                Disable progress bar display and other output.
                z
                The number seconds conda will wait for your client to establish a connection
                to a remote url resource.
                zd
                The maximum number of retries each HTTP connection should attempt.
                zi
                The factor determines the time HTTP connection should wait for attempt.
                z
                Once conda has connected to a remote resource and sent an HTTP request, the
                read timeout is the number of seconds conda will wait for the server to send
                a response.
                z
                Threads to use when downloading and reading repodata.  When not set,
                defaults to None, which uses the default ThreadPoolExecutor behavior.
                z
                Opt in, or opt out, of automatic error reporting to core maintainers. Error
                reports are anonymous, with only the error stack trace and information given
                by `conda info` being sent.
                z"
                Add the "free" channel back into defaults, behind "main" in priority. The "free"
                channel was removed from the collection of default channels in conda 4.7.0.
                z
                Should any error occur during an unlink/link transaction, revert any disk
                mutations made to that point in the transaction.
                z
                Enforce available safety guarantees during package installation.
                The value must be one of 'enabled', 'warn', or 'disabled'.
                a  
                Treat .tar.bz2 files as different from .conda packages when
                filenames are otherwise similar. This defaults to False, so
                that your package cache doesn't churn when rolling out the new
                package format. If you'd rather not assume that a .tar.bz2 and
                .conda from the same place represent the same content, set this
                to True.
                z
                Spend extra time validating package contents.  Currently, runs sha256 verification
                on every file within each package during installation.
                z
                Base URL for obtaining trust metadata updates (i.e., the `*.root.json` and
                `key_mgr.json` files) used to verify metadata and (eventually) package signatures.
                z
                Allow packages to create OS-specific shortcuts (e.g. in the Windows Start
                Menu) at install time.
                zc
                Show channel URLs when displaying what is going to be downloaded.
                a  
                Conda verifies SSL certificates for HTTPS requests, just like a web
                browser. By default, SSL verification is enabled, and conda operations will
                fail if a required url's certificate cannot be verified. Setting ssl_verify to
                False disables certification verification. The value for ssl_verify can also
                be (1) a path to a CA bundle file, or (2) a path to a directory containing
                certificates of trusted CA.
                z
                A list of features that are tracked by default. An entry here is similar to
                adding an entry to the create_default_packages list.
                a  
                Specify filenames for repodata fetching. The default is ('current_repodata.json',
                'repodata.json'), which tries a subset of the full index containing only the
                latest version for each package, then falls back to repodata.json.  You may
                want to specify something else to use an alternate index that has been reduced
                somehow.
                z[
                Use cache of channel index files, even if it has expired.
                a'  
                A boolean indicating that only .tar.bz2 conda packages should be downloaded.
                This is forced to True if conda-build is installed and older than 3.18.3,
                because older versions of conda break when conda feeds it the new file format.
                zf
                Sets output log level. 0 is warn. 1 is info. 2 is debug. 3 is trace.
                z
                Threads to use when performing the transaction verification step.  When not set,
                defaults to 1.
                a  
                The exclusive list of channels allowed to be used on the system. Use of any
                other channels will result in an error. If conda-build channels are to be
                allowed, along with the --use-local command line flag, be sure to include the
                'local' channel in the list. If the list is empty or left undefined, no
                channel exclusions will be enforced.
                z
                A boolean to determine if conda should find conflicting packages in the case
                of a failed install.
                ar  
                An integer that specifies how many levels deep to search for unsatisfiable
                dependencies. If this number is 1 it will complete the unsatisfiable hints
                fastest (but perhaps not the most complete). The higher this number, the
                longer the generation of the unsat hint will take. Defaults to 3.
                aV  
                A string to choose between the different solver logics implemented in
                conda. A solver logic takes care of turning your requested packages into a
                list of specs to add and/or remove from a given environment, based on their
                dependencies and specified constraints.
                a  
                Sets the number of channel notices to be displayed when running commands
                the "install", "create", "update", "env create", and "env update" . Defaults
                to 5. In order to completely suppress channel notices, set this to 0.
                )GrZ  rx   r[  rm  r   r   ru  r8  rv  re  rw  r   rx  r   rf  r   r   r   r   rg  r   r   r   r   rt   rh  r  r|   ry  rw   ri  rz  r]  r   rY  rs  r{  r^  r.  rn  rj  rk  r~   r_  r|  r`  ra  rb  rc  ru   r}  r!  ro  rp  rt  rq  ry   rr  r~  rd  rl  r\  r  r   r   rv   rX  r  r  rD  r  )r0   r.   r   rU   rU   rV   r     s   




		    zContext.description_map)NN)__name__
__module____qualname__r:   r;   r  r  r  rm  re  rv  rw  r{  r  rx  ry  r<   rm   rg  re   r4   rk   r  r  r  r   rs  rk  r   r   r   r   r   r   r   r#   warnrp  rq  r  r    rn  rj  rh  ro  rl  r  rt  r   r   r  r[   r   r   r   boolr]  rn   rd  r   r   r9   r_  r`  rc  ra  rb  rZ  r[  r   r`   r  r   ZFLEXIBLErf  r   r2  r   r&  r$  r   r   r  rY  r.  r~  r-  rX  r!  r   r\  r5  r   r   ru  r   r  r  r   r  r  rz  r^  r|  r  r}  rr  r  r9  r   ZNOT_SETr  r&   ZUPDATE_SPECSr  r$   ZPYCOSATr  r  r%   ZCLASSICrD  r  ri  r  r  r  r   r8  r   r   r   r   propertyr   r   r   r   r   r   r   r   rt   ru   rv   rw   r   r   r-   r   r   r{   rY   r|   r~   r   r   r   r   r   rx   r   rZ   r   r   r  ry   r	  r   r   r  r   r   r   r   r1  r   r   r   rE  r   rL  r?  r@  rA  rB  rC  rU  rE   rW  r  r  r  __classcell__rU   rU   r   rV   ro      s  


   
 
  










	
	








	


















#















wro   c                  C   s"   t tj\} }|dko t| dkS )NZ_conda_rM   )
path_splitra   r   r   )r   env_namerU   rU   rV   r   2  s    r   c                 C   s2   t | | t jdd  ddlm} |  t S )Nr   r)   r
  )r   r   __dict__popr  r  Z_reset_state)r   r   r  rU   rU   rV   reset_context8  s
    r  c                 k   sd   | s|r.t j }t j| pi  t j| t||dV  | sD|r`t j  t j| t  d S )Nr   r   )r   r   r   r   r  clear)envr   r   kwargsZold_envrU   rU   rV   fresh_contextB  s    

r  c                   @   s0   e Zd ZedfddZedfddZdd ZdS )ContextStackObjectNc                 C   s   |  || d S rP   )	set_valuer   r   r   rU   rU   rV   r   Q  s    zContextStackObject.__init__c                 C   s   || _ || _d S rP   r  r  rU   rU   rV   r  T  s    zContextStackObject.set_valuec                 C   s   t | j| j d S rP   )r  r   r   r   rU   rU   rV   applyX  s    zContextStackObject.apply)r  r  r  r"   r   r  r  rU   rU   rU   rV   r  O  s   r  c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )ContextStackc                 C   s*   dd t dD | _d| _d | _d | _d S )Nc                 S   s   g | ]
}t  qS rU   r  rS   _rU   rU   rV   
<listcomp>_  s     z)ContextStack.__init__.<locals>.<listcomp>rf   r   )range_stack
_stack_idx_last_search_path_last_argparse_argsr   rU   rU   rV   r   ^  s    zContextStack.__init__c                 C   s\   |  j d7  _ t| j}| j |kr<| jdd t|D  | j| j  || |   d S )Nr   c                 S   s   g | ]
}t  qS rU   r  r  rU   rU   rV   r  h  s     z%ContextStack.push.<locals>.<listcomp>)r  rh   r  extendr  r  r  )r   r   r   Zold_lenrU   rU   rV   pushd  s    

zContextStack.pushc                 C   s\   | j | j| j jks(| j| j| j jkrX| j| j   | j| j j| _ | j| j j| _d S rP   )r  r  r  r   r  r   r  r   rU   rU   rV   r  l  s    zContextStack.applyc                 C   s"   |  j d8  _ | j| j    d S r   )r  r  r  r   rU   rU   rV   r  t  s    zContextStack.popc                 C   s(   | j | j || | j | j   d S rP   )r  r  r  r  r  rU   rU   rV   replacex  s    zContextStack.replaceN)r  r  r  r   r  r  r  r  rU   rU   rU   rV   r  \  s
   r  c                 C   s   | rt || nt   d S rP   )context_stackr  r  pushingr   r   rU   rU   rV   stack_context  s    r  c                 C   s   t | d|dS NrU   r  )r  r  r   rU   rU   rV   stack_context_default  s    r  c                 C   s   t ||S rP   r  r  r  rU   rU   rV   replace_context  s    r  c                 C   s   t jd|dS r  r  r  rU   rU   rV   replace_context_default  s    r  )maxsizec                  C   s   ddl m}  t|  S )Nr)   get_cpu_info)Z_vendor.cpuinfor  r0   r  rU   rU   rV   rS    s    rS  c                 C   sF   | sd S t | tjrtS t| \}}tjD ]}t ||r*|  S q*| S rP   )rA   r   rZ   r!   r  r|   )r   Zmaybe_envs_dirZ
maybe_namer   rU   rU   rV   r    s    


r  c                 C   sr   | st | tdfkrtjS |dkr(tj}|D ],}t|s:q,t|| }t|r,t|  S q,ddlm	} || dS )zsFind the location of a prefix given a conda env name.  If the location does not exist, an
    error is raised.
    r   Nr)   EnvironmentNameNotFound)
AssertionErrorr!   r   rZ   r|   r   r   r
   r/  r  )r   r|   r   r   r  rU   rU   rV   locate_prefix_by_name  s    
r  T)prefix_namectxreturnc                 C   s   ddl m} t| r0|td| dt d| tdfkrP|rF|jS |dn8ddl m} z
t| W S  |k
r   t	t
 |  Y S X d	S )
z9Run various validations to make sure prefix_name is validr)   )CondaValueErrorz+
                Invalid environment name: z)
                Characters not allowed: z
                r   z6Use of 'base' as environment name is not allowed here.r  N)r/  r  r(   intersectionr.   r!   rZ   r  r  r   _first_writable_envs_dir)r  r  Z
allow_baser  r  rU   rU   rV   validate_prefix_name  s$    
	

r  c                 C   s   |p| j }z
|j}W n tk
r,   d}Y nX z
|j}W n tk
rP   d}Y nX |dk	rv| svddlm} |d|dk	r| sddlm} |d|dkr|dkr| jS |dk	rt|S t	|| dS dS )a   Get the prefix to operate in.  The prefix may not yet exist.

    Args:
        ctx: the context of conda
        args: the argparse args from the command line

    Returns: the prefix
    Raises: CondaEnvironmentNotFoundError if the prefix is invalid
    Nr)   r)  z!Argument --name requires a value.z#Argument --prefix requires a value.)r  )
r  r   r   r   stripr/  r*  r   r@   r  )r  argsr   r  Zprefix_pathr*  rU   rU   rV   r     s(    




r   c               
   C   s   t jD ]} | tjkrqt| d}t|rhzt|d  | W   S  tt	fk
rd   t
d|  Y qX qddlm} || }|r|   S qddlm} |t jd S )Nz.conda_envs_dir_testaz#Tried envs_dir but not writable: %sr)   )create_envs_directory)NoWritableEnvsDirError)r   r|   r   devnullr   r   r   r   r   r   r   Ztracer   r  r/  r  )r   Zenvs_dir_magic_filer  Zwas_createdr  rU   rU   rV   r    s     




r  c                 C   s   t dt t| pt|S )Nz`conda.base.context.get_prefix` is pending deprecation and will be removed in a future release. Please use `conda.base.context.determine_target_prefix` instead.)warningsr  PendingDeprecationWarningr   r   )r  r  searchrU   rU   rV   
get_prefix)  s
    r  rU   )file)N)NN)N)T)N)T)Z
__future__r   r   r   r   collectionsr   errnor   	functoolsr   Zloggingr	   r   os.pathr
   r   r   r   r   r   r   r  r   ra   r   
contextlibr   r   r  Z	constantsr   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   rq   r+   r>  Z_vendor.appdirsr,   Zauxlib.decoratorsr-   Z
auxlib.ishr.   Z_vendor.boltons.setutilsr/   Z_vendor.frozendictr0   Z_vendor.toolzr1   r2   r3   Zcommon.compatr4   r5   r6   Zcommon.configurationr7   r8   r9   r:   r;   r<   r=   Zcommon._os.linuxr?   Zcommon.pathr@   rA   Z
common.urlrB   rC   rD   Zcommon.decoratorsrE   rF   getcwdr   r   r   chdirr   r  r   r   r   r   Zuser_rc_pathZsys_rc_pathr]   r`   re   rk   rn   ro   r   r  r  objectr  r  r  r  r  r  r  Zconda_tests_ctxt_mgmt_def_polrS  r  r  rm   r  r   r  r  r   printreprstderrexitrU   rU   rU   rV   <module>   s   $\$
	           '
!





%
	