B <_"@sdZddlZddlZddlZddlZddlZddlZddlZddl Z ej dddej dddej dddej dd ej dd gZ e d Zd d ZdFddZddZddZeddddddZedddddGddZdd Zed!edd"d#Zed$edd%d&Zed'Zed(edd)d*Zed+d,d-d.d/Zed0d,d-d1d2Zed3d,d-d4d5Zed6d,ed7d8d9Zed:d,ed7d;d<Z d=d>Z!d?d@Z"e#dAkrddl$Z$e$j%edBZ&e&j'dCdDdEe&(Z)e)j!re!e)j!ne"dS)Hz)Check proposed changes for common issues.NZModulesZ_ctypesZ libffi_osxZ libffi_msvcZ_decimalZlibmpdecZexpatzlibZsrcdircCsd||dkrdndS)z7Return 'N file(s)' with the proper plurality on 'file'.z {} file{}s)format)countr=/opt/alt/python37/lib64/python3.7/Tools/scripts/patchcheck.py n_files_strsr Fcsfdd}|S)z*Decorator to output status info to stdout.csfdd}|S)Ncs\tjdtj||}s6s6tdn"rHt|nt|rRdnd|S)Nz ... ZdoneyesZNO)sysstdoutwriteflushprint)argskwargsresult)fxninfomessagemodalrr call_fxn s   z/status..decorated_fxn..call_fxnr)rr)rrr)rr decorated_fxns zstatus..decorated_fxnr)rrrrr)rrrr statuss rcCs6d}ytj|tjtdStjk r0dSXdS)z0Get the symbolic name for the current git branchzgit rev-parse --abbrev-ref HEAD)stderrcwdN)split subprocess check_outputDEVNULLSRCDIRCalledProcessError)cmdrrr get_git_branch/sr$cCs:d}ytj|tjtdWntjk r4dSXdS)zkGet the remote name to use for upstream branches Uses "upstream" if it exists, "origin" otherwise zgit remote get-url upstream)rroriginZupstream)rrrr r!r")r#rrr get_git_upstream_remote:s r&zGetting base branch for PRcCs|dk r |SdS)Nznot a PR branchr)xrrr Jr()rcCsftjtjtdsdStj}|jdkr0d}n d|}t }|dksP||krTdSt }|d|S)Nz.gitZalphaZmasterz{0.major}.{0.minor}/) ospathexistsjoinr!r version_info releaselevelrr$r&)version base_branchZ this_branchZupstream_remoterrr get_base_branchIs  r3z6Getting the list of files that have been added/changedcCs tt|S)N)r len)r'rrr r(]r)c stjtjtdr|r$d|}nd}g}tj|tjtdl}xd|j D]Z}| }|jdd\}t |}| dsqLdkrdd d|qLWWd QRXn td g}x:|D]2tjtfd d tDrq|qW|S)z0Get the list of changed or added files from git.z.gitzgit diff --name-status zgit status --porcelain)r rr)maxsplitZMAUz -> Nz)need a git checkout to get modified filesc3s|]}|VqdS)N) startswith).0r,)filenamerr ~sz changed_files..)r+r,r-r.r!rPopenrPIPEr decoderstripset intersectionstripappendr exitnormpathany EXCLUDE_DIRS)r2r# filenamesstlineZ status_textrZ filenames2r)r9r changed_files\s2         rJcCsTt|}|dkrt|Sdt|g}x|D]}|d|q.Wd|SdS)Nrz{}:z {} )r4r rrBr.) file_pathsrlinesr,rrr report_modified_filess rNzFixing Python file whitespacecCsdt_dd|D}|S)zAMake sure that the whitespace for .py files have been normalized.FcSs.g|]&}|drttjt|r|qS)z.py)endswithreindentZcheckr+r,r.r!)r8r,rrr s z(normalize_whitespace..)rPZ makebackup)rLfixedrrr normalize_whitespacesrSzFixing C file whitespacec Csbg}xX|D]P}tjt|}t|d}d|kr6w WdQRXtj|ddd||q W|S)zReport if any C files r NF)verbose) r+r,r.r!openreaduntabifyZprocessrB)rLrRr,abspathfrrr normalize_c_whitespaces    r]s \s+(\r?\n)$zFixing docs whitespacec Csg}x|D]}tjt|}yrt|d}|}WdQRXdd|D}||krt||dt|d}||WdQRX| |Wq t k r}zt d||fWdd}~XYq Xq W|S)NrbcSsg|]}td|qS)s\1)ws_resub)r8rIrrr rQsz-normalize_docs_whitespace..z.bakwbzCannot fix %s: %s) r+r,r.r!rX readlinesshutilZcopyfile writelinesrB Exceptionr)rLrRr,r[r\rMZ new_lineserrrrr normalize_docs_whitespaces   &rgz Docs modifiedT)rcCst|S)z9Report if any file in the Doc directory has been changed.)bool)rLrrr docs_modifiedsrizMisc/ACKS updatedcCstjdd|kS)z$Check if Misc/ACKS has been changed.MiscZACKS)r+r,r.)rLrrr credit_givensrkz Misc/NEWS.d updated with `blurb`cCstdd|DS)z&Check if Misc/NEWS.d has been changed.css$|]}|tjdddVqdS)rjzNEWS.dnextN)r7r+r,r.)r8prrr r:sz reported_news..)rE)rLrrr reported_newssrnzconfigure regenerated)rrcCs d|krd|krdSdSdSdS)z(Check if configure has been regenerated.z configure.acZ configurer noz not neededNr)rLrrr regenerated_configuresrpzpyconfig.h.in regeneratedcCs d|krd|krdSdSdSdS)z,Check if pyconfig.h.in has been regenerated.z configure.acz pyconfig.h.inr roz not neededNr)rLrrr regenerated_pyconfig_h_insrqcCs|dkrtddSt}t|}dd|D}dd|D}dd|D}g}|t||t||t||stdn&tdt|d td t d dS) NZfalsezNot a pull request; skippingcSsg|]}|dr|qS)z.py)rO)r8fnrrr rQsztravis..cSsg|]}|dr|qS))z.cz.h)rO)r8rrrrr rQscSs$g|]}|dr|dr|qS)Doc)z.rstz.inc)r7rO)r8rrrrr rQs zNo whitespace issues foundzPlease fix the z file(s) with whitespace issuesz9(on UNIX you can run `make patchcheck` to make the fixes)r) rr3rJextendrSr]rgr4r rC)Z pull_requestr2rL python_filesc_files doc_filesrRrrr traviss" rxcCst}t|}dd|D}dd|D}dd|D}dd|D}t|t|t|t|t|t|t|t ||s|r|rdnd}t t d |dS) NcSsg|]}|dr|qS)z.py)rO)r8rrrrr rQszmain..cSsg|]}|dr|qS))z.cz.h)rO)r8rrrrr rQscSs$g|]}|dr|dr|qS)rs)z.rstz.inc)r7rO)r8rrrrr rQs cSsh|]}|dr|qS)rj)r7)r8rmrrr szmain..z and check for refleaks??zDid you run the test suite) r3rJrSr]rgrirkrnrprqr)r2rLrurvrwZ misc_filesendrrr mains$ r|__main__)Z descriptionz--traviszPerform pass/fail checks)help)FN)N)*__doc__rer rcZos.pathr+rZ sysconfigrPrZr,r.rFZget_config_varr!r rr$r&r3rJrNrSr]compiler_rgrirkrnstrrprqrxr|__name__argparseArgumentParserparser add_argument parse_argsrrrrr sX      (