Skip to main content

Updates versions across multiple files.

Install

pip install vm

Usage

You need a versions.json, or a versions.yml where you can specify for what you’re tracking the versions, and what files to be updated using glob patterns:

germanium:
  version: 1.10.3
  files:
    README.*: "^(germanium )(.*?)$"
    setup.py: "version='**VERSION**',"
    doc/usage/index.adoc: "^(= Germanium v)(.*?)$"
    germanium/version.py: "current = \"**VERSION**\""

Help:

usage: version-manager [-h] [--display NAME] [--all]
                       [--set NAME=VAL [NAME=VAL ...]] [--load FILE] [-t]
                       [--ignore-missing-parents] [--version]

Versions processor

optional arguments:
  -h, --help            show this help message and exit
  --display NAME, -d NAME
                        Display the version of a single tracked version.
  --all, -a, --list     Display all the tracked versions and their values.
  --set NAME=VAL [NAME=VAL ...], -s NAME=VAL [NAME=VAL ...]
                        Set values overriding what's in the yml files.
  --load FILE, -l FILE  Override versions from the given yml file.
  -t, --tag-name, --tag
                        Get the current name to use in general tags. If the
                        branch name can't be detected from the git repo, the
                        $BRANCH_NAME environment variable will be used.
  --ignore-missing-parents
                        Ignore missing parents, and simply don't patch the
                        values. Upstream values are still being patched if
                        existing.
  --version             Show the currently installed program version (2.5.1)

Specifying Versions

The version value will be expanded using the shell if it contains a '$' or a '’, so you can have a version such as:

"description": {
  "version": "Built at $(date) on $(uname -n)"
}

or YAML:

description:
  version: Built at $(date) on $(uname -n)

Versions can also refer to other version files, and extract properties from there, using the parent: notation in the version:

"germaniumdrivers": {
  "version": "parent:../germanium/@germaniumdrivers"
}

germaniumdrivers:
  version: "parent:../germanium/@germaniumdrivers"

The path will point to the versions.json/yml file, or to the folder that contains the versions.json/yml file, and after that fill will be read and interpreted the germaniumdrivers version will be used.

Versions can be also manually overriden from the command line, using the --set or -s flag, for example:

version-manager -s germanium=2.0.8

This will ignore the value specified in the versions.yml file, and use the specified one.

Feature Branches

The version can also be prefixed by upstream:. In that case if the currently checked out branch name contains -x-, or the exported BRANCH_NAME environment variable has that name, the version returned by version-manager --tag will be used instead.

germaniumdrivers:
  version: "upstream:1.1.0"

As long as the branch is not marked to contain cross feature branches dependencies with -x- it will return 1.1.0.

This also works for parent branches, so you can have:

germaniumdrivers:
  version: "parent:upstream:../germanium/@germaniumdrivers"

If the branch name is for example: feature/UI-123-x-test-new-drivers the parent: value will not be read, and 0.1-feature_UI-123-x-test-new-drivers will be returned as the value.

File Matchers

There are currently only three file matchers:

RegExp File Matcher

It is a RegExp that has two or three groups, and it will have the second group replaced to the matched version.

VERSION File Matcher

This will construct a RegExp that will match exactly the given text, with the VERSION being the second group.

So having a matcher such as:

"files": {
    "README": "This installs version **VERSION** of the product."
}

or yaml

files:
  README: This installs version **VERSION** of the product.

is equivalent with:

"files": {
    "README": "(This installs version )(.+?)( of the product\\.)"
}

or yaml

files:
  README: (This installs version )(.+?)( of the product\\.)

If the **`s are replaced with `^^ at the beginning, or ` at the end, they will act as RegExp anchors, equivalent to `^` and `$`. In case in the expression there is content before the `^^`, or after the `, the content is ignored.

maven: File Matcher

This will construct a RegExp that will match:

`(<groupId>${m[1]}</groupId>\\s*` +
`<artifactId>${m[2]}</artifactId>\\s*` +
`<version>)(.*?)(</version>)`;

In order to specify the matcher, just use:

{"germanium": {
  "version": "2.0.0",
  "files": {
    "pom.xml": "maven:com.germaniumhq:germanium"
  }
}

or yaml

germanium:
  version: 2.0.0
  files:
    pom.xml: maven:com.germaniumhq:germanium

Matcher Constraints

In order to make sure that the expressions are not replacing in too many places, constraints can be added to limit, or extend the matches.

Matcher constraints are always active, and in case no constraint is specified then the maximum replacement count is set to 1.

Match Count

{
  "product" : {
    "version": "1.0",
    "files": {
      "README.md": {
        "match": "^(= Germanium v)(.*?)$",
        "count": 2
      }
    }
  }
}

or yaml

product:
  version: "1.0"
  files:
    README.md:
      match: ^(= Germanium v)(.*?)$
      count: 2

The count can be also 0 for no matches, or negative to indicate any number of matches is allowed.

Multiple Matchers

In a single file, we can have multiple matchers as well, for example:

{
  "product" : {
    "version": "1.0",
    "files": {
      "README.md": [
        "^(= Germanium v)(.*?)$",
        "(Germanium )(\\d+\\.\\d+)()"
      ]
    }
  }
}

For each matcher that is added, if there is no match count specified, it’s assumed that it will only match once in the file.

Of course, constraints can be applied for both the full set of matchers:

{
  "product" : {
    "version": "1.0",
    "files": {
      "README.md": {
        "match": [
          "^(= Germanium v)(.*?)$",
          "(Germanium )(\\d+\\.\\d+)()"
        ],
        "count": 3
      }
    }
  }
}

or even individual expressions:

{
  "product" : {
    "version": "1.0",
    "files": {
      "README.md": {
        "match": [
          "^(= Germanium v)(.*?)$",
          {
            "match": "(Germanium )(\\d+\\.\\d+)()",
            "count": 2
          }
        ],
        "count": 3
      }
    }
  }
}

Notes

  1. Files are actually glob patterns, so you can match */.js for example.

  2. The configuration files can be yml.

  3. vm will output the following error codes: 0 when no files are changed, 0 when files are changed successfuly, or a non zero error code in case of error.

Metadata

Release files for vm 2022.11.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vm 2022.11.1
File Size Uploaded
vm-2022.11.1.tar.gz 14.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for vm 2022.11.1
File Interpreter ABI Platform
vm-2022.11.1-py3-none-any.whl Python 3 none any Details

Total release size: 33.2 kB

Release files / vm-2022.11.1.tar.gz

Download URL vm-2022.11.1.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8da131581f2ac5197272939cf37f9ed54dba5b29347be4450ad026fe8b38d24b
BLAKE2b-256 checksum
How to use checksums
b217d533f16b6778fff189201bcf8459d7f3fb6b2864b744980aafa30d0f02ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.8.10 Linux/5.15.0-52-generic

Release files / vm-2022.11.1-py3-none-any.whl

Download URL vm-2022.11.1-py3-none-any.whl
Size 18.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
01ecbe816ac72a914349240d11a3c8c7f73aae9f6878ad828ea05fda204a515e
BLAKE2b-256 checksum
How to use checksums
3caeb49d4ccc6acf9fb2d62406bd1ee0b719df6535fc8efd6436ec30cffec4a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.2 CPython/3.8.10 Linux/5.15.0-52-generic

Release history Release notifications | RSS feed

This release

2022.11.1 This release

2 release files

2.5.4

1 release file

2.5.3

1 release file

2.5.2

1 release file

2.5.1

1 release file

2.5.0

1 release file

2.4.2

1 release file

2.4.1

1 release file

2.4.0

1 release file

2.3.2

1 release file

2.3.0

1 release file

2.2.21

1 release file

2.1.0

1 release file

2.0.22

1 release file

2.0.21

1 release file

2.0.20

1 release file

2.0.19

1 release file

2.0.18

1 release file

2.0.17

1 release file

2.0.16

1 release file

2.0.15

1 release file

2.0.14

1 release file

2.0.12

1 release file

2.0.11

1 release file

2.0.10

1 release file

2.0.9

1 release file

2.0.8

1 release file

2.0.7

1 release file

2.0.6

1 release file

2.0.5

1 release file

2.0.4

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page