
    -Ph8                        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lm	Z	 d dl
mZmZmZmZmZmZmZ d dlmZ d dlmZ d d	lmZ d=dZ G d d          Zd>dZd?dZ	 d@dAd$Z G d% d&e          ZdBd(ZdCd,ZdDd.Z dEd1Z!	 	 	 dFdGd<Z"dS )H    )annotationsN)defaultdict)fnmatch)Path)AnyDefaultDictIterableIteratorMapping
NamedTupleSequence)ClickException)Template)Configbasenamestrfrag_type_namesIterable[str]return.tuple[str, str, int] | tuple[None, None, None]c                B   d}|                      d          }t          |          dk    r|S t          t          dt          |                              D ]}||         |v r||         }d                    |d|                                                   }|                                rt          t          |                    }d}t          |          |dz   k    r5||dz                                            rt          ||dz                      }|||fc S |S )N)NNN.   r   )	splitlenreversedrangejoinstripisdigitr   int)r   r   invalidpartsicategoryissuecounters           R/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/towncrier/_builder.pyparse_newfragment_basenamer)      s"    !GNN3E
5zzQ eAs5zz**++  8&&QxH
 HHU1Q3Z((..00E }} (CJJG 5zzQU##a!e(<(<(>(>#eAEl++(G++++# '(     c                  $    e Zd ZdZddZddd
ZdS )FragmentsPathz
    A helper to get the full path to a fragments directory.

    This is a callable that optionally takes a section directory and returns the full
    path to the fragments directory for that section (or the default if no section is
    provided).
    base_directoryr   configr   c                x   || _         || _        |j        Pt          j                            t          j                            ||j                            | _         d| _        d S t          j                            t          j                            ||j        |j	                            | _         d| _        d S )N newsfragments)
r-   r.   	directoryospathabspathr   append_directorypackage_dirpackage)selfr-   r.   s      r(   __init__zFragmentsPath.__init__F   s    ,'"$'//^V-=>># #D %'D!!!"$'//^V-?PP# #D %4D!!!r*   r0   section_directoryr   c                X    t           j                            | j        || j                  S N)r3   r4   r   r-   r6   )r9   r;   s     r(   __call__zFragmentsPath.__call__T   s(    w||!2D4I
 
 	
r*   N)r-   r   r.   r   )r0   )r;   r   r   r   )__name__
__module____qualname____doc__r:   r>    r*   r(   r,   r,   =   sK         4 4 4 4
 
 
 
 
 
 
r*   r,   r-   r.   r   strictboolNtuple[Mapping[str, Mapping[tuple[str, str, int], str]], list[tuple[str, str]]]c           	        h d}t          |j        t                    r7|                    t          j                            |j                             |j        r$|                    d |j        D                        t          | |          }i }g }t          t                    }|j                                        D ]\  }}	 ||	          }		 t	          j        |	          }
n# t          $ r g }
Y nw xY wi }|
D ]at!          fd|D                       rt#          |j                  \  }}}||r|t'          d d          R|J |J |j        r4|                    |j                  rd}||         }||xx         dz  cc<   |j        r7|r5t/          j        |j        |          st'          d	| d
|j         d          t          j                            |	          }|                    ||f           t7          |                              dd          }|||f|v r$t;          d                    |||	                    |||||f<   c|||<   ||fS )z
    Sections are a dictonary of section names to paths.

    If strict, raise ClickException if any fragments have an invalid name.
    >   .keep.gitkeep	readme.md
