Provide examples regular expression for pep 440. (#227)
* Provide examples regular expression for pep 440. Closes #226
This commit is contained in:
parent
938c61d1d7
commit
978a93cfc9
61
pep-0440.txt
61
pep-0440.txt
|
@ -94,6 +94,11 @@ this scheme but MUST also include the normalizations specified below.
|
||||||
Installation tools MAY warn the user when non-compliant or ambiguous versions
|
Installation tools MAY warn the user when non-compliant or ambiguous versions
|
||||||
are detected.
|
are detected.
|
||||||
|
|
||||||
|
See also `Appendix B : Parsing version strings with regular expressions` which
|
||||||
|
provides a regular expression to check strict conformance with the canonical
|
||||||
|
format, as well as a more permissive regular expression accepting inputs that
|
||||||
|
may require subsequent normalization.
|
||||||
|
|
||||||
Public version identifiers are separated into up to five segments:
|
Public version identifiers are separated into up to five segments:
|
||||||
|
|
||||||
* Epoch segment: ``N!``
|
* Epoch segment: ``N!``
|
||||||
|
@ -1575,6 +1580,62 @@ Metadata v2.0 guidelines versus setuptools::
|
||||||
Projects with No Compatible Versions: 498/47114 (1.06%)
|
Projects with No Compatible Versions: 498/47114 (1.06%)
|
||||||
Projects with Differing Latest Version: 688/47114 (1.46%)
|
Projects with Differing Latest Version: 688/47114 (1.46%)
|
||||||
|
|
||||||
|
Appendix B : Parsing version strings with regular expressions
|
||||||
|
=============================================================
|
||||||
|
|
||||||
|
As noted earlier in the `Public version identifiers` section, published
|
||||||
|
version identifiers SHOULD use the canonical format. This section provides
|
||||||
|
regular expressions that can be used to test whether a version is already
|
||||||
|
in that form, and if it's not, extract the various components for subsequent
|
||||||
|
normalization.
|
||||||
|
|
||||||
|
To test whether a version identifier is in the canonical format, you can use
|
||||||
|
the following function::
|
||||||
|
|
||||||
|
import re
|
||||||
|
def is_canonical(version):
|
||||||
|
return re.match(r'^([1-9]\d*!)?(0|[1-9]\d*)(\.(0|[1-9]\d*))*((a|b|rc)(0|[1-9]\d*))?(\.post(0|[1-9]\d*))?(\.dev(0|[1-9]\d*))?$', version) is not None
|
||||||
|
|
||||||
|
To extract the components of a version identifier, use the following regular
|
||||||
|
expression (as defined by the `packaging <https://github.com/pypa/packaging>`_
|
||||||
|
project)::
|
||||||
|
|
||||||
|
VERSION_PATTERN = r"""
|
||||||
|
v?
|
||||||
|
(?:
|
||||||
|
(?:(?P<epoch>[0-9]+)!)? # epoch
|
||||||
|
(?P<release>[0-9]+(?:\.[0-9]+)*) # release segment
|
||||||
|
(?P<pre> # pre-release
|
||||||
|
[-_\.]?
|
||||||
|
(?P<pre_l>(a|b|c|rc|alpha|beta|pre|preview))
|
||||||
|
[-_\.]?
|
||||||
|
(?P<pre_n>[0-9]+)?
|
||||||
|
)?
|
||||||
|
(?P<post> # post release
|
||||||
|
(?:-(?P<post_n1>[0-9]+))
|
||||||
|
|
|
||||||
|
(?:
|
||||||
|
[-_\.]?
|
||||||
|
(?P<post_l>post|rev|r)
|
||||||
|
[-_\.]?
|
||||||
|
(?P<post_n2>[0-9]+)?
|
||||||
|
)
|
||||||
|
)?
|
||||||
|
(?P<dev> # dev release
|
||||||
|
[-_\.]?
|
||||||
|
(?P<dev_l>dev)
|
||||||
|
[-_\.]?
|
||||||
|
(?P<dev_n>[0-9]+)?
|
||||||
|
)?
|
||||||
|
)
|
||||||
|
(?:\+(?P<local>[a-z0-9]+(?:[-_\.][a-z0-9]+)*))? # local version
|
||||||
|
"""
|
||||||
|
|
||||||
|
_regex = re.compile(
|
||||||
|
r"^\s*" + VERSION_PATTERN + r"\s*$",
|
||||||
|
re.VERBOSE | re.IGNORECASE,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
Copyright
|
Copyright
|
||||||
=========
|
=========
|
||||||
|
|
Loading…
Reference in New Issue