a
    pDf                     @   sP   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 deZ	dS )    N)Argument
Subcommand   )convert_appsc                   @   s   e Zd ZdZdZdZdeddddd	fd
ededddfdeddddfdededdfdededdfdedddfdedddfdedd dfd!ed"d#d$fd%eddd&dfd'edd(dfd)ede	d*d+d,ffZ
d-Zejdd.d/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   )Zpyscriptr   zpyodide-workerzpyscript-worker)argsreturnc           
         sr  |j  }|| jvr$td| j|jp,d}t|trt|dkrt	|d 
 r|d }|drr|d }n@|drt|dd}t|}W d    n1 s0    Y  i  d	}d
d |jD }| krtd q fdd| D }|jo| }	z6t||j|||j |	|j|j|j|j |jdd W n" tyX   td Y qnY n0 d}| |jsd S qd S )Nz&Supported conversion targets include: autor   r   z.txtz.jsonzutf-8)encodingFc                 S   s   i | ]}|t t| qS  )hashopenread).0fr   r   b/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/panel/command/convert.py
<dictcomp>j       z"Convert.invoke.<locals>.<dictcomp>g      ?c                    s"   g | ]\}}  ||kr|qS r   )get)r   r   hZprev_hashesr   r    
<listcomp>n   r"   z"Convert.invoke.<locals>.<listcomp>T)	dest_pathruntimerequirementsZ	prerenderZbuild_indexZ	build_pwatitlemax_workersZ
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   outZ
skip_embedZpwar*   Z	num_procsZdisable_http_patchr,   KeyboardInterruptprintZwatch)
selfr   r(   r)   reqreq_filebuilthashesr   r>   r   r%   r    invokeW   sN    






(



zConvert.invoke)__name__
__module____qualname____doc__namer   r   dictstrintr   r0   argparse	NamespacerG   r   r   r   r    r      s   @r   )
rP   r9   r5   r;   Zbokeh.command.subcommandr   r   Z
io.convertr   r   r   r   r   r    <module>   s   