o ]LbW @sDdZddlmZddlZddlZddlZddlmZddlm Z ddl m Z ddl m Z mZmZmZmZmZmZmZddlmZmZiZeeZz,ddlZeejd d ed d ddlmZej Wdn1sowYWn e!ydZYnwd Z"dedfdedfdedfdedfdedfgZ#e$dZ%dZ&edZ'Gddde(Z)Gddde(Z*dd Z+d!d"Z,d#d$Z-d%d&Z.d'd(Z/d)d*Z0d+d,Z1d-d.Z2d/d0Z3d1d2Z4d3d4Z5d5d6Z6ed7d8d9d:ed;ed<fd=d>d?ed@ed<fdAdBd?edCdfgedDej7dEdMdFdGZ8edHdIdJdMdKdLZ9dS)Na/generate release notes from commit messages (EXPERIMENTAL) It is common to maintain files detailing changes in a project between releases. Maintaining these files can be difficult and time consuming. The :hg:`releasenotes` command provided by this extension makes the process simpler by automating it. )absolute_importN)_)open)hex)cmdutilconfigerror logcmdutilminirstpycompat registrarutil)procutil stringutilignorez.*python-Levenshtein.*zfuzzywuzzy.fuzz)actionmessagecategorymodulesships-with-hg-coresfeatures New FeaturessbcsBackwards Compatibility Changesfixs Bug FixessperfsPerformance Improvementssapis API Changess#^\.\. ([a-zA-Z0-9_]+)::\s*([^$]+)?$s\bissue ?[0-9]{4,6}(?![0-9])\bs Other Changesc@sTeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ dS)parsedreleasenotescCs i|_dSNsectionsselfr4/usr/lib/python3/dist-packages/hgext/releasenotes.py__init__R zparsedreleasenotes.__init__cCs ||jvSrrrsectionrrr __contains__Urzparsedreleasenotes.__contains__cCstt|jSr)itersortedrrrrr__iter__Xszparsedreleasenotes.__iter__cCs.|j|ggf|j|d||fdS)z Add a titled release note entry.rNr setdefaultappend)rr!title paragraphsrrr addtitleditem[sz parsedreleasenotes.addtitleditemcCs*|j|ggf|j|d|dS)z[Adds a non-titled release note entry. Will be rendered as a bullet point. Nr&)rr!r*rrraddnontitleditem`sz#parsedreleasenotes.addnontitleditemcC|j|ggfdS)z|Returns titled entries in a section. Returns a list of (title, paragraphs) tuples describing sub-sections. rrgetr rrrtitledforsectionhsz#parsedreleasenotes.titledforsectioncCr.)z5Returns non-titled, bulleted paragraphs in a section.r,r/r rrrnontitledforsectionosz&parsedreleasenotes.nontitledforsectioncstfdd||DS)Nc3s|] }|dkVqdS)rNr.0tr)rr tsz8parsedreleasenotes.hastitledinsection..)anyr1)rr!r)rr6rhastitledinsectionssz%parsedreleasenotes.hastitledinsectionc Cs.ts |td|D]}t||t||}||D]>\}}|||r6|td||fq t||fgd}|dkrPt |}|rPt |||rPq t |||rWq | |||q ||D]/}|||vrnqdt|gd}|dkrt |}|rt |||rqdt |||rqd| ||qdq dS)z{Merge another instance into this one. This is used to combine multiple sources of release notes together. sKmodule 'fuzzywuzzy' not found, merging of similar releasenotes is disabled s*%s already exists in %s section; ignoring rrN)fuzzwarnr converttitledr1convertnontitledr2r9write getissuenum findissuesimilarr+r-) ruiotherr! existingnotesr)r* incoming_strissuerrrmergevsV      zparsedreleasenotes.mergeN) __name__ __module__ __qualname__rr"r%r+r-r1r2r9rGrrrrrQs rc@s.eZdZd ddZddZddZdd ZdS) releasenotessectionsNcCsF|rtt}t|}|r||tt||_dStt|_dSr) r sortdictDEFAULT_SECTIONSgetcustomadmonitionsupdatelistr iteritems _sections)rrBreporcustom_sectionsrrrrs  zreleasenotessections.__init__cCs t|jSr)r#rRrrrrr%rzreleasenotessections.__iter__cCsdd|jDS)NcSsg|]}|dqS)rrr3rrr sz.releasenotessections.names..rRrrrrnamesszreleasenotessections.namescCs$|jD] \}}||kr|SqdSrrV)rr)namevaluerrrsectionfromtitles z%releasenotessections.sectionfromtitler)rHrIrJrr%rWrZrrrrrKs    rKcCs>g}|D]\}}g}|D]}||q |d|q|S)z. Convert titled paragraphs to strings  extendr(join)titledparagraphs string_listr)r*linespararrrr<s  r<cCs:g}|D]}g}|D]}||q |d|q|S)z/ Convert non-titled bullets to strings r[r\)nontitledparagraphsr`r*rarbrrrr=s r=cCs tt|tj}|r|}|S)zD Returns issue number from the incoming string if it exists )researchRE_ISSUE IGNORECASEgroup)rErFrrrr?sr?cs0tfdd|Dr|tddSdS)z? Returns true if issue number already exists in notes. c3s|]}|vVqdSrrr4srFrrr7szfindissue..s'"%s" already exists in notes; ignoring TF)r8r>r)rBexistingrFrrkrr@sr@cCs<t|dkrt||}|s|td|dSdSdS)z? Returns true if similar note found in existing notes. s,"%s" already exists in notes file; ignoring TF)lensplitsimilaritycheckr>r)rBrlrErGrrrrAs rAcCs8tsdSd}|D]}t||}|dkrd}|Sq|S)zK Returns false when note fragment can be merged to existing notes. TKF)r:token_set_ratio)rErDrGbulletscorerrrrps rpcs>dtdfdd dvrddS)N.csB|vr|}||||dSttd|)Ns#.hgreleasenotes file '%s' not found)dataparserAbortrpathto)frremaprvctxpreadrSrrrs  z"getcustomadmonitions..reads.hgreleasenotesssections)NN)ritems)rSrr|rrNs   rNcs|D]_}||}tt|rad|vrq|tdd|ddffddfdd|D}t|dkrO|td |d q|rad t |}|td |qdS) a` Checks the commit messages for admonitions and their validity. .. abcd:: First paragraph under this admonition For this commit message, using `hg releasenotes -r . --check` returns: Invalid admonition 'abcd' present in changeset 3ea92981e103 As admonition 'abcd' is neither present in default nor custom admonitions r,s0Invalid admonition '%s' present in changeset %s N cstdd|S)Nr,)difflibSequenceMatcherrhratio)x) admonitionrrCs z"checkadmonitions..csg|] }|dkr|qS)g333333?rri)simrrrUGz$checkadmonitions..s(did you mean %s?) rs, s(did you mean one of %s?) ) rdre RE_DIRECTIVE descriptionrhr>rrrnr^r$)rBrS directivesrevsrevr}rAssr)rrrcheckadmonitions+s(   rcCs(|D]}|d|d|dfqdS)Ns%s: %s rr,)r>)rBrr!rrr_getadmonitionlistOsrcCs^t}|D]}||}tj||d\}}t|D]\}} | ddkr%q| d} | dr5| ddnd} |dt|krJtt d|| fg} t |dt|D]5} || }|dd krbqU|ddkrjn!|dd kr||j t d || f|d dkr| |dqU| s|j t d t|| r|| | | q|| | qq|S)N) admonitionstypes admonitionsadmonitiontitlelinesrr,s6changeset %s: release notes directive %s lacks contentmargin paragraphs=changeset %s: unexpected block in release notes directive %s indents.error parsing releasenotes for revision: '%s' )rr rwr enumeratestriprnrrxrrangerBr;r(rnoder+r-)rSrrnotesrr}blocksprunediblock directiver)r*jpblockrrrparsenotesfromrevisionsTs`        6rc st}t|ddfdd }d}tD]j\}}|ddkr"q|dd}|d d krR||}|s>ttd ||}||} | rQ| D]} ||| qHq|d d kry|t krl||} | D]} ||| qbq||d } | ||| qttd||S)z6Parse text content containing generated release notes.rFcs$g}t|dtD]}|}|ddkrq |ddkr!|S|ddkru|ddkr4ttd|rEd d |d D}||q d d |d Dg}|ddD]}|dd vran|ddkrn||d qW||q |ddkrttd|d|r||d q |S)Nr,rrsectionbulletrrs#indented bullet lists not supportedcSg|] }|ddqSr,Nrr4lrrrrUrzJparsereleasenotesfile..gatherparagraphsbullets..rcSrrrrrrrrUr)rrrs*unexpected block type in release notes: %s)rrnrrxrr()offsetr) notefragmentrrrarrrgatherparagraphsbulletssD        z6parsereleasenotesfile..gatherparagraphsbulletsNrrrs underline=s!unknown release notes section: %s-Tsunsupported section type for %s)F) rr rwrrZrrxrr-BULLET_SECTIONr+) rtextrrcurrentsectionrrr)rX bullet_pointsrbr*rrrparsereleasenotesfiles<%       rc Csg}|D]\}}||vr q|||dt||d||D];\}}|||dt||dt|D]\}}|rK|d|tjd|ddq@|dq%| |} ||r| r|t |dtt |d| D]9}|tjd|dddd d |d d D]}|d|tjd|dd d d q|dqq|r|d r|dd|S)zSerialize release notes from parsed fragments and notes. This function essentially takes the output of ``parsenotesfromrevisions()`` and ``parserelnotesfile()`` and produces output combining the 2. rrr[N)widthrs* s )r initindent hangindentr,N ) r(rnr1rr]rwrapr^ splitlinesr2r) rrra sectionname sectiontitler)r*rrb nontitledrrrserializenotessb                r releasenotesrrevrs&revisions to process for release notessREVccheckFs+checks for validity of admonitions (if any)llists/list the available admonitions with their titles"hg releasenotes [-r REV] [-c] FILE) helpcategoryc Ksft|}t||}t|dddg|drt||S|d}t||p(dg}|dr9t ||| |St || |}|durR| d| t||Szt|d}t||} Wdn1sjwYWnty} z| jtjkrt} WYd} ~ nd} ~ ww| ||t|d}| t|| WddS1swYdS) a parse release notes from commit messages into an output file Given an output file and set of revisions, this command will parse commit messages for release notes then add them to the output file. Release notes are defined in commit messages as ReStructuredText directives. These have the form:: .. directive:: title content Each ``directive`` maps to an output section in a generated release notes file, which itself is ReStructuredText. For example, the ``.. feature::`` directive would map to a ``New Features`` section. Release note directives can be either short-form or long-form. In short- form, ``title`` is omitted and the release note is rendered as a bullet list. In long form, a sub-section with the title ``title`` is added to the section. The ``FILE`` argument controls the output file to write gathered release notes to. The format of the file is:: Section 1 ========= ... Section 2 ========= ... Only sections with defined release notes are emitted. If a section only has short-form notes, it will consist of bullet list:: Section ======= * Release note 1 * Release note 2 If a section has long-form notes, sub-sections will be emitted:: Section ======= Note 1 Title ------------ Description of the first long-form note. Note 2 Title ------------ Description of the second long-form note. If the ``FILE`` argument points to an existing file, that file will be parsed for release notes having the format that would be generated by this command. The notes from the processed commit messages will be *merged* into this parsed set. During release notes merging: * Duplicate items are automatically ignored * Items that are different are automatically ignored if the similarity is greater than a threshold. This means that the release notes file can be updated independently from this command and changes should not be lost when running this command on that file. A particular use case for this is to tweak the wording of a release note after it has been added to the release notes file. The -c/--check option checks the commit message for invalid admonitions. The -l/--list option, presents the user with a list of existing available admonitions along with their title. This also includes the custom admonitions (if any). rrrs not public()Nrrbswb)r byteskwargsrKrcheck_incompatible_argumentsr0rr revrangerrWrpagerr>rrrrIOErrorerrnoENOENTrrG) rBrSfile_optsrrrincomingfhrerrr releasenotes/s8 o          "rsdebugparsereleasenotesT)norepoc Cs|dkr tj}nt|d }|}Wdn1swYt||}t||}|D]O}|td|||D]\}} |td|| D]} |tdd | qNq?| |D]} |td| D]} |tdd | qnqcq/dS) z6parse release notes and print resulting data structurerrNs section: %s s subsection: %s s paragraph: %s r[s bullet point: ) rstdinrrrKrr>rr1r^r2) rBpathrSrrrrr!r)r*rbrrrdebugparsereleasenotess*     rr):__doc__ __future__rrrrdmercurial.i18nrmercurial.pycompatrmercurial.noder mercurialrrrr r r r r mercurial.utilsrrcmdtablecommandwarningscatch_warningsfilterwarnings UserWarningfuzzywuzzy.fuzzr:rr ImportError testedwithrMcompilerrfrobjectrrKr<r=r?r@rArprNrrrrrCATEGORY_CHANGE_NAVIGATIONrrrrrrs    (           ]    $COI  u