Mercurial > repos > guerler > hhblits
comparison lib/python3.8/site-packages/setuptools/_vendor/packaging/utils.py @ 0:9e54283cc701 draft
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
author | guerler |
---|---|
date | Mon, 27 Jul 2020 03:47:31 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9e54283cc701 |
---|---|
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 .version import InvalidVersion, Version | |
9 | |
10 | |
11 _canonicalize_regex = re.compile(r"[-_.]+") | |
12 | |
13 | |
14 def canonicalize_name(name): | |
15 # This is taken from PEP 503. | |
16 return _canonicalize_regex.sub("-", name).lower() | |
17 | |
18 | |
19 def canonicalize_version(version): | |
20 """ | |
21 This is very similar to Version.__str__, but has one subtle differences | |
22 with the way it handles the release segment. | |
23 """ | |
24 | |
25 try: | |
26 version = Version(version) | |
27 except InvalidVersion: | |
28 # Legacy versions cannot be normalized | |
29 return version | |
30 | |
31 parts = [] | |
32 | |
33 # Epoch | |
34 if version.epoch != 0: | |
35 parts.append("{0}!".format(version.epoch)) | |
36 | |
37 # Release segment | |
38 # NB: This strips trailing '.0's to normalize | |
39 parts.append(re.sub(r"(\.0)+$", "", ".".join(str(x) for x in version.release))) | |
40 | |
41 # Pre-release | |
42 if version.pre is not None: | |
43 parts.append("".join(str(x) for x in version.pre)) | |
44 | |
45 # Post-release | |
46 if version.post is not None: | |
47 parts.append(".post{0}".format(version.post)) | |
48 | |
49 # Development release | |
50 if version.dev is not None: | |
51 parts.append(".dev{0}".format(version.dev)) | |
52 | |
53 # Local version segment | |
54 if version.local is not None: | |
55 parts.append("+{0}".format(version.local)) | |
56 | |
57 return "".join(parts) |