
    e                     ^    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  G d de          Z	dS )    N)Argument
Subcommand   )convert_appsc                      e Zd ZdZdZdZd edddd	          fd
 ededd          fd eddd          fd eded          fd eded          fd edd          fd edd          fd edd           fd! ed"d#$          fd% eddd&          fd' edd(          fd) ede	d*d+,          ffZ
d-Zd.ej        d/dfd0ZdS )1Convertz^ Subcommand to convert Panel application to some build target, e.g. pyodide or pyscript.

    convertz8Convert a Panel App to another format, e.g. a HTML file.fileszDIRECTORY-OR-SCRIPT*zOThe app directories or scripts to serve (serve empty document if not specified)N)metavarnargshelpdefaultz--tostorezTThe format to convert to, one of 'pyodide' (default), 'pyodide-worker' or 'pyscript'pyodide)actiontyper   r   z
--compiledFstore_falsez:Whether to use the compiled and faster version of Pyodide.)r   r   r   z--outz#The directory to write the file to.)r   r   r   z--titlez&A custom title for the application(s).z--skip-embed
store_truezmWhether to skip embedding pre-rendered content in the converted file to display content while app is loading.)r   r   z--indexz8Whether to create an index if multiple files are served.z--pwazDWhether to add files to serve applications as a Progressive Web App.z--requirements+zExplicit requirements to add to the converted file, a single requirements.txt file or a JSON file containing requirements per app. By default requirements are inferred from the code.)r   r   z--disable-http-patchzIWhether to disable patching http requests using the pyodide-http library.z--watchzWatch the filesz--num-procs   zAThe number of processes to start in parallel to convert the apps.)r   r   r   r   )pyscriptr   zpyodide-workerargsreturnc                   
 |j                                         }|| j        vrt          d| j                  |j        pd}t          |t                    rt          |          dk    rt          j	        |d                   
                                rx|d         }|                    d          r	|d         }nR|                    d          r=t          |d          5 }t          j        |          }d d d            n# 1 swxY w Y   i 
d	}	 d |j        D             }|
k    rt!          j        d           -
fd|                                D             }|j        o| }		 t)          ||j        |||j         |	|j        |j        |j        |j         |j        d
           n # t8          $ r t;          d           Y d S w xY wd
}|
|j        sd S )Nz&Supported conversion targets include: autor   r   z.txtz.jsonzutf-8)encodingFTc                 l    i | ]1}|t          t          |                                                    2S  )hashopenread).0fs     5lib/python3.11/site-packages/panel/command/convert.py
<dictcomp>z"Convert.invoke.<locals>.<dictcomp>j   s0    BBB!ad1ggllnn--BBB    g      ?c                 L    g | ] \  }}                     |          |k    |!S r   )get)r#   r$   hprev_hashess      r%   
<listcomp>z"Convert.invoke.<locals>.<listcomp>n   s3    MMM41a[__Q5G5G15L5LQ5L5L5Lr'   )	dest_pathruntimerequirements	prerenderbuild_index	build_pwatitlemax_workers
http_patchcompiledverbosezAborted while building docs.)tolower_targets
ValueErrorr/   
isinstancelistlenpathlibPathis_fileendswithr!   jsonloadr
   timesleepitemsindexr   out
skip_embedpwar3   	num_procsdisable_http_patchr6   KeyboardInterruptprintwatch)selfr   r.   r/   reqreq_filebuilthashesr
   rH   r+   s             @r%   invokezConvert.invokeW   sT   '--//$-''WdmWWXXX(2F|T**
	7""La))1133 # q/C||F## 7+Ag&& 7#000 7H#'9X#6#6L7 7 7 7 7 7 7 7 7 7 7 7 7 7 7	BBtzBBBF$$
3MMMM6<<>>MMMEJ,u9E
TXw\"&/1uPTPX*$.#'#::T]      %   4555 E K: +	s%   $DD	D	,A F- -G
	G
)__name__
__module____qualname____doc__namer   r   dictstrintr   r:   argparse	NamespacerV   r   r'   r%   r   r      s'        
 DED 
((+g	
 
 
 	 
l	
 
 
 	 
tt#R
 
 
 	
 
$$;
 
 
 	
 
DD>
 
 
 	
 
" F
 
 
 	 
DD"P
 
 
 	 
$$"\
 
 
 	 
44q
 
 
 	 
 #a"
 "
 "
 	
 
DD"'
 
 
 	 
Y	
 
 
 	q>D@ 9H'8- '$ ' ' ' ' ' 'r'   r   )
r_   rC   r?   rE   bokeh.command.subcommandr   r   
io.convertr   r   r   r'   r%   <module>rc      s        9 9 9 9 9 9 9 9 % % % % % %s s s s sj s s s s sr'   