U VY@sdZddlmZddlmZddlmZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlZddlmZddlmZdZdZddZddZddZddZ dOddZ!dPddZ"Gdd d ejZ#Gd!d"d"ejZ$Gd#d$d$ej%Z&Gd%d&d&e j'Z(d'd(Z)z&dd)l*m+Z+Gd*d+d+e+j,Z-d,Z.Wne/k rdZ.YnXd-d.Z0d/Z1d0Z2e2e2e1d1Z3e j45e j6dfd2d3Z7Gd4d5d5ejZ8Gd6d7d7ejZ9Gd8d9d9ej:Z;Gd:d;d;ejZd?d?ejZ>z dd@lm?Z?d,Z@e?jAZAe?jBZBWn"e/k rdZ@dZAdZBYnXdAdBZCdCdDZDdEdFZEdGdHZFdQdIdJZGdKdLZHdRdMdNZIejJjKZKdS)Sz4 Utilities with minimum-depends for use in setup.py )unicode_literals)install)logN)develop) easy_install)egg_info)install_scripts)sdist) extra_files)git)options) testr_command)version)zrequirements.txtztools/pip-requires)ztest-requirements.txtztools/test-requirescCsXtjd}|r(tdd|dDSttdttj dj ttj j t tt S)NPBR_REQUIREMENTS_FILEScss|]}|VqdSNstrip.0fr>/opt/alt/python38/lib/python3.8/site-packages/pbr/packaging.py 5sz)get_requirements_files..,z-pyr)osenvirongettuplesplitlistmapstrsys version_infojoinpathsplitextREQUIREMENTS_FILES)filesrrrget_requirements_files2s  r)cCs:g}||d}|r||||d|||<dS)z5Append a separated list to possibly existing value. N)rappendextendr$)configkey text_list new_value current_valuerrrappend_text_list?s    r3cCsdd|DS)NcSsg|]}tj|r|qSr)rr%existsrrrr Js z!_any_existing..r) file_listrrr _any_existingIsr7c CsBt|D]4}t|d }|dW5QRSQRXqgS)Nrr+)r7openreadr)requirements_filesrequirements_filefilrrrget_reqs_from_filesNs  &r>Fc CsF|dkrt}dd}g}t|D]}|r"|dr=\2)resubgroup)matchrrr egg_fragmentZsz(parse_requirements..egg_fragment#z-r ) strip_markersz\s*-e\s+z\s*-e\s+.*#egg=(.*)$ \s*https?:z\s*https?:.*#egg=(.*)$z\s*-f\s+zIndex Locationz#.*$r*;rz[pbr] Excluding %s: %s)r)r>r startswith partitionparse_requirements pkg_resources Requirementparse project_name ValueErrorr@rCrAfindr,rinfo) r;rHrD requirementslinereq_filerQreasonsemi_posrrrrMUsJ           rMcCsj|dkrt}g}t|D]J}td|r,qtd|rN|tdd|qtd|r||q|S)Nz (\s*#)|(\s*$)z \s*-[ef]\s+r*rI)r)r>r@rCr,rA)r;dependency_linksrVrrrparse_dependency_linkss     r[c@seZdZdZdZddZdS)InstallWithGitzExtracts ChangeLog and AUTHORS from git then installs. This is useful for e.g. readthedocs where the package is installed and then docs built. rcCst|jtj|Sr) _from_git distributionrrunselfrrrr_s zInstallWithGit.runN__name__ __module__ __qualname____doc__ command_namer_rrrrr\sr\c@seZdZdZdZddZdS) LocalInstallzRuns python setup.py install in a sensible manner. Force a non-egg installed in the manner of single-version-externally-managed, which allows us to install manpages and config files. rcCst|jtj|Sr)r]r^ du_installrr_r`rrrr_s zLocalInstall.runNrbrrrrrhsrhc@seZdZdZdZddZdS) TestrTestz&Make setup.py test do the right thing.testcCstj|dSr)r Testrr_r`rrrr_sz TestrTest.runNrbrrrrrjsrjc@s4eZdZdZeZgZdZddZddZddZ d S) LocalRPMVersionz:Output the rpm *compatible* version string of this package rpm_versioncCs.td|j}tt|dS)Nz[pbr] Extracting rpm version) rrTr^get_nameprintr VersionInfosemantic_version rpm_string)ranamerrrr_s  zLocalRPMVersion.runcCsdSrrr`rrrinitialize_optionssz"LocalRPMVersion.initialize_optionscCsdSrrr`rrrfinalize_optionssz LocalRPMVersion.finalize_optionsN) rcrdrerf description user_optionsrgr_rurvrrrrrmsrmcCstjSr)r have_testrrrrrrysry)commandsc@seZdZdZdZddZdS)NoseTestz)Fallback test runner if testr is a no-go.rkcCstj|dSr)rz nosetestsr_r`rrrr_sz NoseTest.runNrbrrrrr{sr{TcCstSr) _have_noserrrr have_nosesr~a5#PBR Generated from %(group)r import threading from %(module_name)s import %(import_target)s if __name__ == "__main__": import argparse import socket import wsgiref.simple_server as wss my_ip = socket.gethostbyname(socket.gethostname()) parser = argparse.ArgumentParser( description=%(import_target)s.__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('--port', '-p', type=int, default=8000, help='TCP port to listen on') args = parser.parse_args() server = wss.make_server('', args.port, %(invoke_target)s()) print("*" * 80) print("STARTING test server %(module_name)s.%(invoke_target)s") url = "http://%%s:%%d/" %% (my_ip, server.server_port) print("Available at %%s" %% url) print("DANGER! For testing only, do not use in production") print("*" * 80) server.serve_forever() else: application = None app_lock = threading.Lock() with app_lock: if application is None: application = %(invoke_target)s() z# PBR Generated from %(group)r import sys from %(module_name)s import %(import_target)s if __name__ == "__main__": sys.exit(%(invoke_target)s()) )console_scripts gui_scripts wsgi_scriptsc cstd||}tD]n\}}||D]V\}}|jrHt|jdkrPtd|t||j |jdd |jd}|||fVq,qdS)z$Override entrypoints console_script.r*rGzBScript targets must be of the form 'func' or 'Class.class_method'.r.)rB module_name import_target invoke_targetN) rget_script_headerENTRY_POINTS_MAPitems get_entry_mapattrslenrRdictrr$) dist executable is_wininstheaderrBtemplatertep script_textrrroverride_get_script_args6s rc@seZdZdZddZdS) LocalDeveloprcCs:tjdkrtj||S|js6t|D]}|j|q&dS)Nwin32)r"platformrinstall_wrapper_scriptsexclude_scriptsr write_script)rarargsrrrrLs   z$LocalDevelop.install_wrapper_scriptsN)rcrdrergrrrrrrHsrc@seZdZdZdZddZdS)LocalInstallScriptsz(Intercepts console scripts entry_points.rc Csddl}|d|jjr,|jjj|ng|_|jr    zLocalInstallScripts.runNrbrrrrrTsrc@s eZdZdZddZddZdS)LocalManifestMakerz?Add any files that are in git and some standard sensible files.cCsdD]}|j|qdS)N)zinclude AUTHORSzinclude ChangeLogzexclude .gitignorezexclude .gitreviewzglobal-exclude *.pyc)filelistprocess_template_line)ra template_linerrr_add_pbr_defaultssz$LocalManifestMaker._add_pbr_defaultscCs|jd}tj||j|j|j|j|jt t |dd}|spt }|r|j|ntj|jr||d}||jjd|jddS)Npbrskip_git_sdistSKIP_GIT_SDISTr*)prefix)r^get_option_dictr add_defaultsrr,rmanifestr-r get_extra_filesr get_boolean_optionr _find_git_filesrr%r4 read_manifestrrinclude_patternr)ra option_dict should_skiprcfilesrrrrrs"   zLocalManifestMaker.add_defaultsN)rcrdrerfrrrrrrr|s rc@seZdZdZdZddZdS) LocalEggInfozAOverride the egg_info command to regenerate SOURCES.txt sensibly.rcCstj|jd}tj|r2tjds2dtjkr^tdt |j }||_ | |j |_ n:tdt|_ t|ddD]}|j |qdS) apGenerate SOURCES.txt only if there isn't one already. If we are in an sdist command, then we always want to update SOURCES.txt. If we are not in an sdist command, then it doesn't matter one flip, and is actually destructive. However, if we're in a git context, it's always the right thing to do to recreate SOURCES.txt z SOURCES.txtz.gitr z[pbr] Processing SOURCES.txtz"[pbr] Reusing existing SOURCES.txtr8r+N)rr%r$rr4r"argvrrTrr^rr_rFileListr9r:rr,)ramanifest_filenamemmentryrrr find_sourcess        zLocalEggInfo.find_sourcesN)rcrdrerfrgrrrrrrsrcCs>|d}t}|r t|}tj||dtj|ddS)Nr)r changelog)r)rr _iter_log_oneline_iter_changelogwrite_git_changeloggenerate_authors)r^rrrrrr]s   r]c@seZdZdZdZddZdS) LocalSDistz5Builds the ChangeLog and Authors files from VC first.r cCst|jtj|dSr)r]r^r r_r`rrrr_s zLocalSDist.runNrbrrrrrsr)builddoccCstSr) _have_sphinxrrrr have_sphinxsrc si|r|d}nd}td|g|}tdfdd|dD}t}|D]}|dd|d DqPfd d }|d |d |d|d|d|d|d|d|D]}td|qd dS)aCalculate the sort of semver increment needed from git history. Every commit from HEAD to tag is consider for Sem-Ver metadata lines. See the pbr docs for their syntax. :return: a dict of kwargs for passing into SemanticVersion.increment. z..HEADHEADr sem-ver:cs*g|]"}|dr|dqS)rN)lowerrKr)rrV) header_lenrrr5sz)_get_increment_kwargs..r+cSsg|] }|qSrr)rsymbolrrrr5srcs||krd|<||dS)NT)discard)rsymbolsimpact)resultrr_handle_symbolsz-_get_increment_kwargs.._handle_symbolbugfixpatchfeatureminor deprecationz api-breakmajorz[pbr] Unknown Sem-Ver symbol %rN) r _run_git_commandrrsetupdaterrTpop) git_dirtag version_specrrzrrrrr)rrr_get_increment_kwargss&       rc Cstj|d}d}t|D]f\}\}}}t}t|D]0}z|tj|Wq4t k rbYq4Xq4|rt | |fSqd|fS)zReturn the commit data about the most recent tag. We use git-describe to find this out, but if there are no tags then we fall back to counting commits since the beginning of time. )rrr*) r r enumeraterraddrSemanticVersionfrom_pip_string Exceptionmaxrelease_string)rr row_countignoredtag_set version_tagsrrrr_get_revno_and_last_tags  rcCst|\}}tj|pd}|dkr*|}n|jft||}|dk r`||kr`tdt||d|dkrl|S||}|dk r||}||kr|S|S)aCalculate a version from a target version in git_dir. This is used for untagged versions only. A new version is calculated as necessary based on git metadata - distance to tags, current hash, contents of commit messages. :param git_dir: The git directory we're working from. :param target_version: If None, the last tagged version (or 0 if there are no tags yet) is incremented as needed to produce an appropriate target version following semver rules. Otherwise target_version is used as a constraint - if semver rules would result in a newer version then an exception is raised. :return: A semver version object. 0rNzRgit history requires a target version of %(new)s, but target version is %(target)s)newtarget) rrrr incrementrrRrto_dev)rtarget_versionrdistance last_semver new_versionnew_dev target_devrrr_get_version_from_git_targets*    rcCst}|rvz,tjddg|dddd}tj|}Wn*tk rb|rZtj|}nd}YnXt||}| Szt WSt k rYdSXdS) aCalculate a version string from git. If the revision is tagged, return that. Otherwise calculate a semantic version description of the tree. The number of revisions since the last tag is included in the dev counter in the version for untagged versions. :param pre_version: If supplied use this as the target version rather than inferring one from the last tag + commit messages. describez --exact-matchT)throw_on_error-rNr*) r _run_git_functionsrreplacerrrrrrunicode NameError) pre_versionrtaggedrrrrr_get_version_from_git>s0   rc Csddg}i}|D]Z}zt|d}Wnttfk r>YqYnXzt|}Wqtjk rhYqYqXq|dd|krdS|ddS)zGet the version from package metadata if present. This looks for PKG-INFO if present (for sdists), and if not looks for METADATA (for wheels) and failing that will return None. zPKG-INFOMETADATAr8NameNVersion)r9IOErrorOSErroremailmessage_from_file MessageErrorr) package_namepkg_metadata_filenames pkg_metadatafilenamepkg_metadata_filerrr_get_version_from_pkg_metadatads  rcCsdtjdtjdd}|r |St|}|r0|St|}tjddkrP|d}|rX|StddS)aGet the version of the project. First, try getting it from PKG-INFO or METADATA, if it exists. If it does, that means we're in a distribution tarball or that install has happened. Otherwise, if there is no PKG-INFO or METADATA file, pull the version from git. We do not support setup.py version sanity in git archive tarballs, nor do we support packagers directly sucking our git repo into theirs. We expect that a source tarball be made from our git repo - or that if someone wants to make a source tarball from a fork of our repo with additional tags in it that they understand and desire the results of doing that. :param pre_version: The version field from setup.cfg - if set then this version will be the next release. PBR_VERSIONOSLO_PACKAGE_VERSIONNrrGzutf-8zVersioning for this project requires either an sdist tarball, or access to an upstream git repository. Are you sure that git is installed?) rrrrrr"r#encoder)rrrrrr get_version|s  r#)NF)N)N)N)Lrf __future__rdistutils.commandrrirrrrr@r"rN setuptoolsZsetuptools.commandrrrrr rr r r pbr.pbr_jsonr rr'TEST_REQUIREMENTS_FILESr)r3r7r>rMr[r\rhrlrjCommandrmryZnoserzr|r{r} ImportErrorr~ _wsgi_text _script_textrr%normpathrrrrmanifest_makerrrr]rrr LocalBuildDocLocalBuildLatexrrrrrrr#pbr_jsonwrite_pbr_jsonrrrrs                 @     &   (!     %% & )