Giter Club home page Giter Club logo

python-semver's Introduction

Warning

This is a development version. Do NOT use it in production before the final 3.0.0 is released.

Quickstart

A Python module for semantic versioning. Simplifies comparing versions.

Build status Python versions Monthly downloads from PyPI Software license Documentation Status Black Formatter

Note

This project works for Python 3.6 and greater only. If you are looking for a compatible version for Python 2, use the maintenance branch maint/v2.

The last version of semver which supports Python 2.7 to 3.5 will be 2.x.y However, keep in mind, the major 2 release is frozen: no new features nor backports will be integrated.

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

The module follows the MAJOR.MINOR.PATCH style:

  • MAJOR version when you make incompatible API changes,
  • MINOR version when you add functionality in a backwards compatible manner, and
  • PATCH version when you make backwards compatible bug fixes.

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

To import this library, use:

>>> import semver

Working with the library is quite straightforward. To turn a version string into the different parts, use the semver.VersionInfo.parse function:

>>> ver = semver.VersionInfo.parse('1.2.3-pre.2+build.4')
>>> ver.major
1
>>> ver.minor
2
>>> ver.patch
3
>>> ver.prerelease
'pre.2'
>>> ver.build
'build.4'

To raise parts of a version, there are a couple of functions available for you. The function semver.VersionInfo.bump_major leaves the original object untouched, but returns a new semver.VersionInfo instance with the raised major part:

>>> ver = semver.VersionInfo.parse("3.4.5")
>>> ver.bump_major()
VersionInfo(major=4, minor=0, patch=0, prerelease=None, build=None)

It is allowed to concatenate different "bump functions":

>>> ver.bump_major().bump_minor()
VersionInfo(major=4, minor=1, patch=0, prerelease=None, build=None)

To compare two versions, semver provides the semver.compare function. The return value indicates the relationship between the first and second version:

>>> 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

There are other functions to discover. Read on!

python-semver's People

Contributors

anvil avatar beatgammit avatar bittner avatar carlodri avatar fish2000 avatar flamefire avatar jakul avatar jieter avatar k-bx avatar kxepal avatar ofek avatar peblair avatar pipermerriam avatar ppkt avatar robi-wan avatar sbrudenell avatar scls19fr avatar talantr avatar tazle avatar tlaferriere avatar tomschr avatar txels avatar werwolfby avatar zgoda-mobica avatar zlalanne avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.