File: raise-parts-of-a-version.rst

package info (click to toggle)
python-semver 3.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 700 kB
  • sloc: python: 1,972; makefile: 28
file content (70 lines) | stat: -rw-r--r-- 2,421 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Raising Parts of a Version
==========================

.. note::

   Keep in mind, "raising" the pre-release only will make your
   complete version *lower* than before.

   For example, having version ``1.0.0`` and raising the pre-release
   will lead to ``1.0.0-rc.1``, but ``1.0.0-rc.1`` is smaller than ``1.0.0``.

   If you search for a way to take into account this behavior, look for the
   method :meth:`~semver.version.Version.next_version`
   in section :ref:`increase-parts-of-a-version`.


The ``semver`` module contains the following functions to raise parts of
a version:

* :meth:`~semver.version.Version.bump_major`: raises the major part and set all other parts to
  zero. Set ``prerelease`` and ``build`` to ``None``.
* :meth:`~semver.version.Version.bump_minor`: raises the minor part and sets ``patch`` to zero.
  Set ``prerelease`` and ``build`` to ``None``.
* :meth:`~semver.version.Version.bump_patch`: raises the patch part. Set ``prerelease`` and
  ``build`` to ``None``.
* :meth:`~semver.version.Version.bump_prerelease`: raises the prerelease part and set
  ``build`` to ``None``.
* :meth:`~semver.version.Version.bump_build`: raises the build part.


.. code-block:: python

    >>> str(Version.parse("3.4.5-pre.2+build.4").bump_major())
    '4.0.0'
    >>> str(Version.parse("3.4.5-pre.2+build.4").bump_minor())
    '3.5.0'
    >>> str(Version.parse("3.4.5-pre.2+build.4").bump_patch())
    '3.4.6'
    >>> str(Version.parse("3.4.5-pre.2+build.4").bump_prerelease())
    '3.4.5-pre.3'
    >>> str(Version.parse("3.4.5-pre.2+build.4").bump_build())
    '3.4.5-pre.2+build.5'

Likewise the module level functions :func:`semver.bump_major`.

For the methods :meth:`~semver.version.Version.bump_prerelease`
and :meth:`~semver.version.Version.bump_build` it's possible to pass an empty string or ``None``.
However, it gives different results:

.. code-block:: python

    >>> str(Version.parse("3.4.5").bump_prerelease(''))
    '3.4.5-1'
    >>> str(Version.parse("3.4.5").bump_prerelease(None))
    '3.4.5-rc.1'

An empty string removes any prefix whereas ``None`` is the same as calling
the method without any argument.

If you already have a prerelease, the argument for the method
is not taken into account:

.. code-block:: python

    >>> str(Version.parse("3.4.5-rc.1").bump_prerelease(None))
    '3.4.5-rc.2'
    >>> str(Version.parse("3.4.5-rc.1").bump_prerelease(''))
    '3.4.5-rc.2'