Skip to main content

Update version info file with latest changelog version entry

Project description

Changelog2version

Downloads Release Python License: MIT codecov

Update version info file with latest changelog version entry


General

Create version info files based on the latest changelog entry.

Installation

pip install changelog2version

Usage

This example shows you how to parse the repo's changelog and update the package version file with that version.

changelog2version \
    --changelog_file changelog.md \
    --version_file examples/version.py \
    --debug

Available default template files

By default a Python version file is generated. Check the table below and the example usage for further details and supported template files

Type Parameter Description
Python py See example package version
C/CPP c Header file with available version info

C header file

changelog2version \
    --changelog_file changelog.md \
    --version_file examples/version_info.h \
    --version_file_type c \
    --debug
//
//  version_info.h
//
//  Created automatically by script
//

#ifndef version_info_h
#define version_info_h

#define MAJOR_VERSION   0     //< major software version
#define MINOR_VERSION   4     //< minor software version
#define PATCH_VERSION   0     //< patch software version

#endif

Python package file

changelog2version \
    --changelog_file changelog.md \
    --version_file examples/version.py \
    --version_file_type py \
    --debug
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

__version_info__ = ("0", "4", "0")
__version__ = '.'.join(__version_info__)

Advanced

Custom regular expressions

To extract a version line from a given changelog file with an alternative regex, the version_line_regex argument can be used as shown below. The expression is validated during the CLI argument parsing

changelog2version \
    --changelog_file changelog.md \
    --version_file src/changelog2version/version.py \
    --version_line_regex "^\#\# \[\d{1,}[.]\d{1,}[.]\d{1,}\]" \
    --debug

Same applies for a custom semver line regex in order to extract the semantic version part from a full version line, use the semver_line_regex argument to adjust the regular expression to your needs.

Custom template file

Beside the default supported template files users can also provide custom template files.

This is the list of currently available variables

Name Description
major_version Major version, incompatible API changes
minor_version Minor version, add functionality (backwards-compatible)
patch_version Patch version, bug fixes (backwards-compatible)
prerelease_data pre-release data, if available
build_data Build metadata, if available
file_name User specified name of rendered file
file_name_without_suffix User specified name of rendered file without suffix
template_name Name of rendered template file
template_name_without_suffix Name of rendered template file without suffix
Custom keyword Provided by the user via --additional_template_data
additional_data="{\"creation_datetime\": \"$(date +"%Y-%m-%dT%H:%M:%S")\", \"machine_name\": \"$(whoami)\"}"
changelog2version \
    --changelog_file changelog.md \
    --version_file examples/version_info.c \
    --template_file examples/version_info.c.template \
    --additional_template_data "${additional_data}" \
    --debug

# or less fancy
changelog2version \
    --changelog_file changelog.md \
    --version_file examples/version_info.c \
    --template_file examples/version_info.c.template \
    --additional_template_data '{"creation_datetime": "2022-08-05T21:11:12", "machine_name": "Death Star"}' \
    --debug

Executing the created example file examples/version_info.c will print the following content (datetime and creator might be different)

Script version is (major.minor.patch): 0.4.0
Prerelease data: None
Prerelease data: None
Creation datetime: 2022-08-05T21:11:12
Created by Death Star

Additional version info content

To create custom release candidate packages the python version file variable __version__ can be exended with a custom string.

Choose the additional version info content carefully as not everything is supported by PyPi, see the Python Core metadata specifications and PEP440

changelog2version \
    --changelog_file changelog.md \
    --version_file examples/version.py \
    --version_file_type py \
    --additional_version_info="rc1234" \
    --debug
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

__version_info__ = ("0", "5", "0")
__version__ = '.'.join(__version_info__) + '-rc1234'

Credits

Based on the PyPa sample project. Also a big thank you to the creators and maintainers of SemVer.org for their documentation and regex example

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

changelog2version-0.5.0.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

changelog2version-0.5.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file changelog2version-0.5.0.tar.gz.

File metadata

  • Download URL: changelog2version-0.5.0.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for changelog2version-0.5.0.tar.gz
Algorithm Hash digest
SHA256 e6a29b27eecb35dd2f2627d2fcfa92d91d824fbb0263084edeaab60c40f2edef
MD5 a583fcb111a471f503792f1b4d651ecc
BLAKE2b-256 8938bf56c7b09fecbdb1b94c87c56531bea60ad5cce99dc09193015d4d9ffa66

See more details on using hashes here.

File details

Details for the file changelog2version-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for changelog2version-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4e94deaa5c9f4148411b2106ddb52aaf1a4e614ca39eaed2b4ecd03d3423cb7b
MD5 6aad0723bfd81c9f4f2bfc84eafebdd7
BLAKE2b-256 76c9fb9287ceb323abe50fa7a48ba041c7aa9d4187d5333a675aacaf69f3c546

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page