
    Lg              
      j   d dl m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	Z	d dl
Z
d dl
mZ d dlmZ ddgd	d
Z ej                  e       ej                   e      d               Zej%                         d        Zej                         d        Zej%                         d        Zej                         d        Zej%                  d       ej.                  dd      d%d              Zej%                  d       ej.                  dd      d               Zej%                  d       ej.                  dd       ej.                  dd       ej4                  dddej6                  d      d                             Z	 d%	 	 	 	 	 	 	 d&d Zej%                  d!      d"        Zd# Zd$ Z y)'    )annotationsN)reduce)Any)__version__)importlib_metadataz-hz--helpX   )help_option_namesmax_content_width)context_settingsc                      y)zDask command line interface.N r       (lib/python3.12/site-packages/dask/cli.pyclir      s     	r   c                 .    ddl } | j                  d       y)zBOpen Dask documentation (https://docs.dask.org/) in a web browser.r   Nzhttps://docs.dask.org)
webbrowseropen)r   s    r   docsr      s     OO+,r   c                      y)z)Information about your dask installation.Nr   r   r   r   infor   $        	r   c                     ddl m}   |         y)z(Print versions of Dask related projects.r   show_versionsN)
dask.utilsr   r   s    r   versionsr   *   s     )Or   c                      y)zDask config settingsNr   r   r   r   configr   2   r   r   get)namekeyT)requiredc                   	 t        d | j                  d      t        j                  j                        }t        t        t        f      r)t        j                  t        j                  |             y	|t        j                  d
       y	t        j                  |       y	# t        t
        f$ r= t        j                  t        j                  d|  d      d       t        d       Y w xY w)z&Print config key, or the whole config.c                    | |   S Nr   )dks     r   <lambda>zconfig_get.<locals>.<lambda>=   s    1Q4r   .zSection not found: red)fgT)err   NNone)r   splitdaskr   KeyError	TypeErrorclickechostyleexit
isinstancelistdictecho_via_pageryamldump)r!   datas     r   
config_getr>   8   s    '39K9KL
 $t%TYYt_-	

6

4 i  

5;;!4SE:uE4PQs   5B$ $A	C0/C0findc                   t        t        j                  j                  |             }|rt	        j
                  d|  d       t        t        t        |d                   }|D ]  }t        t        j                  j                  |g            }t        j                  j                  | |      }d|t        t        |            z
  z  }t	        j
                  | d| d|  d| d	        yt	        j
                  d
|  d       t	        j
                  dj                  t        t        t        j                  j                                     y)z9Find a Dask config key by searching config location pathszFound [z] in the following files:c                *    t        t        |             S r%   )lenstr)vs    r   r(   zconfig_find.<locals>.<lambda>Q   s    3s1v;r   )r!   r    z [=]zUnable to find [z ] in any of the following paths:
N)r8   r0   r   paths_containing_keyr3   r4   rB   rC   maxnextcollect_yamlr   joinmappaths)r!   rP   max_lenpathr   valuespacings          r   config_findrU   J   s    11#67E

WSE!:;<c#e)>?@AD$++22D6:;FKKOOCO7EWs3t9~56GJJ$q	C5%:;	  	

%cU*JKL

499Sdkk&7&789:r   setrS   z--fileFzFile to use, defaulting to the first config file containing the key, 'DASK_CONFIG' environment variable location or finally, '~/.config/dask/dask.yaml')defaultr"   typehelpc                    t         j                  j                  |      }t        | ||      \  }}t	        j
                  d|  d| d|        y)z$Set a Dask config key to a new valuez	Updated [z] to [z], config saved to N)r0   r   interpret_valuesave_configr3   r4   )r!   rS   file_rR   s        r   
config_setr_   \   sJ      KK''.E#ud+GAt	JJ3%veW,?vFGr   c                <   |Wt        t        j                  j                  |       t	        j
                  t        j                  j                        dz        }|j                  j                  dd       |j                         r(t        j                  |j                               xs i }ni }t        j                  j                  | |i|       	 |j                  t        j                  |             ||fS # t         $ r}t#        d| d      |d}~ww xY w)z]
    Save new config values to dask config file,
    return new config and path to file.
    Nz	dask.yamlT)exist_okparentsrE   z.

For some reason we couldn't write config to z.
Perhaps you don't have permissions here?

You can change the directory where Dask writes config files
to somewhere else using the DASK_CONFIG environment variable.

For example, you could set the following:

    export DASK_CONFIG=~/.dask
)rL   r0   r   rJ   pathlibPathPATHparentmkdirexistsr;   	safe_load	read_textrV   
write_textr<   OSErrorRuntimeError)r!   rS   config_filer   es        r   r\   r\   q   s    KK,,S1LL))*[8
 dD9 5 5 78>BKKOOS%LO0tyy01" ;!  --8M 	:
 	s   $C= =	DDDr8   c                     t        j                  t        j                  t        j
                  j
                               y)zPrint the whole config.N)r3   r:   r;   r<   r0   r   r   r   r   config_listrq      s%     
4;;#5#567r   c                   	 |j                         }t        |t        j                  t        j                  f      s#t        j                  dt        |       d       y|j                  | j                  v r#t        j                  d|j                   d       | j                  |       y# t        $ r0}t        j                  d|j                   d| d       Y d}~yd}~ww xY w)a  Add `entry_point` command to `interface`.

    Parameters
    ----------
    interface : click.Command or click.Group
        The click interface to augment with `entry_point`.
    entry_point : importlib.metadata.EntryPoint
        The entry point which loads to a ``click.Command`` or
        ``click.Group`` instance to be added as a sub-command or
        sub-group in `interface`.

    z)While registering the command with name 'z', an exception occurred; r)   NzRentry points in 'dask_cli' must be instances of click.Command or click.Group, not zC', an existing command or group; the original has been overwritten.)load	Exceptionwarningswarnr    r7   r3   CommandGrouprX   commandsadd_command)	interfaceentry_pointcommandro   s       r   _register_command_epr~      s    ""$ gu{{;<115gqB	
 	||y)))7~ FL L	

 '"'  78H8H7I J##$#Q(	
 	s   B, ,	C%5&C  C%c                 n    t        j                  d      D ]  } t        t        |         t                y)z$Run the dask command line interface.dask_cli)groupN)r   entry_pointsr~   r   )eps    r   run_clir      s+    
 !--J?S"% @ Er   r%   )r!   rC   rS   r   rn   zpathlib.Path | Nonereturnztuple[dict, pathlib.Path])!
__future__r   rc   ru   	functoolsr   typingr   r3   r;   r0   r   dask._compatibilityr   CONTEXT_SETTINGSr   version_optionr   r}   r   r   r   r   argumentr>   rU   optionrd   r_   r\   rq   r~   r   r   r   r   <module>r      s	   "         2 )  ./k"	 # 0	
 - - 	 	
   	 	
 U% &   V%; & ;  U%$'		%
H
 ( & H (,*	** %* 	*Z V8 8
"#J
r   