METADATA 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. Metadata-Version: 2.1
  2. Name: semantic-version
  3. Version: 2.8.5
  4. Summary: A library implementing the 'SemVer' scheme.
  5. Home-page: https://github.com/rbarrois/python-semanticversion
  6. Author: Raphaël Barrois
  7. Author-email: raphael.barrois+semver@polytechnique.org
  8. License: BSD
  9. Download-URL: http://pypi.python.org/pypi/semantic_version/
  10. Keywords: semantic version,versioning,version
  11. Platform: UNKNOWN
  12. Classifier: Development Status :: 5 - Production/Stable
  13. Classifier: Intended Audience :: Developers
  14. Classifier: License :: OSI Approved :: BSD License
  15. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  16. Classifier: Operating System :: OS Independent
  17. Classifier: Programming Language :: Python
  18. Classifier: Programming Language :: Python :: 2.7
  19. Classifier: Programming Language :: Python :: 3
  20. Classifier: Programming Language :: Python :: 3.4
  21. Classifier: Programming Language :: Python :: 3.5
  22. Classifier: Programming Language :: Python :: 3.6
  23. Classifier: Programming Language :: Python :: 3.7
  24. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  25. Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
  26. python-semanticversion
  27. ======================
  28. This small python library provides a few tools to handle `SemVer`_ in Python.
  29. It follows strictly the 2.0.0 version of the SemVer scheme.
  30. .. image:: https://secure.travis-ci.org/rbarrois/python-semanticversion.png?branch=master
  31. :target: http://travis-ci.org/rbarrois/python-semanticversion/
  32. .. image:: https://img.shields.io/pypi/v/semantic_version.svg
  33. :target: https://python-semanticversion.readthedocs.io/en/latest/changelog.html
  34. :alt: Latest Version
  35. .. image:: https://img.shields.io/pypi/pyversions/semantic_version.svg
  36. :target: https://pypi.python.org/pypi/semantic_version/
  37. :alt: Supported Python versions
  38. .. image:: https://img.shields.io/pypi/wheel/semantic_version.svg
  39. :target: https://pypi.python.org/pypi/semantic_version/
  40. :alt: Wheel status
  41. .. image:: https://img.shields.io/pypi/l/semantic_version.svg
  42. :target: https://pypi.python.org/pypi/semantic_version/
  43. :alt: License
  44. Links
  45. -----
  46. - Package on `PyPI`_: http://pypi.python.org/pypi/semantic_version/
  47. - Doc on `ReadTheDocs <http://readthedocs.org/>`_: https://python-semanticversion.readthedocs.io/
  48. - Source on `GitHub <http://github.com/>`_: http://github.com/rbarrois/python-semanticversion/
  49. - Build on `Travis CI <http://travis-ci.org/>`_: http://travis-ci.org/rbarrois/python-semanticversion/
  50. - Semantic Version specification: `SemVer`_
  51. Getting started
  52. ===============
  53. Install the package from `PyPI`_, using pip:
  54. .. code-block:: sh
  55. pip install semantic_version
  56. Or from GitHub:
  57. .. code-block:: sh
  58. $ git clone git://github.com/rbarrois/python-semanticversion.git
  59. Import it in your code:
  60. .. code-block:: python
  61. import semantic_version
  62. This module provides classes to handle semantic versions:
  63. - ``Version`` represents a version number (``0.1.1-alpha+build.2012-05-15``)
  64. - ``BaseSpec``-derived classes represent requirement specifications (``>=0.1.1,<0.3.0``):
  65. - ``SimpleSpec`` describes a natural description syntax
  66. - ``NpmSpec`` is used for NPM-style range descriptions.
  67. Versions
  68. --------
  69. Defining a ``Version`` is quite simple:
  70. .. code-block:: pycon
  71. >>> import semantic_version
  72. >>> v = semantic_version.Version('0.1.1')
  73. >>> v.major
  74. 0
  75. >>> v.minor
  76. 1
  77. >>> v.patch
  78. 1
  79. >>> v.prerelease
  80. []
  81. >>> v.build
  82. []
  83. >>> list(v)
  84. [0, 1, 1, [], []]
  85. If the provided version string is invalid, a ``ValueError`` will be raised:
  86. .. code-block:: pycon
  87. >>> semantic_version.Version('0.1')
  88. Traceback (most recent call last):
  89. File "<stdin>", line 1, in <module>
  90. File "/Users/rbarrois/dev/semantic_version/src/semantic_version/base.py", line 64, in __init__
  91. major, minor, patch, prerelease, build = self.parse(version_string, partial)
  92. File "/Users/rbarrois/dev/semantic_version/src/semantic_version/base.py", line 86, in parse
  93. raise ValueError('Invalid version string: %r' % version_string)
  94. ValueError: Invalid version string: '0.1'
  95. Obviously, ``Versions`` can be compared:
  96. .. code-block:: pycon
  97. >>> semantic_version.Version('0.1.1') < semantic_version.Version('0.1.2')
  98. True
  99. >>> semantic_version.Version('0.1.1') > semantic_version.Version('0.1.1-alpha')
  100. True
  101. >>> semantic_version.Version('0.1.1') <= semantic_version.Version('0.1.1-alpha')
  102. False
  103. You can also get a new version that represents a bump in one of the version levels:
  104. .. code-block:: pycon
  105. >>> v = semantic_version.Version('0.1.1+build')
  106. >>> new_v = v.next_major()
  107. >>> str(new_v)
  108. '1.0.0'
  109. >>> v = semantic_version.Version('1.1.1+build')
  110. >>> new_v = v.next_minor()
  111. >>> str(new_v)
  112. '1.2.0'
  113. >>> v = semantic_version.Version('1.1.1+build')
  114. >>> new_v = v.next_patch()
  115. >>> str(new_v)
  116. '1.1.2'
  117. It is also possible to check whether a given string is a proper semantic version string:
  118. .. code-block:: pycon
  119. >>> semantic_version.validate('0.1.3')
  120. True
  121. >>> semantic_version.validate('0a2')
  122. False
  123. Finally, one may create a ``Version`` with named components instead:
  124. .. code-block:: pycon
  125. >>> semantic_version.Version(major=0, minor=1, patch=2)
  126. Version('0.1.2')
  127. In that case, ``major``, ``minor`` and ``patch`` are mandatory, and must be integers.
  128. ``prerelease`` and ``patch``, if provided, must be tuples of strings:
  129. .. code-block:: pycon
  130. >>> semantic_version.Version(major=0, minor=1, patch=2, prerelease=('alpha', '2'))
  131. Version('0.1.2-alpha.2')
  132. Requirement specification
  133. -------------------------
  134. The ``SimpleSpec`` object describes a range of accepted versions:
  135. .. code-block:: pycon
  136. >>> s = SimpleSpec('>=0.1.1') # At least 0.1.1
  137. >>> s.match(Version('0.1.1'))
  138. True
  139. >>> s.match(Version('0.1.1-alpha1')) # pre-release doesn't satisfy version spec
  140. False
  141. >>> s.match(Version('0.1.0'))
  142. False
  143. Simpler test syntax is also available using the ``in`` keyword:
  144. .. code-block:: pycon
  145. >>> s = SimpleSpec('==0.1.1')
  146. >>> Version('0.1.1-alpha1') in s
  147. True
  148. >>> Version('0.1.2') in s
  149. False
  150. Combining specifications can be expressed as follows:
  151. .. code-block:: pycon
  152. >>> SimpleSpec('>=0.1.1,<0.3.0')
  153. Using a specification
  154. """""""""""""""""""""
  155. The ``SimpleSpec.filter`` method filters an iterable of ``Version``:
  156. .. code-block:: pycon
  157. >>> s = SimpleSpec('>=0.1.0,<0.4.0')
  158. >>> versions = (Version('0.%d.0' % i) for i in range(6))
  159. >>> for v in s.filter(versions):
  160. ... print v
  161. 0.1.0
  162. 0.2.0
  163. 0.3.0
  164. It is also possible to select the 'best' version from such iterables:
  165. .. code-block:: pycon
  166. >>> s = SimpleSpec('>=0.1.0,<0.4.0')
  167. >>> versions = (Version('0.%d.0' % i) for i in range(6))
  168. >>> s.select(versions)
  169. Version('0.3.0')
  170. Coercing an arbitrary version string
  171. """"""""""""""""""""""""""""""""""""
  172. Some user-supplied input might not match the semantic version scheme.
  173. For such cases, the ``Version.coerce`` method will try to convert any
  174. version-like string into a valid semver version:
  175. .. code-block:: pycon
  176. >>> Version.coerce('0')
  177. Version('0.0.0')
  178. >>> Version.coerce('0.1.2.3.4')
  179. Version('0.1.2+3.4')
  180. >>> Version.coerce('0.1.2a3')
  181. Version('0.1.2-a3')
  182. Including pre-release identifiers in specifications
  183. """""""""""""""""""""""""""""""""""""""""""""""""""
  184. When testing a ``Version`` against a ``SimpleSpec``, comparisons are
  185. adjusted for common user expectations; thus, a pre-release version (``1.0.0-alpha``)
  186. will not satisfy the ``==1.0.0`` ``SimpleSpec``.
  187. Pre-release identifiers will only be compared if included in the ``BaseSpec``
  188. definition or (for the empty pre-release number) if a single dash is appended
  189. (``1.0.0-``):
  190. .. code-block:: pycon
  191. >>> Version('0.1.0-alpha') in SimpleSpec('<0.1.0') # No pre-release identifier
  192. False
  193. >>> Version('0.1.0-alpha') in SimpleSpec('<0.1.0-') # Include pre-release in checks
  194. True
  195. Including build metadata in specifications
  196. """"""""""""""""""""""""""""""""""""""""""
  197. Build metadata has no ordering; thus, the only meaningful comparison including
  198. build metadata is equality.
  199. .. code-block:: pycon
  200. >>> Version('1.0.0+build2') in SimpleSpec('<=1.0.0') # Build metadata ignored
  201. True
  202. >>> Version('1.0.0+build1') in SimpleSpec('==1.0.0+build2') # Include build in checks
  203. False
  204. NPM-based ranges
  205. ----------------
  206. The ``NpmSpec`` class handles NPM-style ranges:
  207. .. code-block:: pycon
  208. >>> Version('1.2.3') in NpmSpec('1.2.2 - 1.4')
  209. True
  210. >>> Version('1.2.3') in NpmSpec('<1.x || >=1.2.3')
  211. True
  212. Refer to https://docs.npmjs.com/misc/semver.html for a detailed description of NPM
  213. range syntax.
  214. Using with Django
  215. =================
  216. The ``semantic_version.django_fields`` module provides django fields to
  217. store ``Version`` or ``BaseSpec`` objects.
  218. More documentation is available in the ``django`` section.
  219. Contributing
  220. ============
  221. In order to contribute to the source code:
  222. - Open an issue on `GitHub`_: https://github.com/rbarrois/python-semanticversion/issues
  223. - Fork the `repository <https://github.com/rbarrois/python-semanticversion>`_
  224. and submit a pull request on `GitHub`_
  225. - Or send me a patch (mailto:raphael.barrois+semver@polytechnique.org)
  226. When submitting patches or pull requests, you should respect the following rules:
  227. - Coding conventions are based on ``8``
  228. - The whole test suite must pass after adding the changes
  229. - The test coverage for a new feature must be 100%
  230. - New features and methods should be documented in the ``reference`` section
  231. and included in the ``changelog``
  232. - Include your name in the ``contributors`` section
  233. .. note:: All files should contain the following header::
  234. # -*- encoding: utf-8 -*-
  235. # Copyright (c) The python-semanticversion project
  236. Contents
  237. ========
  238. :maxdepth: 2
  239. reference
  240. django
  241. changelog
  242. credits
  243. .. _SemVer: http://semver.org/
  244. .. _PyPI: http://pypi.python.org/
  245. Indices and tables
  246. ==================
  247. * ``genindex``
  248. * ``modindex``
  249. * ``search``