tbump


Nametbump JSON
Version 6.11.0 PyPI version JSON
download
home_pagehttps://github.com/dmerejkowsky/tbump
SummaryBump software releases
upload_time2023-09-09 11:22:59
maintainer
docs_urlNone
authorDimitri Merejkowsky
requires_python>=3.7,<4.0
licenseBSD-3-Clause
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            .. image:: https://img.shields.io/pypi/v/tbump.svg
  :target: https://pypi.org/project/tbump/

.. image:: https://img.shields.io/github/license/dmerejkowsky/tbump.svg
  :target: https://github.com/dmerejkowsky/tbump/blob/main/LICENSE

.. image:: https://github.com/dmerejkowsky/tbump/workflows/tests/badge.svg
   :target: https://github.com/dmerejkowsky/tbump/actions

.. image:: https://github.com/dmerejkowsky/tbump/workflows/linters/badge.svg
   :target: https://github.com/dmerejkowsky/tbump/actions

.. image:: https://img.shields.io/badge/code%20style-black-black.svg
   :target: https://github.com/psf/black

.. image:: https://img.shields.io/badge/mypy-checked-blue.svg
   :target: https://mypy-lang.org


tbump: bump software releases
=============================

tbump helps you bump the version of your project easily.

Note
----

This project was originally hosted on the `TankerHQ
<https://github.com/TankerHQ>`_ organization, which was my employer from 2016
to 2021. They kindly agreed to give me back ownership of this project. Thanks!

Installation
------------

The recommended way to install ``tbump`` is to use `pipx <https://pipxproject.github.io/pipx/>`_

* Make sure to have Python **3.7** or later installed.
* Install ``pipx``
* Run ``pipx install tbump``.

``tbump`` is also available on ``pypi`` and can be installed with ``pip`` if you know what you are doing.

Screenshot
-----------

Here's what a typical usage of ``tbump`` looks like:

.. code-block:: console

    $ tbump 5.0.5
    :: Bumping from 5.0.4 to 5.0.5
    => Would patch these files
    - setup.py:14 version="5.0.4",
    + setup.py:14 version="5.0.5",
    - tbump.toml:2 current = "5.0.4"
    + tbump.toml:2 current = "5.0.5"
    => Would run these hooks before commit
    * (1/2) $ ./test.sh
    * (2/2) $ grep -q -F 5.0.5 Changelog.rst
    => Would run these git commands
     * git add --update
     * git commit --message Bump to 5.0.5
     * git tag --annotate --message v5.0.5 v5.0.5
     * git push origin master
     * git push origin v5.0.5
    => Would run these hooks after push
    * (1/1) $ ./publish.sh
    :: Looking good? (y/N)
    y
    => Patching files
    ...
    => Running hooks before commit
    ...
    => Making bump commit and push matching tags
    ...
    => Running hooks after push
    ...
    Done ✓



Usage
------

First, run ``tbump init <current_version>``, where ``current_version``
is the current version of your program. This will create a
``tbump.toml`` file looking like this:

.. code-block:: ini

    [version]
    current = "1.2.41"
    regex = '''
      (?P<major>\d+)
      \.
      (?P<minor>\d+)
      \.
      (?P<patch>\d+)
    '''

    [git]
    message_template = "Bump to {new_version}"
    tag_template = "v{new_version}"

    [[file]]
    src = "setup.py"


.. note::

 * The file uses `toml syntax <https://github.com/toml-lang/toml>`_.
 * Strings should be templated using curly brackets, to be used with
   Python's built-in ``.format()`` method.
 * Paths may contain unix-style `globs
   <https://docs.python.org/3/library/glob.html>`_, e.g. ``src =
   "a/**/script.?s"`` matches both ``a/b/script.js`` and
   ``a/b/c/script.ts``.
 * The version regular expression will be used in `verbose mode
   <https://docs.python.org/3/library/re.html#re.VERBOSE>`_ and can
   contain named groups (see below).
 * tbump will also look for a ``[tool.tbump]`` section in the
   `pyproject.toml` file if its exists. You can use ``tbump init`` with
   the ``--pyproject`` option to append the configuration in this file
   instead of creating a new file.


Then run:

.. code-block:: console

    $ tbump 1.2.42

``tbump`` will:

* Replace the string ``1.2.41`` by ``1.2.42`` in every file listed in the
  configuration

* Make a commit based on the ``message_template``.

* Make an **annotated** tag based on the ``tag_template``

* Push the current branch and the tag.

Note that by default, ``tbump`` will display all the changes and stop to ask if they are correct before performing any action, allowing you to abort and re-try the bump if something is not right.
You can use ``--non-interactive`` to disable this behavior.

If you only want to bump the files without performing any git actions or running the hook commands, use the ``--only-patch`` option.

The current version of the project can be found using the command:

.. code-block:: console

    $ tbump current-version

Advanced configuration
----------------------

Command-line options
++++++++++++++++++++

See:

.. code-block:: console

   tbump --help


Restricting the lines that are replaced
+++++++++++++++++++++++++++++++++++++++


Sometimes you want to make sure only the line matching a given pattern is replaced. For instance, with the following ``package.json``:

.. code-block:: js

    /* in package.json */
    {
       "name": "foo",
       "version": "0.42",
       "dependencies": {
         "some-dep": "0.42",
         "other-dep": "1.3",
       }
    }

you'll want to make sure that when you bump from ``0.42`` to ``0.43``, that the line containing ``some-dep`` does not change.

In this case, you can set a ``search`` option in the ``file`` section:

.. code-block:: ini

    # In tbump.toml

    [[file]]
    src = "package.json"
    search = '"version": "{current_version}"'

Note that the search string is actually a full regular expression, except for the ``{current_version}`` marker which is substituted as plain text.


Using a custom version template
+++++++++++++++++++++++++++++++

If you are using a version schema like ``1.2.3-alpha-4``, you may want to expose a variable that only contains the "public" part of the version string. (``1.2.3`` in this case).

To do so, add a ``version_template`` option in the ``file`` section. The names used in the format string should match the group names in the regular expression.


.. code-block:: js

      /* in version.js */

      export FULL_VERSION = '1.2.3-alpha-4';
      export PUBLIC_VERSION = '1.2.3';

.. code-block:: ini


      [[file]]
      src = "version.js"
      version_template = "{major}.{minor}.{patch}"
      search = "export PUBLIC_VERSION = '{current_version}'"

      [[file]]
      src = "version.js"
      search = "export FULL_VERSION = '{current_version}'"


Running commands before commit
++++++++++++++++++++++++++++++

You can specify a list of hooks to be run after the file have changed, but before the commit is made and pushed.

This is useful if some of the files under version control are generated through an external program.

Here's an example:


.. code-block:: ini

    [[before_commit]]
    name = "Check Changelog"
    cmd = "grep -q -F {new_version} Changelog.rst"


The name is mandatory. The command will be executed via the shell, after the  ``{new_version}``  placeholder is replaced with the new version.

Any hook that fails will interrupt the bump. You may want to run ``git reset --hard`` before trying again to undo the changes made in the files.

Running commands after push
+++++++++++++++++++++++++++

You can specify a list of hooks to be run right after the tag has been pushed, using an `[[after_push]]` section.

This is useful if you need the command to run on a clean repository, without un-committed changes, for instance to publish ``rust`` packages:

.. code-block:: ini

    [[after_push]]
    name = "Publish to crates.io"
    cmd = "cargo publish"


Setting default values for version fields
+++++++++++++++++++++++++++++++++++++++++


(Added in 6.6.0)

If you have a ``version_template`` that includes fields that don't always have a match
(e.g. prerelease info),
you can set a default value to use instead of ``None``,
which would raise an error.

For example:

.. code-block:: ini

    [version]
    current = "1.2.3"
    regex = """
      (?P<major>\d+)
      \.
      (?P<minor>\d+)
      \.
      (?P<patch>\d+)
      (\-
        (?P<extra>.+)
      )?
      """

    [[file]]
    src = "version.py"
    version_template = '({major}, {minor}, {patch}, "{extra}")'
    search = "version_info = {current_version}"

    [[field]]
    # the name of the field
    name = "extra"
    # the default value to use, if there is no match
    default = ""


