Skip to content

Commit b145931

Browse files
committed
Fix #235: Shift focus on semver.VersionInfo.*
* Module level functions like `semver.bump_version` are still available in the documentation, but they play a much less important role now. The preferred way is to use semver.Versioninfo instances to use. * Replace 2.9.2 -> 2.10.0 due to #237 * Fix docstring examples
1 parent c9b2a7f commit b145931

File tree

5 files changed

+104
-116
lines changed

5 files changed

+104
-116
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Change Log
66
All notable changes to this code base will be documented in this file,
77
in every released version.
88

9-
Version 2.9.x (WIP)
9+
Version 2.10.0 (WIP)
1010
===================
1111

1212
:Released: 2020-xx-yy
@@ -15,6 +15,10 @@ Version 2.9.x (WIP)
1515
Features
1616
--------
1717

18+
* :pr:`235`: Improved documentation and shift focus on ``semver.VersionInfo`` instead of advertising
19+
the old and deprecated module-level functions.
20+
21+
1822
Bug Fixes
1923
---------
2024

README.rst

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,23 @@ A Python module for `semantic versioning`_. Simplifies comparing versions.
99

1010
.. teaser-end
1111
12-
.. note::
12+
.. warning::
1313

14-
With version 2.9.0 we've moved the GitHub project. The project is now
15-
located under the organization ``python-semver``.
16-
The complete URL is::
14+
As anything comes to an end, this project will focus on Python 3.x only.
15+
New features and bugfixes will be integrated into the 3.x.y branch only.
1716

18-
https://github.com/python-semver/python-semver
17+
Major version 3 of semver will contain some incompatible changes:
1918

20-
If you still have an old repository, correct your upstream URL to the new URL::
19+
* removes support for Python 2.7 and 3.3
20+
* removes deprecated functions (see :ref:`sec_replace_deprecated_functions` for
21+
further information).
2122

22-
$ git remote set-url upstream git@github.com:python-semver/python-semver.git
23+
The last version of semver which supports Python 2.7 and 3.4 will be
24+
2.10.x. However, keep in mind, version 2.10.x is frozen: no new
25+
features nor backports will be integrated.
2326

27+
We recommend to upgrade your workflow to Python 3.x to gain support,
28+
bugfixes, and new features.
2429

2530
The module follows the ``MAJOR.MINOR.PATCH`` style:
2631

@@ -30,55 +35,36 @@ The module follows the ``MAJOR.MINOR.PATCH`` style:
3035

3136
Additional labels for pre-release and build metadata are supported.
3237

33-
34-
.. warning::
35-
36-
Major version 3.0.0 of semver will remove support for Python 2.7 and 3.4.
37-
38-
As anything comes to an end, this project will focus on Python 3.x.
39-
New features and bugfixes will be integrated only into the 3.x.y branch
40-
of semver.
41-
42-
The last version of semver which supports Python 2.7 and 3.4 will be
43-
2.9.x. However, keep in mind, version 2.9.x is frozen: no new
44-
features nor backports will be integrated.
45-
46-
We recommend to upgrade your workflow to Python 3.x to gain support,
47-
bugfixes, and new features.
48-
49-
5038
To import this library, use:
5139

5240
.. code-block:: python
5341
5442
>>> import semver
5543
5644
Working with the library is quite straightforward. To turn a version string into the
57-
different parts, use the `semver.parse` function:
45+
different parts, use the ``semver.VersionInfo.parse`` function:
5846

5947
.. code-block:: python
6048
61-
>>> ver = semver.parse('1.2.3-pre.2+build.4')
62-
>>> ver['major']
49+
>>> ver = semver.VersionInfo.parse('1.2.3-pre.2+build.4')
50+
>>> ver.major
6351
1
64-
>>> ver['minor']
52+
>>> ver.minor
6553
2
66-
>>> ver['patch']
54+
>>> ver.patch
6755
3
68-
>>> ver['prerelease']
56+
>>> ver.prerelease
6957
'pre.2'
70-
>>> ver['build']
58+
>>> ver.build
7159
'build.4'
7260
7361
To raise parts of a version, there are a couple of functions available for
74-
you. The `semver.parse_version_info` function converts a version string
75-
into a `semver.VersionInfo` class. The function
76-
`semver.VersionInfo.bump_major` leaves the original object untouched, but
77-
returns a new `semver.VersionInfo` instance with the raised major part:
62+
you. The function :func:`semver.VersionInfo.bump_major` leaves the original object untouched, but
63+
returns a new :class:`semver.VersionInfo` instance with the raised major part:
7864

7965
.. code-block:: python
8066
81-
>>> ver = semver.parse_version_info("3.4.5")
67+
>>> ver = semver.VersionInfo.parse("3.4.5")
8268
>>> ver.bump_major()
8369
VersionInfo(major=4, minor=0, patch=0, prerelease=None, build=None)
8470

docs/pysemver.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ Synopsis
1010

1111
.. code:: bash
1212
13-
pysemver compare <VERSION1> <VERSION2>
14-
pysemver bump {major,minor,patch,prerelease,build} <VERSION>
13+
pysemver <COMMAND> <OPTION>...
1514
1615
1716
Description
@@ -52,7 +51,7 @@ Bump a version.
5251
5352
.. option:: <PART>
5453

55-
The part to bump. Valid strings can be ``major``, ``minor``,
54+
The part to bump. Valid strings are ``major``, ``minor``,
5655
``patch``, ``prerelease``, or ``build``. The part has the
5756
following effects:
5857

docs/usage.rst

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
Using 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

107
Each type can be converted into the other, if the minimum requirements
118
are 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

4946
A :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+
176174
In 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+
189189
Replacing Parts of a Version
190190
----------------------------
191191

192192
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`:
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+
207206
If 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
251250
The ``semver`` module contains the following functions to raise parts of
252251
a 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

278279
Comparing Versions
279280
------------------
@@ -405,11 +406,12 @@ For example:
405406
Replacing 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
413415
semver, the deprecated functions will be removed.
414416

415417
The following list shows the deprecated functions and how you can replace

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy