11Using semver
22============
33
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.
96
107Each type can be converted into the other, if the minimum requirements
118are met.
@@ -32,23 +29,22 @@ creating a version:
3229* through an object oriented approach with the :class: `semver.VersionInfo `
3330 class. This is the preferred method when using semver.
3431
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 ` .
3936
4037
4138.. warning :: **Deprecation Warning**
4239
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.
4441 These functions will be removed in semver 3.
4542 For details, see the sections :ref: `sec_replace_deprecated_functions ` and
4643 :ref: `sec_display_deprecation_warnings `.
4744
4845
4946A :class: `semver.VersionInfo ` instance can be created in different ways:
5047
51-
5248* From a string::
5349
5450 >>> semver.VersionInfo.parse("3.4.5-pre.2+build.4")
@@ -173,6 +169,8 @@ If you do, you get an ``AttributeError``::
173169 ...
174170 AttributeError: attribute 'minor' is readonly
175171
172+ If you need to replace different parts of a version, refer to section :ref: `sec.replace.parts `.
173+
176174In case you need the different parts of a version stepwise, iterate over the :class: `semver.VersionInfo ` instance::
177175
178176 >>> 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
186184 [3, 4, 5, 'pre.2', 'build.4']
187185
188186
187+ .. _sec.replace.parts :
188+
189189Replacing Parts of a Version
190190----------------------------
191191
192192If 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 `:
200194
201195* From a :class: `semver.VersionInfo ` instance::
202196
203197 >>> version = semver.VersionInfo.parse("1.4.5-pre.1+build.6")
204198 >>> version.replace(major=2, minor=2)
205199 VersionInfo(major=2, minor=2, patch=5, prerelease='pre.1', build='build.6')
206200
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+
207206If you pass invalid keys you get an exception::
208207
209208 >>> semver.replace("1.2.3", invalidkey=2)
@@ -251,29 +250,31 @@ Increasing Parts of a Version
251250The ``semver `` module contains the following functions to raise parts of
252251a version:
253252
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
255254 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.
257256 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
259258 ``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
261260 ``build `` to ``None ``.
262- * :func: `semver.bump_build `: raises the build part.
261+ * :func: `semver.VersionInfo. bump_build `: raises the build part.
263262
264263.. code-block :: python
265264
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() )
267266 ' 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() )
269268 ' 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() )
271270 ' 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() )
273272 ' 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() )
275274 ' 3.4.5-pre.2+build.5'
276275
276+ Likewise the module level functions :func: `semver.bump_major `.
277+
277278
278279Comparing Versions
279280------------------
@@ -405,11 +406,12 @@ For example:
405406Replacing Deprecated Functions
406407------------------------------
407408
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.
411413
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
413415semver, the deprecated functions will be removed.
414416
415417The following list shows the deprecated functions and how you can replace
0 commit comments