Working with git providers that don't support --atomic
++++++++++++++++++++++++++++++++++++++++++++++++++++++

If the push destination does not support ``--atomic``,
add ``atomic_push=false`` to the config file,
under the ``[git]`` section:

..code-block:: ini

  [git]
  atomic_push = false


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dmerejkowsky/tbump",
    "name": "tbump",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Dimitri Merejkowsky",
    "author_email": "dimitri@dmerej.info",
    "download_url": "https://files.pythonhosted.org/packages/ab/1f/d02379532311192521a20b3597dc0f01bd37596e950a6cb40795ae9acb94/tbump-6.11.0.tar.gz",
    "platform": null,
    "description": ".. image:: https://img.shields.io/pypi/v/tbump.svg\n  :target: https://pypi.org/project/tbump/\n\n.. image:: https://img.shields.io/github/license/dmerejkowsky/tbump.svg\n  :target: https://github.com/dmerejkowsky/tbump/blob/main/LICENSE\n\n.. image:: https://github.com/dmerejkowsky/tbump/workflows/tests/badge.svg\n   :target: https://github.com/dmerejkowsky/tbump/actions\n\n.. image:: https://github.com/dmerejkowsky/tbump/workflows/linters/badge.svg\n   :target: https://github.com/dmerejkowsky/tbump/actions\n\n.. image:: https://img.shields.io/badge/code%20style-black-black.svg\n   :target: https://github.com/psf/black\n\n.. image:: https://img.shields.io/badge/mypy-checked-blue.svg\n   :target: https://mypy-lang.org\n\n\ntbump: bump software releases\n=============================\n\ntbump helps you bump the version of your project easily.\n\nNote\n----\n\nThis project was originally hosted on the `TankerHQ\n<https://github.com/TankerHQ>`_ organization, which was my employer from 2016\nto 2021. They kindly agreed to give me back ownership of this project. Thanks!\n\nInstallation\n------------\n\nThe recommended way to install ``tbump`` is to use `pipx <https://pipxproject.github.io/pipx/>`_\n\n* Make sure to have Python **3.7** or later installed.\n* Install ``pipx``\n* Run ``pipx install tbump``.\n\n``tbump`` is also available on ``pypi`` and can be installed with ``pip`` if you know what you are doing.\n\nScreenshot\n-----------\n\nHere's what a typical usage of ``tbump`` looks like:\n\n.. code-block:: console\n\n    $ tbump 5.0.5\n    :: Bumping from 5.0.4 to 5.0.5\n    => Would patch these files\n    - setup.py:14 version=\"5.0.4\",\n    + setup.py:14 version=\"5.0.5\",\n    - tbump.toml:2 current = \"5.0.4\"\n    + tbump.toml:2 current = \"5.0.5\"\n    => Would run these hooks before commit\n    * (1/2) $ ./test.sh\n    * (2/2) $ grep -q -F 5.0.5 Changelog.rst\n    => Would run these git commands\n     * git add --update\n     * git commit --message Bump to 5.0.5\n     * git tag --annotate --message v5.0.5 v5.0.5\n     * git push origin master\n     * git push origin v5.0.5\n    => Would run these hooks after push\n    * (1/1) $ ./publish.sh\n    :: Looking good? (y/N)\n    y\n    => Patching files\n    ...\n    => Running hooks before commit\n    ...\n    => Making bump commit and push matching tags\n    ...\n    => Running hooks after push\n    ...\n    Done \u2713\n\n\n\nUsage\n------\n\nFirst, run ``tbump init <current_version>``, where ``current_version``\nis the current version of your program. This will create a\n``tbump.toml`` file looking like this:\n\n.. code-block:: ini\n\n    [version]\n    current = \"1.2.41\"\n    regex = '''\n      (?P<major>\\d+)\n      \\.\n      (?P<minor>\\d+)\n      \\.\n      (?P<patch>\\d+)\n    '''\n\n    [git]\n    message_template = \"Bump to {new_version}\"\n    tag_template = \"v{new_version}\"\n\n    [[file]]\n    src = \"setup.py\"\n\n\n.. note::\n\n * The file uses `toml syntax <https://github.com/toml-lang/toml>`_.\n * Strings should be templated using curly brackets, to be used with\n   Python's built-in ``.format()`` method.\n * Paths may contain unix-style `globs\n   <https://docs.python.org/3/library/glob.html>`_, e.g. ``src =\n   \"a/**/script.?s\"`` matches both ``a/b/script.js`` and\n   ``a/b/c/script.ts``.\n * The version regular expression will be used in `verbose mode\n   <https://docs.python.org/3/library/re.html#re.VERBOSE>`_ and can\n   contain named groups (see below).\n * tbump will also look for a ``[tool.tbump]`` section in the\n   `pyproject.toml` file if its exists. You can use ``tbump init`` with\n   the ``--pyproject`` option to append the configuration in this file\n   instead of creating a new file.\n\n\nThen run:\n\n.. code-block:: console\n\n    $ tbump 1.2.42\n\n``tbump`` will:\n\n* Replace the string ``1.2.41`` by ``1.2.42`` in every file listed in the\n  configuration\n\n* Make a commit based on the ``message_template``.\n\n* Make an **annotated** tag based on the ``tag_template``\n\n* Push the current branch and the tag.\n\nNote that by default, ``tbump`` will display all the changes and stop to ask if they are correct before performing any action, allowing you to abort and re-try the bump if something is not right.\nYou can use ``--non-interactive`` to disable this behavior.\n\nIf you only want to bump the files without performing any git actions or running the hook commands, use the ``--only-patch`` option.\n\nThe current version of the project can be found using the command:\n\n.. code-block:: console\n\n    $ tbump current-version\n\nAdvanced configuration\n----------------------\n\nCommand-line options\n++++++++++++++++++++\n\nSee:\n\n.. code-block:: console\n\n   tbump --help\n\n\nRestricting the lines that are replaced\n+++++++++++++++++++++++++++++++++++++++\n\n\nSometimes you want to make sure only the line matching a given pattern is replaced. For instance, with the following ``package.json``:\n\n.. code-block:: js\n\n    /* in package.json */\n    {\n       \"name\": \"foo\",\n       \"version\": \"0.42\",\n       \"dependencies\": {\n         \"some-dep\": \"0.42\",\n         \"other-dep\": \"1.3\",\n       }\n    }\n\nyou'll want to make sure that when you bump from ``0.42`` to ``0.43``, that the line containing ``some-dep`` does not change.\n\nIn this case, you can set a ``search`` option in the ``file`` section:\n\n.. code-block:: ini\n\n    # In tbump.toml\n\n    [[file]]\n    src = \"package.json\"\n    search = '\"version\": \"{current_version}\"'\n\nNote that the search string is actually a full regular expression, except for the ``{current_version}`` marker which is substituted as plain text.\n\n\nUsing a custom version template\n+++++++++++++++++++++++++++++++\n\nIf you are using a version schema like ``1.2.3-alpha-4``, you may want to expose a variable that only contains the \"public\" part of the version string. (``1.2.3`` in this case).\n\nTo do so, add a ``version_template`` option in the ``file`` section. The names used in the format string should match the group names in the regular expression.\n\n\n.. code-block:: js\n\n      /* in version.js */\n\n      export FULL_VERSION = '1.2.3-alpha-4';\n      export PUBLIC_VERSION = '1.2.3';\n\n.. code-block:: ini\n\n\n      [[file]]\n      src = \"version.js\"\n      version_template = \"{major}.{minor}.{patch}\"\n      search = \"export PUBLIC_VERSION = '{current_version}'\"\n\n      [[file]]\n      src = \"version.js\"\n      search = \"export FULL_VERSION = '{current_version}'\"\n\n\nRunning commands before commit\n++++++++++++++++++++++++++++++\n\nYou can specify a list of hooks to be run after the file have changed, but before the commit is made and pushed.\n\nThis is useful if some of the files under version control are generated through an external program.\n\nHere's an example:\n\n\n.. code-block:: ini\n\n    [[before_commit]]\n    name = \"Check Changelog\"\n    cmd = \"grep -q -F {new_version} Changelog.rst\"\n\n\nThe name is mandatory. The command will be executed via the shell, after the  ``{new_version}``  placeholder is replaced with the new version.\n\nAny hook that fails will interrupt the bump. You may want to run ``git reset --hard`` before trying again to undo the changes made in the files.\n\nRunning commands after push\n+++++++++++++++++++++++++++\n\nYou can specify a list of hooks to be run right after the tag has been pushed, using an `[[after_push]]` section.\n\nThis is useful if you need the command to run on a clean repository, without un-committed changes, for instance to publish ``rust`` packages:\n\n.. code-block:: ini\n\n    [[after_push]]\n    name = \"Publish to crates.io\"\n    cmd = \"cargo publish\"\n\n\nSetting default values for version fields\n+++++++++++++++++++++++++++++++++++++++++\n\n\n(Added in 6.6.0)\n\nIf you have a ``version_template`` that includes fields that don't always have a match\n(e.g. prerelease info),\nyou can set a default value to use instead of ``None``,\nwhich would raise an error.\n\nFor example:\n\n.. code-block:: ini\n\n    [version]\n    current = \"1.2.3\"\n    regex = \"\"\"\n      (?P<major>\\d+)\n      \\.\n      (?P<minor>\\d+)\n      \\.\n      (?P<patch>\\d+)\n      (\\-\n        (?P<extra>.+)\n      )?\n      \"\"\"\n\n    [[file]]\n    src = \"version.py\"\n    version_template = '({major}, {minor}, {patch}, \"{extra}\")'\n    search = \"version_info = {current_version}\"\n\n    [[field]]\n    # the name of the field\n    name = \"extra\"\n    # the default value to use, if there is no match\n    default = \"\"\n\n\nWorking with git providers that don't support --atomic\n++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\nIf the push destination does not support ``--atomic``,\nadd ``atomic_push=false`` to the config file,\nunder the ``[git]`` section:\n\n..code-block:: ini\n\n  [git]\n  atomic_push = false\n\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "Bump software releases",
    "version": "6.11.0",
    "project_urls": {
        "Changelog": "https://github.com/dmerejkowsky/tbump/blob/main/Changelog.rst",
        "Homepage": "https://github.com/dmerejkowsky/tbump",
        "Issues": "https://github.com/dmerejkowsky/tbump/issues",
        "Repository": "https://github.com/dmerejkowsky/tbump"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4841c21994a64efe86ed81c1a0935aeec840548839a37a7f3716f74a75e54fc2",
                "md5": "b1563e7cb8b249ca5dce652ed8e5c994",
                "sha256": "6b181fe6f3ae84ce0b9af8cc2009a8bca41ded34e73f623a7413b9684f1b4526"
            },
            "downloads": -1,
            "filename": "tbump-6.11.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b1563e7cb8b249ca5dce652ed8e5c994",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 35607,
            "upload_time": "2023-09-09T11:22:56",
            "upload_time_iso_8601": "2023-09-09T11:22:56.581487Z",
            "url": "https://files.pythonhosted.org/packages/48/41/c21994a64efe86ed81c1a0935aeec840548839a37a7f3716f74a75e54fc2/tbump-6.11.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ab1fd02379532311192521a20b3597dc0f01bd37596e950a6cb40795ae9acb94",
                "md5": "513a6583a652a5f3a2da2108047cb085",
                "sha256": "385e710eedf0a8a6ff959cf1e9f3cfd17c873617132fc0ec5f629af0c355c870"
            },
            "downloads": -1,
            "filename": "tbump-6.11.0.tar.gz",
            "has_sig": false,
            "md5_digest": "513a6583a652a5f3a2da2108047cb085",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 28642,
            "upload_time": "2023-09-09T11:22:59",
            "upload_time_iso_8601": "2023-09-09T11:22:59.039107Z",
            "url": "https://files.pythonhosted.org/packages/ab/1f/d02379532311192521a20b3597dc0f01bd37596e950a6cb40795ae9acb94/tbump-6.11.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-09 11:22:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dmerejkowsky",
    "github_project": "tbump",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "tbump"
}
        
Elapsed time: 0.12628s