aboutsummaryrefslogtreecommitdiff
path: root/circuitpython/tools/python-semver/README.rst
blob: ecc95e1af5ab55e6ee4809c01b4e3c64c98553d0 (plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
Semver |latest-version|
=======================

|build-status| |python-support| |downloads| |license|

A Python module for `semantic versioning`_. Simplifies comparing versions.


.. |latest-version| image:: https://img.shields.io/pypi/v/semver.svg
   :alt: Latest version on PyPI
   :target: https://pypi.python.org/pypi/semver
.. |build-status| image:: https://travis-ci.org/k-bx/python-semver.svg?branch=master
   :alt: Build status
   :target: https://travis-ci.org/k-bx/python-semver
.. |python-support| image:: https://img.shields.io/pypi/pyversions/semver.svg
   :target: https://pypi.python.org/pypi/semver
   :alt: Python versions
.. |downloads| image:: https://img.shields.io/pypi/dm/semver.svg
   :alt: Monthly downloads from PyPI
   :target: https://pypi.python.org/pypi/semver
.. |license| image:: https://img.shields.io/pypi/l/semver.svg
   :alt: Software license
   :target: https://github.com/k-bx/python-semver/blob/master/LICENSE.txt
.. _semantic versioning: http://semver.org/

Usage
-----

This module provides just couple of functions, main of which are:

.. code-block:: python

    >>> import semver
    >>> semver.compare("1.0.0", "2.0.0")
    -1
    >>> semver.compare("2.0.0", "1.0.0")
    1
    >>> semver.compare("2.0.0", "2.0.0")
    0
    >>> semver.match("2.0.0", ">=1.0.0")
    True
    >>> semver.match("1.0.0", ">1.0.0")
    False
    >>> semver.format_version(3, 4, 5, 'pre.2', 'build.4')
    '3.4.5-pre.2+build.4'
    >>> version_parts = semver.parse("3.4.5-pre.2+build.4")
    >>> version_parts == {
    ...     'major': 3, 'minor': 4, 'patch': 5,
    ...     'prerelease': 'pre.2', 'build': 'build.4'}
    True
    >>> version_info = semver.parse_version_info("3.4.5-pre.2+build.4")
    >>> version_info
    VersionInfo(major=3, minor=4, patch=5, prerelease='pre.2', build='build.4')
    >>> version_info.major
    3
    >>> version_info > (1, 0)
    True
    >>> version_info < (3, 5)
    True
    >>> semver.bump_major("3.4.5")
    '4.0.0'
    >>> semver.bump_minor("3.4.5")
    '3.5.0'
    >>> semver.bump_patch("3.4.5")
    '3.4.6'
    >>> semver.max_ver("1.0.0", "2.0.0")
    '2.0.0'
    >>> semver.min_ver("1.0.0", "2.0.0")
    '1.0.0'

Installation
------------

For Python 2:

.. code-block:: bash

    pip install semver

For Python 3:

.. code-block:: bash

    pip3 install semver

How to Contribute
-----------------

When you make changes to the code please run the tests before pushing your
code to your fork and opening a `pull request`_:

.. code-block:: bash

    python setup.py test

We use `py.test`_ and `tox`_ to run tests against all supported Python
versions.  All test dependencies are resolved automatically, apart from
virtualenv, which for the moment you still may have to install manually:

.. code-block:: bash

    pip install "virtualenv<14.0.0"  # <14.0.0 needed for Python 3.2 only

You can use the ``clean`` command to remove build and test files and folders:

.. code-block:: bash

    python setup.py clean


.. _pull request: https://github.com/k-bx/python-semver/pulls
.. _py.test: http://pytest.org/
.. _tox: http://tox.testrun.org/