3 F\!J@sHdZddlZddlZddlZddZGdddeZGdddeZdS) z9 Utilities for consuming the version from pkg_resources. Nc Cs&y t|dStk r dSXdS)NTF)int ValueError)stringr`/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/pbr/pbr/version.py_is_ints rc@seZdZdZd0ddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ eddZeddZddZddZd d!Zd1d#d$Zd2d&d'Zd(d)Zd*d+Zd,d-Zd.d/ZdS)3SemanticVersionzvA pure semantic version independent of serialisation. See the pbr doc 'semver' for details on the semantics. rNcCs@||_||_||_||_||_|jr2|j r2d|_|p8d|_dS)a Create a SemanticVersion. :param major: Major component of the version. :param minor: Minor component of the version. Defaults to 0. :param patch: Patch level component. Defaults to 0. :param prerelease_type: What sort of prerelease version this is - one of a(alpha), b(beta) or rc(release candidate). :param prerelease: For prerelease versions, what number prerelease. Defaults to 0. :param dev_count: How many commits since the last release. rN)_major_minor_patch_prerelease_type _prerelease _dev_count)selfmajorminorpatchprerelease_type prerelease dev_countrrr__init__(szSemanticVersion.__init__cCst|tsdS|j|jkS)NF) isinstancer__dict__)rotherrrr__eq__?s zSemanticVersion.__eq__cCsttt|jjS)N)summaphashrvalues)rrrr__hash__DszSemanticVersion.__hash__cCsNddddd}|jr"|j r"d}nd}|j|j|j|||j|j|jpJtjfS)z.Return a key for sorting SemanticVersion's on.abrcz)r r!r"Nr)rr r r r r sysmaxsize)rZ rc_lookupZuq_devrrr _sort_keyGs   zSemanticVersion._sort_keycCs"t|tstd|j|jkS)z1Compare self and other, another Semantic Version.z,ordering to non-SemanticVersion is undefined)rr TypeErrorr')rrrrr__lt__^s zSemanticVersion.__lt__cCs||kp||kS)Nr)rrrrr__le__hszSemanticVersion.__le__cCs ||k S)Nr)rrrrr__ge__kszSemanticVersion.__ge__cCs ||k S)Nr)rrrrr__gt__nszSemanticVersion.__gt__cCs ||k S)Nr)rrrrr__ne__qszSemanticVersion.__ne__cCs d|jS)Nzpbr.version.SemanticVersion(%s))release_string)rrrr__repr__tszSemanticVersion.__repr__c Cs0y |j|Stk r*td|YnXdS)aCreate a SemanticVersion from a pip version string. This method will parse a version like 1.3.0 into a SemanticVersion. This method is responsible for accepting any version string that any older version of pbr ever created. Therefore: versions like 1.3.0a1 versions are handled, parsed into a canonical form and then output - resulting in 1.3.0.0a1. Pre pbr-semver dev versions like 0.10.1.3.g83bef74 will be parsed but output as 0.10.1.dev3.g83bef74. :raises ValueError: Never tagged versions sdisted by old pbr result in just the git hash, e.g. '1234567' which poses a substantial problem since they collide with the semver versions when all the digits are numerals. Such versions will result in a ValueError being thrown if any non-numeric digits are present. They are an exception to the general case of accepting anything we ever output, since they were never intended and would permanently mess up versions on PyPI if ever released - we're treating that as a critical bug that we ever made them and have stopped doing that. zInvalid version %rN)_from_pip_string_unsafe IndexErrorr)klassversion_stringrrrfrom_pip_stringws zSemanticVersion.from_pip_stringcCs|jd}|ddjs&td||jd}dd|D}t|}|dkr\td|n|dkr|t|kr||djr||}d jtjd d |}|j|||t|dg|||d<|d7}|j dgd||j ||dt |d}t |d}d} d} d} d} d d } t |drBt |d}nd}dg|dd<|dd}d}y|r~t |dr~d}Wntk rYnX|rt |d} n|r|dddks|dddkr| |d\} } |dd}xp|rb|d}|j dr t |dd} n2|j drBd} t |dd} ntd||f|dd}qWt |||| | | d}| r| rtd|f|jj| }|S)NZvVr$zInvalid version %r.cSsg|]}|jr|qSr)isdigit).0crrr sz;SemanticVersion._from_pip_string_unsafe..rcSs|jS)N)r6)xrrrsz9SemanticVersion._from_pip_string_unsafe..cSsTtjd}djtj||}tjd}djtj||}|t|d}|t|fS)Nr6r;isalpha)operator methodcallerjoin itertools dropwhile takewhilelenr)Zsegmentr6r>rrrrr _parse_types   z._parse_typeFT0r r!rdevpostzUnknown remainder %r in %r)rrrz0Cannot combine postN and devN - no mapping in %r)r r!rI)lstripr6rsplitrErArBrDappendextendrr startswithr incrementto_dev)r2r3Zinput_components componentsZ digit_lenZmixed_componentZlast_componentrrrZ post_countrrrFr remainderZremainder_starts_with_int componentresultrrrr0s               z'SemanticVersion._from_pip_string_unsafecCsd|j|j|jfS)z3Return the short version minus any alpha/beta tags.z%s.%s.%s)r r r )rrrr brief_stringszSemanticVersion.brief_stringcCs |jdS)zReturn the version number to use when building a debian package. This translates the PEP440/semver precedence rules into Debian version sorting operators. ~) _long_version)rrrr debian_stringszSemanticVersion.debian_stringcCs`|jr|jd}|j}|j}n6d}|jr:|jd}|j}nd}|jrP|jd}nd}t|||S)aReturn a decremented SemanticVersion. Decrementing versions doesn't make a lot of sense - this method only exists to support rendering of pre-release versions strings into serialisations (such as rpm) with no sort-before operator. The 9999 magic version component is from the spec on this - pbr-semver. :return: A new SemanticVersion object. r$i'r)r r r r)r new_patch new_minor new_majorrrr decrements    zSemanticVersion.decrementFcCs|jr|j}|jd}|j}nd}d}|jd}|rL|jd}d}d}d}n|j}|rr|jd}d}d}d}d}n|j}t|||||S)a~Return an incremented SemanticVersion. The default behaviour is to perform a patch level increment. When incrementing a prerelease version, the patch level is not changed - the prerelease serial is changed (e.g. beta 0 -> beta 1). Incrementing non-pre-release versions will not introduce pre-release versions - except when doing a patch incremental to a pre-release version the new version will only consist of major/minor/patch. :param minor: Increment the minor version. :param major: Increment the major version. :return: A new SemanticVersion object. r$Nr)r r r r r r)rrrZnew_prerelease_typeZnew_prereleaser\r]r^rrrrRs.    zSemanticVersion.incrementr;cCs|js |jr(|dkr(|jjg}d}n |jg}|jrR|jd|||j|jf|jr|jsj|j|n |jd|jd|j|jdjdd|DS)a1Construct a long string version of this semver. :param pre_separator: What separator to use between components that sort before rather than after. If None, use . and lower the version number of the component to preserve sorting. (Used for rpm support) Nr5z%s%s%s%srJr;css|]}t|VqdS)N)str)r7srrr Wsz0SemanticVersion._long_version..)r rr_rXrOr rA)rZ pre_separatorZ rc_markersegmentsrrrrZ>s         zSemanticVersion._long_versioncCs |jddS)zhReturn the full version of the package. This including suffixes indicating VCS status. r5rH)rZ)rrrrr.YszSemanticVersion.release_stringcCs |jdS)aSReturn the version number to use when building an RPM package. This translates the PEP440/semver precedence rules into RPM version sorting operators. Because RPM has no sort-before operator (such as the ~ operator in dpkg), we show all prerelease versions as being versions of the release before. N)rZ)rrrr rpm_string`szSemanticVersion.rpm_stringcCst|j|j|j|j|j|dS)z~Return a development version of this semver. :param dev_count: The number of commits since the last release. )r)rr r r r r )rrrrrrSjszSemanticVersion.to_devc Cs|j|j|jg}|jr`dddddddd dd dd i}|j||jt|jf|j|jpZ|jn6|jr|jd |j|jd n|jd|jdt|S)aPresent the version as a version_info tuple. For documentation on version_info tuples see the Python documentation for sys.version_info. Since semver and PEP-440 represent overlapping but not subsets of versions, we have to have some heuristic / mapping rules, and have extended the releaselevel field to have alphadev, betadev and candidatedev values. When they are present the dev count is used to provide the serial. - a/b/rc take precedence. - if there is no pre-release version the dev version is used. - serial is taken from the dev/a/b/c component. - final non-dev versions never get serials. r Falphar!betar" candidateTZalphadevZbetadevZ candidatedevrJr$finalr)r F)r!F)r"F)r T)r!T)r"T) r r r r rOboolrr tuple)rrcZtype_maprrr version_tupless"   zSemanticVersion.version_tuple)rrNNN)FF)r;)__name__ __module__ __qualname____doc__rrrr'r)r*r+r,r-r/ classmethodr4r0rXr[r_rRrZr.rdrSrkrrrrr"s.    V *   rc@sVeZdZddZddZddZddZd d Zd d Zd dZ e Z eZ dddZ dS) VersionInfocCs||_d|_d|_d|_dS)zObject that understands versioning for a package :param package: name of the python package, such as glance, or python-glanceclient N)packageversion_cached_version _semantic)rrrrrrrszVersionInfo.__init__cCs|jS)z1Make the VersionInfo object behave like a string.)r3)rrrr__str__szVersionInfo.__str__cCsd|j|jfS)zInclude the name.zpbr.version.VersionInfo(%s:%s))rrr3)rrrrr/szVersionInfo.__repr__c Csdddl}y"|jj|j}|j|}|j}Wn.|jk rXddlm}|j |j}YnXt j |S)aObtain a version from pkg_resources or setup-time logic if missing. This will try to get the version of the package from the pkg_resources record associated with the package, and if there is no such record falls back to the logic sdist would use. rN) packaging) pkg_resources Requirementparserr get_providerrsDistributionNotFoundZpbrrw get_versionrr4)rrx requirementZproviderZ result_stringrwrrr_get_version_from_pkg_resourcess    z+VersionInfo._get_version_from_pkg_resourcescCs |jjS)zhReturn the full version of the package. This including suffixes indicating VCS status. )semantic_versionr.)rrrrr.szVersionInfo.release_stringcCs|jdkr|j|_|jS)z3Return the SemanticVersion object for this version.N)rur)rrrrrs  zVersionInfo.semantic_versioncCs |jjS)z3Return the short version minus any alpha/beta tags.)rrX)rrrrr3szVersionInfo.version_stringr;cCs|jsd||jf|_|jS)zReturn a cached version string. This will return a cached version string if one is already cached, irrespective of prefix. If none is cached, one will be created with prefix and then cached and returned. z%s%s)rtr3)rprefixrrrcached_version_stringsz!VersionInfo.cached_version_stringN)r;) rlrmrnrrvr/rr.rr3Zcanonical_version_stringZversion_string_with_vcsrrrrrrqs rq)rorBr?r%robjectrrqrrrrsx