Package: simple-git-versioning
Opinionated version numbering CLIs, and libraryThis project aims at easing the burden of computing and managing a project's
version numbers by leveraginggittags and commit trailers.simple-git-versioningprovides two CLIs:semver2andpep440, one for each
supported versioning sheme of the same name:SemVer2andPEP440.Integration withsetuptoolsis supported.Snippets to expose your project's version number programatically are provided in
theLibrariessection.InstallationWithpip:pipinstallsimple-git-versioningUsageBy default,pep440andsemver2will compute a version number of the formX.Y.Z. Every project starts at0.0.0on their initial commit, and each
commit after that increments the numberZby one, unless they include aVersion-Bumptrailer (case-insensitive) with a value of:major:Xis incremented;minor:Yis incremented;patch:Zis incremented (same as the default).Each tool then provides the ability toswitchto a pre-release mode; or
post-release, and/or dev release, etc. in the case ofpep440.CLIsAll CLIs provide comprehensive help messages, available via the--helpoption.LibrariesLibraries that wish to expose their version number programatically may do so by
including the following snippet:PEP440fromimportlib.metadataimportPackageNotFoundError,versionfrompathlibimportPathfromversioning.pep440importNoVersion,Projecttry:__version__=version("<your python package's name>")exceptPackageNotFoundError:# package is not installedwithProject(path=Path(__file__).parent)asproject:try:__version__=str(project.version())exceptNoVersion:__version__=str(project.release(dev=0))SemVer2fromimportlib.metadataimportPackageNotFoundError,versionfrompathlibimportPathfromversioning.semver2importNoVersion,Projecttry:__version__=version("<your python package's name>")exceptPackageNotFoundError:# package is not installedwithProject(path=Path(__file__).parent)asproject:try:__version__=str(project.version())exceptNoVersion:__version__=str(project.release(pre=("dev",0))poetryIf you usepoetryas a build frontend and backend for your project, you can
configuresimple-git-versioningto derive a version automatically as follows:Installsimple-git-versioningalongsidepoetry:poetryselfadd"simple-git-versioning>=0.2"Enable thepoetryintegration in yourpyproject.toml, and pick the
versioning scheme you wish to apply:[tool.poetry]...[tool.simple-git-versioning]poetry="pep440"# or "semver2"Note thatpoetrymandates aversionalways be set inpyproject.toml, so
you will have to keep a placeholder there (e.g.version: "0.0.0").setuptoolsIf you usesetuptoolsas a build backend for your project, you can configuresimple-git-versioningto derive a version automatically as follows:In yourpyproject.toml:declareversionas a dynamic metadata field;addsimple-git-versioningto your project'sbuild-system.requires;enable thesetuptoolsintegration in yourpyproject.toml, and pick the
versioning scheme you wish to apply.[project]name=...dynamic=["version"][build-system]requires=["setuptools>=63","simple-git-versioning"]build-backend="setuptools.build_meta"[tool.simple-git-versioning]setuptools="pep440"# or "semver2"I recommend checking outsetuptools-scmandsetuptools-pipfile, two
othersetuptoolsextensions I find greatly helpful.