3 F\,@sddlmZddlZddlmZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddl mZd,dd Zd d Zd d ZddZddZd-ddZddZddZddZd.ddZddZdd Zd/d!d"Zd#d$Zd%d&Zdejjddfd'd(Z dd)e!fd*d+Z"dS)0)unicode_literalsN)log)options)versionFTc Cs|rtj}tj}nd}d}tjj}|r2|j|tj||||d}|j}|jrl|rlt j j d||jft |dks|d s|dj rdS|dj jddS)N)stdoutstderrenvz%s returned %drzutf-8replace) subprocessPIPEosenvironcopyupdatePopen communicate returncode distutilserrorsDistutilsErrorlenstripdecode) cmdZthrow_on_errorbufferrZ out_locationZ err_locationZnewenvoutputoutr\/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/pbr/pbr/git.py_run_shell_command"s&   $r cKs,t|ttfs|g}tdd|g|f|S)Ngitz --git-dir=%s) isinstancelisttupler )rgit_dirkwargsrrr_run_git_command=sr'cCsHytdddgStk rB}z|jtjkr0dSWYdd}~XnXdS)Nr!z rev-parsez --git-dirr )r OSErrorerrnoENOENT)errr_get_git_directoryDs  r,c Cs*ytddgWntk r$dSXdS)Nr!z --versionFT)r r(rrrr_git_is_installedNs r-cCst|tjdS)zFind the highest tag from a list. Pass in a list of tag strings and this will return the highest (latest) as sorted by the pkg_resources version parser. )key)max pkg_resources parse_version)tagsrrr_get_highest_tagYsr3r cCsLg}|dkrt}|r>tjdtddg|}|jdjd}dd|DS) zBehave like a file finder entrypoint plugin. We don't actually use the entrypoints system for this because it runs at absurd times. We only want to do this when we are building an sdist. Nz2[pbr] In git context, generating filelist from gitzls-filesz-zzutf-8cSsg|] }|r|qSrr).0frrr qsz#_find_git_files..)_run_git_functionsrinfor'splitr)dirnamer% file_listrrr_find_git_filesbs r=cCs6tddg|}d|kr&|jdddSd|kr2dSdS)Ndescribez--always-.r)r'rsplit)r%r>rrr_get_raw_tag_infots rDcCs t|dkS)Nr)rD)r%rrrget_is_release}srEcCsd}trt}|pdS)N)r-r,)r%rrrr8sr8cCs"|s t}|rtdddg|SdS)z1Return the short sha for this repo, if it exists.rz-n1z--pretty=format:%hN)r8r')r%rrrget_git_short_shas rFcCs(|jdd}|jdd}|jdd}|S)aCleans any instances of invalid sphinx wording. This escapes/removes any instances of invalid characters that can be interpreted by sphinx as a warning or error when translating the Changelog into an HTML file for documentation building within projects. * Escapes '_' which is interpreted as a link * Escapes '*' which is interpreted as a new line * Escapes '`' which is interpreted as a literal *z\*_z\_`z\`)r )msgrrr_clean_changelog_messages   rKccsd}d}|dfVx|D]\}}}|r^t|}t|d}|sH|dfV|dt||dfV|jds|jd r~|dd}t|}|d t|d fVd }qWdS)zConvert a oneline log iterator to formatted strings. :param changelog: An iterator of one line log entries like that given by _iter_log_oneline. :return: An iterator over (release, formatted changelog) tuples. TNzCHANGES ======= r? z%(tag)s %(underline)s )tag underlinezMerge rAz * %(msg)s )rJF)r3rdict startswithendswithrK) changelog first_lineZcurrent_releasehashr2rJrNrrr_iter_changelogs$      rWcCs|dkrt}|sgSt|S)aQIterate over --oneline log entries if possible. This parses the output into a structured form but does not apply presentation logic to the output - making it suitable for different uses. :return: An iterator of (hash, tags_set, 1st_line) tuples, or None if changelog generation is disabled / not available. N)r,_iter_log_inner)r%rrr_iter_log_onelines rYc Cs*ytjj|dStk r$dSXdS)NTF)rZSemanticVersionZfrom_pip_string ValueError) candidaterrr_is_valid_versions  r\c cstjddddg}t||}x|jdD]}|jd}t|dkrFq*|\}}}t}d|kr|jd d }x:|jdd d D]$} | jd d } t| r|j| qW|||fVq*Wd S)aIterate over --oneline log entries. This parses the output intro a structured form but does not apply presentation logic to the output - making it suitable for different uses. :return: An iterator of (hash, tags_set, 1st_line) tuples. z[pbr] Generating ChangeLogrz--decorate=fullz--format=%h%x00%s%x00%drLz refs/tags/rONz, rrP) rr9r'r:rsetrr\add) r%Zlog_cmdrTlineZ line_partssharJZrefnamer2Z tag_stringr[rrrrXs      rXc Cstj}|si}tj|dd}|r&dS|s@t|d}|r@t|}|sHdStjj|d}tjj|rtj |tj  rt j ddSt j dt j|dd d "}x|D]\}} |j| qWWdQRXtj} t j d | |dS) z-Write a changelog based on the git changelog.Zskip_changelogZSKIP_WRITE_GIT_CHANGELOGN)r%Z ChangeLogzI[pbr] ChangeLog not written (file already exists and it is not writeable)z[pbr] Writing ChangeLogwzutf-8)encodingz![pbr] ChangeLog complete (%0.1fs))timerget_boolean_optionrYrWr pathjoinexistsaccessW_OKrr9ioopenwrite) r%dest_dir option_dictrTstart should_skipZ new_changelogZchangelog_filereleasecontentstoprrrwrite_git_changelogs0    rvrAcsjtj|dd}|rdStj}tjj|d}tjj|d}tjj|rZtj|tj rZdSt j dd|dkrvt }|rLg}dd g}|t ||j d 7}fd d |D}t d|} tjd | tj} dd | D} || 7}tt|}t|dR} tjj|r(t|d} | j| jWdQRX| jd j|d jdWdQRXtj} t j d| |dS)z&Create AUTHORS file using git commits.Z skip_authorsZSKIP_GENERATE_AUTHORSNz AUTHORS.inZAUTHORSz[pbr] Generating AUTHORSz5((jenkins|zuul)@review|infra@lists|jenkins@openstack)rz--format=%aN <%aE>rLcsg|]}tj|s|qSr)research)r5a) ignore_emailsrrr78sz$generate_authors..zCo-authored-by:.+cSs$g|]}|r|jdddjqS):rO)r:r)r5signedrrrr7>swbrbzutf-8z[pbr] AUTHORS complete (%0.1fs))rrfrer rgrhrirjrkrr9r,r'r:rwfindall MULTILINEsortedr_rmrnreadencode)r%rorprrrqZ old_authorsZ new_authorsZauthorsZ git_log_cmdZco_authors_outZ co_authorsZnew_authors_fhZold_authors_fhrur)rzrgenerate_authors!sD      r)FTN)r N)N)N)# __future__rdistutils.errorsrrr)rlr rwr rer0Zpbrrrr r'r,r-r3r=rDrEr8rFrKrWrYr\rXrgcurdirrvrQrrrrrs:           '