Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/soupsieve/__meta__.py @ 1:56ad4e20f292 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:32:28 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:d30785e31577 | 1:56ad4e20f292 |
---|---|
1 """Meta related things.""" | |
2 from collections import namedtuple | |
3 import re | |
4 | |
5 RE_VER = re.compile( | |
6 r'''(?x) | |
7 (?P<major>\d+)(?:\.(?P<minor>\d+))?(?:\.(?P<micro>\d+))? | |
8 (?:(?P<type>a|b|rc)(?P<pre>\d+))? | |
9 (?:\.post(?P<post>\d+))? | |
10 (?:\.dev(?P<dev>\d+))? | |
11 ''' | |
12 ) | |
13 | |
14 REL_MAP = { | |
15 ".dev": "", | |
16 ".dev-alpha": "a", | |
17 ".dev-beta": "b", | |
18 ".dev-candidate": "rc", | |
19 "alpha": "a", | |
20 "beta": "b", | |
21 "candidate": "rc", | |
22 "final": "" | |
23 } | |
24 | |
25 DEV_STATUS = { | |
26 ".dev": "2 - Pre-Alpha", | |
27 ".dev-alpha": "2 - Pre-Alpha", | |
28 ".dev-beta": "2 - Pre-Alpha", | |
29 ".dev-candidate": "2 - Pre-Alpha", | |
30 "alpha": "3 - Alpha", | |
31 "beta": "4 - Beta", | |
32 "candidate": "4 - Beta", | |
33 "final": "5 - Production/Stable" | |
34 } | |
35 | |
36 PRE_REL_MAP = {"a": 'alpha', "b": 'beta', "rc": 'candidate'} | |
37 | |
38 | |
39 class Version(namedtuple("Version", ["major", "minor", "micro", "release", "pre", "post", "dev"])): | |
40 """ | |
41 Get the version (PEP 440). | |
42 | |
43 A biased approach to the PEP 440 semantic version. | |
44 | |
45 Provides a tuple structure which is sorted for comparisons `v1 > v2` etc. | |
46 (major, minor, micro, release type, pre-release build, post-release build, development release build) | |
47 Release types are named in is such a way they are comparable with ease. | |
48 Accessors to check if a development, pre-release, or post-release build. Also provides accessor to get | |
49 development status for setup files. | |
50 | |
51 How it works (currently): | |
52 | |
53 - You must specify a release type as either `final`, `alpha`, `beta`, or `candidate`. | |
54 - To define a development release, you can use either `.dev`, `.dev-alpha`, `.dev-beta`, or `.dev-candidate`. | |
55 The dot is used to ensure all development specifiers are sorted before `alpha`. | |
56 You can specify a `dev` number for development builds, but do not have to as implicit development releases | |
57 are allowed. | |
58 - You must specify a `pre` value greater than zero if using a prerelease as this project (not PEP 440) does not | |
59 allow implicit prereleases. | |
60 - You can optionally set `post` to a value greater than zero to make the build a post release. While post releases | |
61 are technically allowed in prereleases, it is strongly discouraged, so we are rejecting them. It should be | |
62 noted that we do not allow `post0` even though PEP 440 does not restrict this. This project specifically | |
63 does not allow implicit post releases. | |
64 - It should be noted that we do not support epochs `1!` or local versions `+some-custom.version-1`. | |
65 | |
66 Acceptable version releases: | |
67 | |
68 ``` | |
69 Version(1, 0, 0, "final") 1.0 | |
70 Version(1, 2, 0, "final") 1.2 | |
71 Version(1, 2, 3, "final") 1.2.3 | |
72 Version(1, 2, 0, ".dev-alpha", pre=4) 1.2a4 | |
73 Version(1, 2, 0, ".dev-beta", pre=4) 1.2b4 | |
74 Version(1, 2, 0, ".dev-candidate", pre=4) 1.2rc4 | |
75 Version(1, 2, 0, "final", post=1) 1.2.post1 | |
76 Version(1, 2, 3, ".dev") 1.2.3.dev0 | |
77 Version(1, 2, 3, ".dev", dev=1) 1.2.3.dev1 | |
78 ``` | |
79 | |
80 """ | |
81 | |
82 def __new__(cls, major, minor, micro, release="final", pre=0, post=0, dev=0): | |
83 """Validate version info.""" | |
84 | |
85 # Ensure all parts are positive integers. | |
86 for value in (major, minor, micro, pre, post): | |
87 if not (isinstance(value, int) and value >= 0): | |
88 raise ValueError("All version parts except 'release' should be integers.") | |
89 | |
90 if release not in REL_MAP: | |
91 raise ValueError("'{}' is not a valid release type.".format(release)) | |
92 | |
93 # Ensure valid pre-release (we do not allow implicit pre-releases). | |
94 if ".dev-candidate" < release < "final": | |
95 if pre == 0: | |
96 raise ValueError("Implicit pre-releases not allowed.") | |
97 elif dev: | |
98 raise ValueError("Version is not a development release.") | |
99 elif post: | |
100 raise ValueError("Post-releases are not allowed with pre-releases.") | |
101 | |
102 # Ensure valid development or development/pre release | |
103 elif release < "alpha": | |
104 if release > ".dev" and pre == 0: | |
105 raise ValueError("Implicit pre-release not allowed.") | |
106 elif post: | |
107 raise ValueError("Post-releases are not allowed with pre-releases.") | |
108 | |
109 # Ensure a valid normal release | |
110 else: | |
111 if pre: | |
112 raise ValueError("Version is not a pre-release.") | |
113 elif dev: | |
114 raise ValueError("Version is not a development release.") | |
115 | |
116 return super(Version, cls).__new__(cls, major, minor, micro, release, pre, post, dev) | |
117 | |
118 def _is_pre(self): | |
119 """Is prerelease.""" | |
120 | |
121 return self.pre > 0 | |
122 | |
123 def _is_dev(self): | |
124 """Is development.""" | |
125 | |
126 return bool(self.release < "alpha") | |
127 | |
128 def _is_post(self): | |
129 """Is post.""" | |
130 | |
131 return self.post > 0 | |
132 | |
133 def _get_dev_status(self): # pragma: no cover | |
134 """Get development status string.""" | |
135 | |
136 return DEV_STATUS[self.release] | |
137 | |
138 def _get_canonical(self): | |
139 """Get the canonical output string.""" | |
140 | |
141 # Assemble major, minor, micro version and append `pre`, `post`, or `dev` if needed.. | |
142 if self.micro == 0: | |
143 ver = "{}.{}".format(self.major, self.minor) | |
144 else: | |
145 ver = "{}.{}.{}".format(self.major, self.minor, self.micro) | |
146 if self._is_pre(): | |
147 ver += '{}{}'.format(REL_MAP[self.release], self.pre) | |
148 if self._is_post(): | |
149 ver += ".post{}".format(self.post) | |
150 if self._is_dev(): | |
151 ver += ".dev{}".format(self.dev) | |
152 | |
153 return ver | |
154 | |
155 | |
156 def parse_version(ver, pre=False): | |
157 """Parse version into a comparable Version tuple.""" | |
158 | |
159 m = RE_VER.match(ver) | |
160 | |
161 # Handle major, minor, micro | |
162 major = int(m.group('major')) | |
163 minor = int(m.group('minor')) if m.group('minor') else 0 | |
164 micro = int(m.group('micro')) if m.group('micro') else 0 | |
165 | |
166 # Handle pre releases | |
167 if m.group('type'): | |
168 release = PRE_REL_MAP[m.group('type')] | |
169 pre = int(m.group('pre')) | |
170 else: | |
171 release = "final" | |
172 pre = 0 | |
173 | |
174 # Handle development releases | |
175 dev = m.group('dev') if m.group('dev') else 0 | |
176 if m.group('dev'): | |
177 dev = int(m.group('dev')) | |
178 release = '.dev-' + release if pre else '.dev' | |
179 else: | |
180 dev = 0 | |
181 | |
182 # Handle post | |
183 post = int(m.group('post')) if m.group('post') else 0 | |
184 | |
185 return Version(major, minor, micro, release, pre, post, dev) | |
186 | |
187 | |
188 __version_info__ = Version(2, 0, 1, "final") | |
189 __version__ = __version_info__._get_canonical() |