U
    Zf                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZG dd dejej	Z
eeZejddd ddd	d
Zdd Zdd Zdd Zdd Zedkre  dS )    Nc                   @   s   e Zd ZdS )_CombinedFormatterN)__name__
__module____qualname__ r   r   F/tmp/pip-unpacked-wheel-47crqvv_/dash/development/update_components.pyr      s   r   z3%(asctime)s,%(msecs)03d %(levelname)s - %(message)sz%H:%M:%S)fmtdatefmtZdcchtmlZ
dash_table)zdash-core-componentszdash-html-componentsz
dash-tablec                 K   s>   zt | f| W n( tk
r8   t | ddf| Y nX d S )Nasciiignore)printUnicodeEncodeErrorencode)msgkwargsr   r   r   status_print   s    r   c              	   C   s   t jdk}| dkr| nd}d| d| d| }tj|| d}t| tj|tjtj|d}| \}}	|	 }
W 5 Q R X |	rt|
rd	nd
|	
  t jd |
s|std| d|
 dt jd t d ntd| dt jd d S )Nwin32all6{dash-core-components,dash-html-components,dash-table}npx lerna exec --concurrency 
 --scope='z	' -- npm posixstdoutstderrshell   🛑  fileu@   🚨 Failed installing npm dependencies for component packages: 	 (status=   ) 🚨   uB   🟢 Finished installing npm dependencies for component packages: u    🟢)sysplatformshlexsplitr   
subprocessPopenPIPEcommunicatepolldecoder   exit)components_sourceconcurrencyZinstall_type
is_windowssource_globcmdstrcmdprocouterrstatusr   r   r   bootstrap_components$   s:    
   
r:   c              
   C   s  t jdk}| dkr| nd}d| d| d}tj|| d}t| tj|tjtj|d}| \}}|	 }	W 5 Q R X |rt|	rd	nd
|
  t jd |	s|std| d|	 dt jd t d d|kr|dd dd }|dD ]}
tjd|
|
ddd}t|
p&|
}tjd|}tj|szt| W n, tk
r~   td| t d Y nX tj|stdd|
 d  t d qtd| d t| t|| ttj|dd d!d" W 5 Q R X td#| d$ qd S )%Nr   r   r   r   r   z' -- npm run buildr   r   r   r   r    u+   🚨 Finished updating component packages: r"   r#   r$   {}r   ,
components-_z/\Zdashu"   🚨 Having issues manipulating %suQ   🚨 Could not locate build artifacts. Check that the npm build process completedz successfully for package: u    🚨u!   🚚 Moving build artifacts from u    to Dash 🚚z.gitkeepwzutf-8)encodingu*   🟢 Finished moving build artifacts from u    to Dash 🟢)r%   r&   r'   r(   r   r)   r*   r+   r,   r-   r.   r   r/   ospathjoinreplacerstripdest_dir_mapgetexistsmakedirsOSErrorlogger	exceptionshutilrmtreecopytreeopen)r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   packageZbuild_directorydest_dir	dest_pathr   r   r   build_componentsH   sp    
   
  



rV   c                  C   s   t jdtdd} | jdddd | jdtd	d
d | jdddd |  }tjdkrl|j	dd	dd|_t
|j|j|jdkrdnd t|j|j d S )Nzdash-update-componentszUpdate the specified subcomponent libraries within Dash by copying over build artifacts, dependencies, and dependency metadata.)progformatter_classdescriptionr0   zA glob string that matches the Dash component libraries to be updated (eg.'dash-table' // 'dash-core-components|dash-html-components' // 'all'). The default argument is 'all'.r   )helpdefaultz--concurrency   zAMaximum concurrent steps, up to 3 (ie all components in parallel))typer[   rZ   z--ciz!For clean-install use '--ci True'Falser   "r   'Truecii)argparseArgumentParserr   add_argumentint
parse_argsr%   r&   r0   rF   r:   r1   rb   rV   )parserargsr   r   r   cli   sB    
   rk   __main__)r%   r)   r'   rC   rd   rO   loggingZcoloredlogsArgumentDefaultsHelpFormatterRawDescriptionHelpFormatterr   	getLoggerr   rM   installrH   r   r:   rV   rk   r   r   r   r   <module>   s4   
 
 $C'