Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/packaging/utils.py @ 0:26e78fe6e8c4 draft
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author | shellac |
---|---|
date | Sat, 02 May 2020 07:14:21 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:26e78fe6e8c4 |
---|---|
1 # This file is dual licensed under the terms of the Apache License, Version | |
2 # 2.0, and the BSD License. See the LICENSE file in the root of this repository | |
3 # for complete details. | |
4 from __future__ import absolute_import, division, print_function | |
5 | |
6 import re | |
7 | |
8 from ._typing import MYPY_CHECK_RUNNING | |
9 from .version import InvalidVersion, Version | |
10 | |
11 if MYPY_CHECK_RUNNING: # pragma: no cover | |
12 from typing import Union | |
13 | |
14 _canonicalize_regex = re.compile(r"[-_.]+") | |
15 | |
16 | |
17 def canonicalize_name(name): | |
18 # type: (str) -> str | |
19 # This is taken from PEP 503. | |
20 return _canonicalize_regex.sub("-", name).lower() | |
21 | |
22 | |
23 def canonicalize_version(_version): | |
24 # type: (str) -> Union[Version, str] | |
25 """ | |
26 This is very similar to Version.__str__, but has one subtle difference | |
27 with the way it handles the release segment. | |
28 """ | |
29 | |
30 try: | |
31 version = Version(_version) | |
32 except InvalidVersion: | |
33 # Legacy versions cannot be normalized | |
34 return _version | |
35 | |
36 parts = [] | |
37 | |
38 # Epoch | |
39 if version.epoch != 0: | |
40 parts.append("{0}!".format(version.epoch)) | |
41 | |
42 # Release segment | |
43 # NB: This strips trailing '.0's to normalize | |
44 parts.append(re.sub(r"(\.0)+$", "", ".".join(str(x) for x in version.release))) | |
45 | |
46 # Pre-release | |
47 if version.pre is not None: | |
48 parts.append("".join(str(x) for x in version.pre)) | |
49 | |
50 # Post-release | |
51 if version.post is not None: | |
52 parts.append(".post{0}".format(version.post)) | |
53 | |
54 # Development release | |
55 if version.dev is not None: | |
56 parts.append(".dev{0}".format(version.dev)) | |
57 | |
58 # Local version segment | |
59 if version.local is not None: | |
60 parts.append("+{0}".format(version.local)) | |
61 | |
62 return "".join(parts) |