README.rst 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. Semver |latest-version|
  2. =======================
  3. |build-status| |python-support| |downloads| |license|
  4. A Python module for `semantic versioning`_. Simplifies comparing versions.
  5. .. |latest-version| image:: https://img.shields.io/pypi/v/semver.svg
  6. :alt: Latest version on PyPI
  7. :target: https://pypi.python.org/pypi/semver
  8. .. |build-status| image:: https://travis-ci.org/k-bx/python-semver.svg?branch=master
  9. :alt: Build status
  10. :target: https://travis-ci.org/k-bx/python-semver
  11. .. |python-support| image:: https://img.shields.io/pypi/pyversions/semver.svg
  12. :target: https://pypi.python.org/pypi/semver
  13. :alt: Python versions
  14. .. |downloads| image:: https://img.shields.io/pypi/dm/semver.svg
  15. :alt: Monthly downloads from PyPI
  16. :target: https://pypi.python.org/pypi/semver
  17. .. |license| image:: https://img.shields.io/pypi/l/semver.svg
  18. :alt: Software license
  19. :target: https://github.com/k-bx/python-semver/blob/master/LICENSE.txt
  20. .. _semantic versioning: http://semver.org/
  21. Usage
  22. -----
  23. This module provides just couple of functions, main of which are:
  24. .. code-block:: python
  25. >>> import semver
  26. >>> semver.compare("1.0.0", "2.0.0")
  27. -1
  28. >>> semver.compare("2.0.0", "1.0.0")
  29. 1
  30. >>> semver.compare("2.0.0", "2.0.0")
  31. 0
  32. >>> semver.match("2.0.0", ">=1.0.0")
  33. True
  34. >>> semver.match("1.0.0", ">1.0.0")
  35. False
  36. >>> semver.format_version(3, 4, 5, 'pre.2', 'build.4')
  37. '3.4.5-pre.2+build.4'
  38. >>> version_parts = semver.parse("3.4.5-pre.2+build.4")
  39. >>> version_parts == {
  40. ... 'major': 3, 'minor': 4, 'patch': 5,
  41. ... 'prerelease': 'pre.2', 'build': 'build.4'}
  42. True
  43. >>> version_info = semver.parse_version_info("3.4.5-pre.2+build.4")
  44. >>> version_info
  45. VersionInfo(major=3, minor=4, patch=5, prerelease='pre.2', build='build.4')
  46. >>> version_info.major
  47. 3
  48. >>> version_info > (1, 0)
  49. True
  50. >>> version_info < (3, 5)
  51. True
  52. >>> semver.bump_major("3.4.5")
  53. '4.0.0'
  54. >>> semver.bump_minor("3.4.5")
  55. '3.5.0'
  56. >>> semver.bump_patch("3.4.5")
  57. '3.4.6'
  58. >>> semver.max_ver("1.0.0", "2.0.0")
  59. '2.0.0'
  60. >>> semver.min_ver("1.0.0", "2.0.0")
  61. '1.0.0'
  62. Installation
  63. ------------
  64. For Python 2:
  65. .. code-block:: bash
  66. pip install semver
  67. For Python 3:
  68. .. code-block:: bash
  69. pip3 install semver
  70. How to Contribute
  71. -----------------
  72. When you make changes to the code please run the tests before pushing your
  73. code to your fork and opening a `pull request`_:
  74. .. code-block:: bash
  75. python setup.py test
  76. We use `py.test`_ and `tox`_ to run tests against all supported Python
  77. versions. All test dependencies are resolved automatically, apart from
  78. virtualenv, which for the moment you still may have to install manually:
  79. .. code-block:: bash
  80. pip install "virtualenv<14.0.0" # <14.0.0 needed for Python 3.2 only
  81. You can use the ``clean`` command to remove build and test files and folders:
  82. .. code-block:: bash
  83. python setup.py clean
  84. .. _pull request: https://github.com/k-bx/python-semver/pulls
  85. .. _py.test: http://pytest.org/
  86. .. _tox: http://tox.testrun.org/