.gitignore
readme.rstreadmec              3  >   K   | ]}|                                 V  d S r=   )lower).0filenames     r(   	<genexpr>z!find_fragments.<locals>.<genexpr>   s,      LL(X^^--LLLLLLr*   c                T    g | ]$}t                                          |          %S rC   )r   rO   )rP   ignore_patternr   s     r(   
<listcomp>z"find_fragments.<locals>.<listcomp>   s=       & HNN,,n==  r*   NzInvalid news fragment name: zJ
If this filename is deliberate, add it to 'ignore' in your configuration.r0   r   zIssue name 'z*' does not match the configured pattern, ''zutf-8replace)encodingerrorszmultiple files for {}.{} in {})
isinstancetemplater   addr3   r4   r   ignoreupdater,   r   r!   sectionsitemslistdirFileNotFoundErroranyr)   typesr   orphan_prefix
startswithissue_patternre	fullmatchr   appendr   	read_text
ValueErrorformat)r-   r.   rD   ignored_filesget_section_pathcontentfragment_filesorphan_fragment_counterkeysection_dirfilesfile_contentr&   r%   r'   full_filenamedatar   s                    @r(   find_fragmentsry   l   sX     M &/3'' = 	"'**6?;;<<<} MLLfmLLLLLL$^V<<GN =H<L<L"O1133 ;$ ;$[&&{33	J{++EE  	 	 	EEE	  /	: /	:H   *7     'A&,( ($E8W  em(:x : : :  
 $$$&&&# 7(8(89M(N(N 71(;'111Q6111 $ V%95AA
 %D5 D D,2,@D D D   GLLh??M!!=(";<<<&&00')0TTDx)\99 4;;x   
 6:L'122#N""s   C**C98C9textprefixc                N     d fd}d                      |                      S )zF
    Adds `prefix` to the beginning of non-empty lines in `text`.
    r   Iterator[str]c               3  v   K                        d          D ]} |                                 r| z   n| V   d S )NT)
splitlinesr   )liner{   rz   s    r(   prefixed_lineszindent.<locals>.prefixed_lines   sP      OOD)) 	< 	<D$(JJLL:6D==d;;;;	< 	<r*   r0   )r   r}   )r   )rz   r{   r   s   `` r(   indentr      sC    < < < < < < < 77>>##$$$r*   T	fragments0Mapping[str, Mapping[tuple[str, str, int], str]]definitionsMapping[str, Mapping[str, Any]]all_bullets7Mapping[str, Mapping[str, Mapping[str, Sequence[str]]]]c                   i }|                                  D ]\  }}i }|                                 D ]\  \  }}}	}
|r+t          |
                                d          dd          }
n|
                                }
