o
    is                  	   @   s  d dl mZ d dlmZmZ ddlmZmZ ddlm	Z	m
Z
mZmZ dZde	 d	e	 d
e dZde dZde dZde dZdZdZdZdZede
e ddddedddddedd d!d"dfd#ed$ed%efd&d'Zdd(d#ed$ed%ed)d*fd+d,Zd*S )-    )Path)MarkdownRenderermsg   )load_project_configworking_dir   )PROJECT_FILEArgOptappz#https://github.com/explosion/weaselzThe [`z`](z) defines the data assets required by the
project, as well as the available commands and workflows. For details, see the
[Weasel documentation](z).zdThe following commands are defined by the project. They
can be executed using [`weasel run [name]`](zZ/tree/main/docs/cli.md#rocket-run).
Commands are only re-run if their inputs have changed.zeThe following workflows are defined by the project. They
can be executed using [`weasel run [name]`](z/tree/main/docs/cli.md#rocket-run)
and will run the specified commands in order. Commands are only re-run if their
inputs have changed.zbThe following assets are defined by the project. They can
be fetched by running [`weasel assets`](zI/tree/main/docs/cli.md#open_file_folder-assets)
in the project directory.)WEASELzSPACY PROJECTz9<!-- {tag}: AUTO-GENERATED DOCS START (do not remove) -->z7<!-- {tag}: AUTO-GENERATED DOCS END (do not remove) -->z<!-- {tag}: IGNORE -->documentz>Path to cloned project. Defaults to current working directory.TF)helpexists	file_okay-z--outputz-ozJPath to output Markdown file for output. Defaults to - for standard output)r   z
--no-emojiz-NEzDon't use emojiproject_diroutput_fileno_emojic                 C   s   t | ||d dS )al  
    Auto-generate a README.md for a project. If the content is saved to a file,
    hidden markers are added so you can add custom content before or after the
    auto-generated section and only the auto-generated docs will be replaced
    when you re-run the command.

    DOCS: https://github.com/explosion/weasel/tree/main/docs/cli.md#closed_book-document
    r   N)project_document)r   r   r    r   G/home/ubuntu/.local/lib/python3.10/site-packages/weasel/cli/document.pyproject_document_cli   s   r   r   returnNc             	      s  t |dk}t| }t|d  tjdd |d}|d}  dd|r/d	| nd
 d |r= |   dtd  t	 |dg } fdd|D }|rw  ddd  t
   |ddg |di  }	 fdd|	D }|r  ddd  t   |ddg |dg }
g }|
D ]K}|drdn|drd nd!}|d" } |}|d!krt| }||  rވ ||}W d    n1 sw   Y  ||||dd
f q|r  dd#d$  t   |g d%  tjdd |r*t j d S  j}| r|jd&d'd(}| }W d    n	1 sIw   Y  tD ]}tj|d|v rdtd)|  d S qPd*}tD ]A}tj|dtj|dd+}|d, |v r|d- |v rd.}td/ ||d, d0 }||d- d }| | | } nqj|std1 |jd2d'd(}|| W d    n	1 sw   Y  t d3| d S )4Nr   r   r   )tagtitledescriptionr   zWeasel Projectz:  u   🪐r   u   📋commandsc                    s&   g | ]}  |d  |ddfqS )namer   r   )codeget).0cmdmdr   r   
<listcomp>B   s   & z$project_document.<locals>.<listcomp>   Commandsu   ⏯CommandDescription	workflowsc                    s2   g | ]\}}  |d  fdd|D fqS )z &rarr; c                 3   s    | ]}  |V  qd S )N)r"   )r$   wr&   r   r   	<genexpr>I   s    z.project_document.<locals>.<listcomp>.<genexpr>)r"   join)r$   nstpr&   r   r   r(   I   s   2 	Workflowsu   ⏭WorkflowStepsassetsgitGiturlURLLocaldestAssetsu   🗂)FileSourcer,   rutf8)encodingz.Found ignore marker in existing file: skippingF)startendrC   rD   Tz7Found existing file: only replacing auto-generated docsr   zReplacing existing filer.   zSaved project documentation)!strr   r   addMARKER_STARTformatr#   r   r	   INTRO_PROJECTINTRO_COMMANDStableitemsINTRO_WORKFLOWSr"   r   r   linkappendINTRO_ASSETS
MARKER_ENDprinttextopenreadMARKER_TAGSMARKER_IGNOREr   warninfosplitwritegood)r   r   r   	is_stdoutconfigr   r   cmdsdatawfsr6   asource	dest_pathr<   pcontentfexisting
marker_tagmarker_tag_foundmarkersbeforeafterr   r&   r   r   2   s   


(



 








r   )pathlibr   wasabir   r   utilr   r   mainr	   r
   r   r   DOCS_URLrI   rJ   rM   rP   rV   rG   rQ   rW   commandcwdboolr   r   r   r   r   r   <module>   sT    