summaryrefslogtreecommitdiff
path: root/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/packaging/utils.py
diff options
context:
space:
mode:
authorShubham Saini <shubham6405@gmail.com>2018-12-11 10:01:23 +0000
committerShubham Saini <shubham6405@gmail.com>2018-12-11 10:01:23 +0000
commit68df54d6629ec019142eb149dd037774f2d11e7c (patch)
tree345bc22d46b4e01a4ba8303b94278952a4ed2b9e /venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/packaging/utils.py
First commit
Diffstat (limited to 'venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/packaging/utils.py')
-rw-r--r--venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/packaging/utils.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/packaging/utils.py b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/packaging/utils.py
new file mode 100644
index 0000000..5151f9f
--- /dev/null
+++ b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_vendor/packaging/utils.py
@@ -0,0 +1,63 @@
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.
4from __future__ import absolute_import, division, print_function
5
6import re
7
8from .version import InvalidVersion, Version
9
10
11_canonicalize_regex = re.compile(r"[-_.]+")
12
13
14def canonicalize_name(name):
15 # This is taken from PEP 503.
16 return _canonicalize_regex.sub("-", name).lower()
17
18
19def 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(
40 re.sub(
41 r'(\.0)+$',
42 '',
43 ".".join(str(x) for x in version.release)
44 )
45 )
46
47 # Pre-release
48 if version.pre is not None:
49 parts.append("".join(str(x) for x in version.pre))
50
51 # Post-release
52 if version.post is not None:
53 parts.append(".post{0}".format(version.post))
54
55 # Development release
56 if version.dev is not None:
57 parts.append(".dev{0}".format(version.dev))
58
59 # Local version segment
60 if version.local is not None:
61 parts.append("+{0}".format(version.local))
62
63 return "".join(parts)