1
1
Using semver
2
2
============
3
3
4
- The ``semver `` module can store a version in different types:
5
-
6
- * as a string.
7
- * as :class: `semver.VersionInfo `, a dedicated class for a version type.
8
- * as a dictionary.
4
+ The ``semver `` module can store a version in the :class: `semver.VersionInfo ` class.
5
+ For historical reasons, a version can be also stored as a string or dictionary.
9
6
10
7
Each type can be converted into the other, if the minimum requirements
11
8
are met.
@@ -32,23 +29,22 @@ creating a version:
32
29
* through an object oriented approach with the :class: `semver.VersionInfo `
33
30
class. This is the preferred method when using semver.
34
31
35
- * through module level functions and builtin datatypes (usually strings
36
- and dicts ).
37
- These method are still available for compatibility reasons, but are
38
- marked as deprecated. Using one of these will emit a DeprecationWarning.
32
+ * through module level functions and builtin datatypes (usually string
33
+ and dict ).
34
+ This method is still available for compatibility reasons, but are
35
+ marked as deprecated. Using it will emit a :class: ` DeprecationWarning ` .
39
36
40
37
41
38
.. warning :: **Deprecation Warning**
42
39
43
- Module level functions are marked as *deprecated * in version 2.9.2 now.
40
+ Module level functions are marked as *deprecated * in version 2.10.0 now.
44
41
These functions will be removed in semver 3.
45
42
For details, see the sections :ref: `sec_replace_deprecated_functions ` and
46
43
:ref: `sec_display_deprecation_warnings `.
47
44
48
45
49
46
A :class: `semver.VersionInfo ` instance can be created in different ways:
50
47
51
-
52
48
* From a string::
53
49
54
50
>>> semver.VersionInfo.parse("3.4.5-pre.2+build.4")
@@ -173,6 +169,8 @@ If you do, you get an ``AttributeError``::
173
169
...
174
170
AttributeError: attribute 'minor' is readonly
175
171
172
+ If you need to replace different parts of a version, refer to section :ref: `sec.replace.parts `.
173
+
176
174
In case you need the different parts of a version stepwise, iterate over the :class: `semver.VersionInfo ` instance::
177
175
178
176
>>> for item in semver.VersionInfo.parse("3.4.5-pre.2+build.4"):
@@ -186,24 +184,25 @@ In case you need the different parts of a version stepwise, iterate over the :cl
186
184
[3, 4, 5, 'pre.2', 'build.4']
187
185
188
186
187
+ .. _sec.replace.parts :
188
+
189
189
Replacing Parts of a Version
190
190
----------------------------
191
191
192
192
If you want to replace different parts of a version, but leave other parts
193
- unmodified, use one of the functions :func: `semver.replace ` or
194
- :func: `semver.VersionInfo.replace `:
195
-
196
- * From a version string::
197
-
198
- >>> semver.replace("1.4.5-pre.1+build.6", major=2)
199
- '2.4.5-pre.1+build.6'
193
+ unmodified, use the function :func: `semver.VersionInfo.replace ` or :func: `semver.replace `:
200
194
201
195
* From a :class: `semver.VersionInfo ` instance::
202
196
203
197
>>> version = semver.VersionInfo.parse("1.4.5-pre.1+build.6")
204
198
>>> version.replace(major=2, minor=2)
205
199
VersionInfo(major=2, minor=2, patch=5, prerelease='pre.1', build='build.6')
206
200
201
+ * From a version string::
202
+
203
+ >>> semver.replace("1.4.5-pre.1+build.6", major=2)
204
+ '2.4.5-pre.1+build.6'
205
+
207
206
If you pass invalid keys you get an exception::
208
207
209
208
>>> semver.replace("1.2.3", invalidkey=2)
@@ -251,29 +250,31 @@ Increasing Parts of a Version
251
250
The ``semver `` module contains the following functions to raise parts of
252
251
a version:
253
252
254
- * :func: `semver.bump_major `: raises the major part and set all other parts to
253
+ * :func: `semver.VersionInfo. bump_major `: raises the major part and set all other parts to
255
254
zero. Set ``prerelease `` and ``build `` to ``None ``.
256
- * :func: `semver.bump_minor `: raises the minor part and sets ``patch `` to zero.
255
+ * :func: `semver.VersionInfo. bump_minor `: raises the minor part and sets ``patch `` to zero.
257
256
Set ``prerelease `` and ``build `` to ``None ``.
258
- * :func: `semver.bump_patch `: raises the patch part. Set ``prerelease `` and
257
+ * :func: `semver.VersionInfo. bump_patch `: raises the patch part. Set ``prerelease `` and
259
258
``build `` to ``None ``.
260
- * :func: `semver.bump_prerelease `: raises the prerelease part and set
259
+ * :func: `semver.VersionInfo. bump_prerelease `: raises the prerelease part and set
261
260
``build `` to ``None ``.
262
- * :func: `semver.bump_build `: raises the build part.
261
+ * :func: `semver.VersionInfo. bump_build `: raises the build part.
263
262
264
263
.. code-block :: python
265
264
266
- >> > semver.bump_major (" 3.4.5-pre.2+build.4" )
265
+ >> > str ( semver.VersionInfo.parse (" 3.4.5-pre.2+build.4" ).bump_major() )
267
266
' 4.0.0'
268
- >> > semver.bump_minor (" 3.4.5-pre.2+build.4" )
267
+ >> > str ( semver.VersionInfo.parse (" 3.4.5-pre.2+build.4" ).bump_minor() )
269
268
' 3.5.0'
270
- >> > semver.bump_patch (" 3.4.5-pre.2+build.4" )
269
+ >> > str ( semver.VersionInfo.parse (" 3.4.5-pre.2+build.4" ).bump_patch() )
271
270
' 3.4.6'
272
- >> > semver.bump_prerelease (" 3.4.5-pre.2+build.4" )
271
+ >> > str ( semver.VersionInfo.parse (" 3.4.5-pre.2+build.4" ).bump_prerelease() )
273
272
' 3.4.5-pre.3'
274
- >> > semver.bump_build (" 3.4.5-pre.2+build.4" )
273
+ >> > str ( semver.VersionInfo.parse (" 3.4.5-pre.2+build.4" ).bump_build() )
275
274
' 3.4.5-pre.2+build.5'
276
275
276
+ Likewise the module level functions :func: `semver.bump_major `.
277
+
277
278
278
279
Comparing Versions
279
280
------------------
@@ -405,11 +406,12 @@ For example:
405
406
Replacing Deprecated Functions
406
407
------------------------------
407
408
408
- The development team of semver has decided to deprecate certain functions on
409
- the module level. The preferred way of using semver is through the
410
- :class: `semver.VersionInfo ` class.
409
+ .. versionchanged :: 2.10.0
410
+ The development team of semver has decided to deprecate certain functions on
411
+ the module level. The preferred way of using semver is through the
412
+ :class: `semver.VersionInfo ` class.
411
413
412
- The deprecated functions can still be used in version 2.x.y . In version 3 of
414
+ The deprecated functions can still be used in version 2.10.0 and above . In version 3 of
413
415
semver, the deprecated functions will be removed.
414
416
415
417
The following list shows the deprecated functions and how you can replace
0 commit comments