Package: bump4version
bump2versionNOTEThis is a maintained fork of the excellentbumpversion project.OverviewVersion-bump your software with a single command!A small command line tool to simplify releasing software by updating all
version strings in your source code by the correct increment. Also creates
commits and tags:version formats are highly configurableworks without any VCS, but happily reads tag information from and writes
commits and tags to Git and Mercurial if availablejust handles text files, so it's not specific to any programming languagesupports Python 3 and PyPy3If you want to use Python 2, usepip>=9and you'll get the last supported version,
or pinbump2version<1.AlternativesIf bump2version does not fully suit your needs, you could take a look
at other tools doing similar or related tasks:ALTERNATIVES.md.InstallationYou can download and install the latest version of this software from the Python package index (PyPI) as follows:pip install --upgrade bump2versionNOTE:pip install bumpversionnow installs the latest bump2version!ChangelogPlease find the changelog here:CHANGELOG.mdUsageNOTE: Throughout this document you can usebumpversionorbump2versioninterchangeably.There are two modes of operation: On the command line for single-file operation
and using a configuration file (.bumpversion.cfg) for more complex multi-file operations.bump2version [options] part [file]partrequiredThe part of the version to increase, e.g.minor.Valid values include those given in the--serialize/--parseoption.Example bumping 0.5.1 to 0.6.0:bump2version --current-version 0.5.1 minor src/VERSIONfile[optional]default: noneThe file that will be modified.This file is added to the list of files specified in[bumpversion:file:…]sections from the configuration file. If you want to rewrite only files
specified on the command line, use--no-configured-files.Example bumping 1.1.9 to 2.0.0:bump2version --current-version 1.1.9 major setup.pyConfiguration fileAll options can optionally be specified in a config file called.bumpversion.cfgso that once you know howbump2versionneeds to be
configured for one particular software package, you can run it without
specifying options later. You should add that file to VCS so others can also
bump versions.Options on the command line take precedence over those from the config file,
which take precedence over those derived from the environment and then from the
defaults.Example.bumpversion.cfg:[bumpversion]current_version=0.2.9commit=Truetag=True[bumpversion:file:setup.py]If no.bumpversion.cfgexists,bump2versionwill also look intosetup.cfgfor configuration.Configuration file -- Global configurationGeneral configuration is grouped in a[bumpversion]section.current_versionrequireddefault: noneThe current version of the software package before bumping.Also available as--current-version(e.g.bump2version --current-version 0.5.1 patch setup.py)new_version[optional]default: noneThe version of the software package after the increment. If not given will be
automatically determined.Also available as--new-version(e.g.to go from 0.5.1 directly to 0.6.1:bump2version --current-version 0.5.1 --new-version 0.6.1 patch setup.py).tag = (True | False)[optional]default: False (Don't create a tag)Whether to create a tag, that is the new version, prefixed with the character
"v". If you are using git, don't forget togit-pushwith the--tagsflag.Also available on the command line as(--tag | --no-tag).sign_tags = (True | False)[optional]default: False (Don't sign tags)Whether to sign tags.Also available on the command line as(--sign-tags | --no-sign-tags).tag_name =[optional]default:v{new_version}The name of the tag that will be created. Only valid when using--tag/tag = True.This is templated using thePython Format String Syntax.
Available in the template context arecurrent_versionandnew_versionas well ascurrent_[part]andnew_[part](e.g. 'current_major'
or 'new_patch').
In addition, all environment variables are exposed, prefixed with$.
You can also use the variablesnoworutcnowto get a current timestamp. Both accept
datetime formatting (when used like as in{now:%d.%m.%Y}).Also available as command-line flagtag-name.  Example usage:bump2version --tag-name 'release-{new_version}' patchtag_message =[optional]default:Bump version: {current_version} → {new_version}The tag message to use when creating a tag. Only valid when using--tag/tag = True.This is templated using thePython Format String Syntax.
Available in the template context arecurrent_versionandnew_versionas well ascurrent_[part]andnew_[part](e.g. 'current_major'
or 'new_patch').
In addition, all environment variables are exposed, prefixed with$.
You can also use the variablesnoworutcnowto get a current timestamp. Both accept
datetime formatting (when used like as in{now:%d.%m.%Y}).Also available as command-line flag--tag-message.  Example usage:bump2version --tag-message 'Release {new_version}' patchbump2versioncreates anannotatedtag in Git by default. To disable this and create alightweighttag, you must explicitly set an emptytag_message:either in the configuration file:tag_message =or in the command-line:bump2version --tag-message ''You can read more about Git tagginghere.commit = (True | False)[optional]default:False (Don't create a commit)Whether to create a commit using git or Mercurial.Also available as(--commit | --no-commit).In many projects it is common to have a pre-commit hook that runs prior to a
commit and in case of failure aborts the commit. For some use cases it might
be desired that when bumping a version and havingcommit = True, the
pre-commit hook should perform slightly different actions than in regular
commits. For example run an extended set of checks only for actual releases of
the software. To allow the pre-commit hooks to distinguish a bumpversion
commit, theBUMPVERSION_CURRENT_VERSIONandBUMPVERSION_NEW_VERSIONenvironment variables are set when executing the commit command.message =[optional]default:Bump version: {current_version} → {new_version}The commit message to use when creating a commit. Only valid when using--commit/commit = True.This is templated using thePython Format String Syntax.
Available in the template context arecurrent_versionandnew_versionas well ascurrent_[part]andnew_[part](e.g. 'current_major'
or 'new_patch').
In addition, all environment variables are exposed, prefixed with$.
You can also use the variablesnoworutcnowto get a current timestamp. Both accept
datetime formatting (when used like as in{now:%d.%m.%Y}).Also available as command-line flag--message.  Example usage:bump2version --message '[{now:%Y-%m-%d}] Jenkins Build {$BUILD_NUMBER}: {new_version}' patch)commit_args =[optional]default:emptyExtra arguments to pass to commit command. Only valid when using--commit/commit = True.This is for example useful to add-sto generateSigned-off-by:line in
the commit message.Multiple arguments can be specified on separate lines.Also available as command-line flag--commit-args, in which case only one
argument can be specified.Configuration file -- Part specific configurationA version string consists of one or more parts, e.g. the version1.0.2has three parts, separated by a dot (.) character. In the default
configuration these parts are namedmajor,minor,patch, however you can
customize that using theparse/serializeoption.By default all parts are considered numeric, that is their initial value is0and they are increased as integers. Also, the value0is considered to be
optional if it's not needed for serialization, i.e. the version1.4.0is
equal to1.4if{major}.{minor}is given as aserializevalue.For advanced versioning schemes, non-numeric parts may be desirable (e.g. to
identifyalpha or beta versionsto indicate the stage of development, the flavor of the software package or
a release name). To do so, you can use a[bumpversion:part:…]section
containing the part's name (e.g. a part namedrelease_nameis configured in
a section called[bumpversion:part:release_name].The following options are valid inside a part configuration:values =default: numeric (i.e.0,1,2, …)Explicit list of all values that will be iterated when bumping that specific
part.Example:[bumpversion:part:release_name]values=witty-warthogridiculous-ratmarvelous-mantisoptional_value =default: The first entry invalues =.If the value of the part matches this value it is considered optional, i.e.
its representation in a--serializepossibility is not required.Example:[bumpversion]current_version=1.alphaparse=(?P<num>\d+)(\.(?P<release>.*))?serialize={num}.{release}{num}[bumpversion:part:release]optional_value=gammavalues=alphabetagammaHere,bump2version releasewould bump1.alphato1.beta. Executingbump2version releaseagain would bump1.betato1, becausereleasebeinggammais configured optional.You should consider the version of1to technically be1.gammawith the.gammapart not being serialized since it is optional.
The{num}entry in theserializelist allows the release part to be
hidden. If you only had{num}.{release}, an optional release will always
be serialized.Attempting to bump the release when it is the value ofgammawill cause aValueErroras it will think you are trying to
exceed thevalueslist of the release part.first_value =default: The first entry invalues =.When the part is reset, the value will be set to the value specified here.Example:[bumpversion]current_version=1.alpha1parse=(?P<num>\d+)(\.(?P<release>.*)(?P<build>\d+))?serialize={num}.{release}{build}[bumpversion:part:release]values=alphabetagamma[bumpversion:part:build]first_value=1Here,bump2version releasewould bump1.alpha1to1.beta1.Without thefirst_value = 1of the build part configured,bump2version releasewould bump1.alpha1to1.beta0, starting
the build at0.independent =default:FalseWhen this value is set toTrue, the part is not reset when other parts are incremented. Its incrementation is
independent of the other parts. It is in particular useful when you have a build number in your version that is
incremented independently of the actual version.Example:[bumpversion]current_version:2.1.6-5123parse=(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)\-(?P<build>\d+)serialize={major}.{minor}.{patch}-{build}[bumpversion:file:VERSION.txt][bumpversion:part:build]independent=TrueHere,bump2version buildwould bump2.1.6-5123to2.1.6-5124. Executingbump2version majorwould bump2.1.6-5124to3.0.0-5124without resetting the build number.Configuration file -- File specific configurationThis configuration is in the section:[bumpversion:file:…]or[bumpversion:glob:…]Both,file:andglob:are configured the same. Their difference is that
file will match file names directly likerequirements.txt. While glob also
matches multiple files via wildcards like**/pom.xml.Note: The configuration file format requires each section header to be
unique. If you want to process a certain file multiple times,
you may append a description between parens to thefilekeyword:[bumpversion:file (special one):…].parse =default:(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)Regular expression (usingPython regular expression syntax) on
how to find and parse the version string.Is required to parse all strings produced byserialize =. Named matching
groups ("(?P<name>...)") provide values to as thepartargument.Also available as--parseserialize =default:{major}.{minor}.{patch}Template specifying how to serialize the version parts back to a version
string.This is templated using thePython Format String Syntax.
Available in the template context are parsed values of the named groups
specified inparse =as well as all environment variables (prefixed with$).Can be specified multiple times, bumpversion will try the serialization
formats beginning with the first and choose the last one where all values can
be represented like this:serialize={major}.{minor}{major}Given the example above, the new version1.9will be serialized as1.9, but the version2.0will be serialized as2.Also available as--serialize. Multiple values on the command line are
given like--serialize {major}.{minor} --serialize {major}search =default:{current_version}Template string how to search for the string to be replaced in the file.
Useful if the remotest possibility exists that the current version number
might be present multiple times in the file and you mean to only bump one of the
occurrences. Can be multiple lines, templated usingPython Format String Syntaxreplace =default:{new_version}Template to create the string that will replace the current version number in
the file.Given thisrequirements.txt:Django>=1.5.6,<1.6
MyProject==1.5.6using this.bumpversion.cfgwill ensure only the line containingMyProjectwill be changed:[bumpversion]current_version=1.5.6[bumpversion:file:requirements.txt]search=MyProject=={current_version}replace=MyProject=={new_version}Can be multiple lines, templated usingPython Format String Syntax.NOTE: (Updated in v1.0.1) It is important to point out that if a
custom search pattern is configured, thenbump2versionwill only perform
a change if it finds an exact match and will not fallback to the default
pattern. This is to prevent accidentally changing strings that match the
default pattern when there is a typo in the custom search pattern.For example, if the string to be replaced includes literal quotes,
the search and replace patterns must include them too to match. Given the
fileversion.sh:MY_VERSION="1.2.3"Then the following search and replace patterns (including quotes) would be
required:[bumpversion:file:version.sh]search=MY_VERSION="{current_version}"replace=MY_VERSION="{new_version}"Command-line OptionsMost of the configuration values above can also be given as an option on the command-line.
Additionally, the following options are available:--dry-run, -nDon't touch any files, just pretend. Best used with--verbose.--allow-dirtyNormally, bumpversion will abort if the working directory is dirty to protect
yourself from releasing unversioned files and/or overwriting unsaved changes.
Use this option to override this check.--no-configured-filesWill not update/check files specified in the .bumpversion.cfg.
Similar to dry-run, but will also avoid checking the files.
Also useful when you want to update just one file with e.g.,bump2version --no-configured-files major my-file.txt--verbosePrint useful information to stderr--listList machine readable information to stdout for consumption by other
programs.Example output:current_version=0.0.18
new_version=0.0.19-h, --helpPrint help and exitUsing bumpversion in a scriptIf you need to use the version generated by bumpversion in a script you can make use of
the--listoption, combined withgrepandsed.Say for example that you are using git-flow to manage your project and want to automatically
create a release. When you issuegit flow release startyou already need to know the
new version, before applying the change.The standard way to get it in a bash script isbump2version --dry-run --list <part> | grep <field name> | sed -r s,"^.*=",,wherepartis as usual the part of the version number you are updating. You need to specify--dry-runto avoid bumpversion actually bumping the version number.For example, if you are updating the minor number and looking for the new version number this becomesbump2version --dry-run --list minor | grep new_version | sed -r s,"^.*=",,Using bumpversion to maintain a go.mod file within a Go projectIn a module-aware Go project, when you create a major version of your module beyond v1, your module name will need
to include the major version # (e.g.github.com/myorg/myproject/v2).You can use bump2version to maintain the major version # within the go.mod file by using theparseandserializeoptions, as in this example:Example.bumpversion.cfgfile:[bumpversion]
    current_version = 2.0.0
    commit = True

    [bumpversion:file:go.mod]
    parse = (?P<major>\d+)
    serialize = {major}
    search = module github.com/myorg/myproject/v{current_version}
    replace = module github.com/myorg/myproject/v{new_version}Examplego.modfile:module github.com/myorg/myproject/v2

    go 1.12

    require (
        ...
    )Then run this command to create version 3.0.0 of your project:bump2version --new-version 3.0.0 majorYourgo.modfile now contains this module directive:module github.com/myorg/myproject/v3Development & ContributingThank you contributors! You can find a full list here:https://github.com/c4urself/bump2version/graphs/contributorsSee also ourCONTRIBUTING.mdDevelopment of this happens on GitHub, patches including tests, documentation
are very welcome, as well as bug reports! Also please open an issue if this
tool does not support every aspect of bumping versions in your development
workflow, as it is intended to be very versatile.Licensebump2version is licensed under the MIT License - see theLICENSE.rstfile for details