||         d         du r|rd}
|                    |i           }|                    |
g           }|r)|                    |           |                                 |||<   |S )N     showcontentFr0   )r`   r   r   rstrip
setdefaultrj   sort)r   r   r   outputsection_namesection_fragmentssectionr&   r%   r'   rp   textsissuess                r(   split_fragmentsr      s   
 F+4??+<+< ' '''353D3J3J3L3L 	 	/&UHg + !$77; "..**8$]3u<<<
 &&x44E%%gr22F  e$$$&|Mr*   c                  8    e Zd ZU ded<   ded<   ded<   ded<   dS )	
IssuePartsrE   is_digit	has_digitr   non_digit_partr!   numberN)r?   r@   rA   __annotations__rC   r*   r(   r   r     s7         NNNOOOKKKKKr*   r   r&   c           	        |                                  r t          dddt          |                     S t          j        d|           }|st          dd| d          S t          dd| d|                                         | |                                d         z   t          |                                                    S )a  
    Used to sort the issue ID inside a news fragment in a human-friendly way.

    Issue IDs are grouped by their non-integer part, then sorted by their integer part.

    For backwards compatible consistency, issues without no number are sorted first and
    digit only issues are sorted last.

    For example::

    >>> sorted(["2", "#11", "#3", "gh-10", "gh-4", "omega", "alpha"], key=issue_key)
    ['alpha', 'omega', '#3', '#11', 'gh-4', 'gh-10', '2']
    Tr0   )r   r   r   r   z\d+FN)r    r   r!   rh   searchstartendgroup)r&   matchs     r(   	issue_keyr     s     }} 
T"SZZ
 
 
 	
 Ife$$E 
eE"
 
 
 	
 _u{{}}_-eiikkmm0DD5;;==!!	   r*   entrytuple[str, Sequence[str]]tuple[str, list[IssueParts]]c                0    | \  }}|rdn|d |D             fS )Nr0   c                ,    g | ]}t          |          S rC   )r   )rP   r&   s     r(   rU   zentry_key.<locals>.<listcomp>0  s     &L&L&LEy'7'7&L&L&Lr*   rC   )r   rp   r   s      r(   	entry_keyr   -  s.    OGV$22W&L&LV&L&L&LLLr*   r!   c                x    | \  }}|sdS |d d         dk    rdS |d d         dk    rdS |d d         dk    rdS dS )	Nr   r   - r   * r      #. rC   )r   rz   _s      r(   
bullet_keyr   3  se    GD! rBQBx4q	bqbT		q	bqbU		q1r*   issue_format
str | Nonec                    | '	 t          |           d|z   S # t          $ r |cY S w xY w|                     |          S )N#)r&   )r!   	Exceptionrm   )r   r&   s     r(   render_issuer   @  s_    	JJJ; 	 	 	LLL	 """///s    ''=Fr[   
underlinesSequence[str]wrapversiondataMapping[str, str]top_underlinerender_titlec
           
        t          | d          }
i }i }|                                D ]\  }}i ||<   i ||<   |                                D ]\  }}t                      }g }|                                D ]E\  }}|                    |t	          |t
                    f           |                    |           F|                    t                     s|                    t                     i }|D ]\  }}fd|D             }|||<   |||         |<   fdt	          |t
                    D             ||         |<   !g }dfd	}|

                    |	|||||||
          }|                    d          D ]O}|r6|                    t          j        |d ||          dd                     :|                    |           Pd                    |          S )z0
    Render the fragments into a news file.
    T)trim_blocks)rs   c                0    g | ]}t          |          S rC   r   rP   r$   r   s     r(   rU   z$render_fragments.<locals>.<listcomp>  s#    JJJaLq99JJJr*   c                0    g | ]}t          |          S rC   r   r   s     r(   rU   z$render_fragments.<locals>.<listcomp>  s3     ? ? ? \1--? ? ?r*   rz   r   r   c                h    s| d d         dk    s| d d         dk    rdS | d d         dk    rdS dS )	Nr   r   r   r   r   r   z   r0   rC   )rz   r   s    r(   
get_indentz$render_fragments.<locals>.get_indent  sS      	$rr(d**d2A2h$.>.>4"1"X5rr*   )r   r_   r   r   r   r   r   issues_by_category
O   F)widthsubsequent_indentbreak_long_wordsbreak_on_hyphens)rz   r   r   r   )r   r`   setrj   sortedr   r^   r   r   r   renderr   textwrapfillr   )r[   r   r   r   r   r   r   r   r   r   jinja_templaterx   r   r   section_valuecategory_namecategory_valuecategory_issuesentriesrz   r   
categoriesrendereddoner   resr   s    `      `                  r(   render_fragmentsr   K  s     hD999N79D:<'0'8'8 ' '#m\+-<(-:-@-@-B-B #	 #	)M>(+O G . 4 4 6 6 / /ffV&C&C&CDEEE&&v.... LLYL''' -,,, J ' , ,fJJJJ6JJJ#+
4  0:D}-? ? ? ?Y???? ? ?|,];;A#	J D      

!#-   	 	C 		$   	KK&0j&6&6%*%*      KK99T??r*   )r   r   r   r   r   r   )r-   r   r.   r   rD   rE   r   rF   )rz   r   r{   r   r   r   )T)r   r   r   r   r   rE   r   r   )r&   r   r   r   )r   r   r   r   )r   r   r   r!   )r   r   r&   r   r   r   )r   FT)r[   r   r   r   r   r   r   r   r   r   r   rE   r   r   r   r   r   rE   r   rE   r   r   )#
__future__r   r3   rh   r   collectionsr   r   pathlibr   typingr   r   r	   r
   r   r   r   clickr   jinja2r   towncrier._settings.loadr   r)   r,   ry   r   r   r   r   r   r   r   r   rC   r*   r(   <module>r      s  
 # " " " " " 				 				  # # # # # #             V V V V V V V V V V V V V V V V V V                   + + + + + +
" " " "J
 
 
 
 
 
 
 
^_# _# _# _#D
% 
% 
% 
%& & & & & &R          >M M M M
 
 
 
0 0 0 0& c c c c c c cr*   