Package: changelog2version
Changelog2versionUpdate version info file with latest changelog version entryGeneralCreate version info files based on the latest changelog entry.InstallationUsageAvailable default template filesC header filePython package fileJSON outputConsoleFileValidate generated fileAdvancedCustom regular expressionsCustom template fileAdditional version info contentContributingUnittestsCreditsInstallationpipinstallchangelog2versionUsageThis example shows you how to parse therepo's changelogand
update thepackage version filewith that
version.changelog2version\--changelog_filechangelog.md\--version_fileexamples/version.py\--debugAvailable default template filesBy default a Python version file is generated. Check the table below and the
example usage for further details and supported template filesTypeParameterDescriptionPythonpySeeexample package versionC/CPPcHeader file with available version infoC header filechangelog2version\--changelog_filechangelog.md\--version_fileexamples/version_info.h\--version_file_typec\--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

#endifPython package filechangelog2version\--changelog_filechangelog.md\--version_fileexamples/version.py\--version_file_typepy\--debug#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

__version_info__ = ("0", "4", "0")
__version__ = '.'.join(__version_info__)JSON outputThe additional, optional argument--prettywill output the JSON data with an
indentation of 4 in order to provide the data in an easy to read format.Consolechangelog2version\--changelog_filechangelog.md\--print\--debug{"info":{"version":"0.7.0","description":"### Added\n- Changelog parsed as JSON contains a new key `description` like the PyPi package JSON info, compare to `https://pypi.org/pypi/changelog2version/json`, with the description/content of the latest change, see #19, relates to #18\n- Increase unittest coverage above 95%\n\n### Changed\n- Line breaks are no longer used in this changelog for enumerations\n- Issues are referenced as `#123` instead of `[#123][ref-issue-123]` to avoid explicit references at the bottom or some other location in the file\n- Output of `changelog2version` call with `--print` but without `--debug` option is JSON compatible\n"},"releases":{"0.7.0":[{"upload_time":"2022-11-11"}],"0.6.0":[{"upload_time":"2022-10-26"}],"0.5.0":[{"upload_time":"2022-10-20"}],"0.4.0":[{"upload_time":"2022-08-07"}],"0.3.0":[{"upload_time":"2022-08-05"}],"0.2.0":[{"upload_time":"2022-08-03"}],"0.1.1":[{"upload_time":"2022-07-31"}],"0.1.0":[{"upload_time":"2022-07-31"}]}}To get the latest version and description in the console as environment
variables use the following callLATEST_VERSION=$(changelog2version--changelog_filechangelog.md--print|python-c"import sys, json; print(json.load(sys.stdin)['info']['version'])")LATEST_CHANGE=$(changelog2version--changelog_filechangelog.md--print|python-c"import sys, json; print(json.load(sys.stdin)['info']['description'])")echo"The latest version extracted from the changelog is${LATEST_VERSION}"# The latest version extracted from the changelog is 0.7.0echo"Description of the latest change"echo"${LATEST_CHANGE}"# ### Added# - Changelog parsed as JSON contains a new key `description` like the PyPi package JSON info, compare to `https://pyp# i.org/pypi/changelog2version/json`, with the description/content of the latest change, see #19, relates to #18# - Increase unittest coverage above 95%# ### Changed# - Line breaks are no longer used in this changelog for enumerations# - Issues are referenced as `#123` instead of `[#123][ref-issue-123]` to avoid explicit references at the bottom or s# ome other location in the file# - Output of `changelog2version` call with `--print` but without `--debug` option is JSON compatibleFilechangelog2version\--changelog_filechangelog.md\--outputchangelog.json\--pretty\--debugSeeexample JSON fileValidate generated fileTo validate an already generated version file agains the latest available
changelog the--validateoption can be used.The following command will exit with a non-zero code in case of a difference
between the generated version file (examples/version.py) and the latest
changelog content.changelog2version\--changelog_filechangelog.md\--version_fileexamples/version.py\--validate\--debugBy default a Python version file is assumed, for a C header version file the
call has to be extended with theversion_file_typeoptionchangelog2version\--changelog_filechangelog.md\--version_fileexamples/version_info.h\--version_file_typec\--validate\--debugAdvancedCustom regular expressionsTo extract a version line from a given changelog file with an alternative
regex, theversion_line_regexargument can be used as shown below. The
expression is validated during the CLI argument parsingchangelog2version\--changelog_filechangelog.md\--version_filesrc/changelog2version/version.py\--version_line_regex"^\#\# \[\d{1,}[.]\d{1,}[.]\d{1,}\]"\--debugSame applies for a custom semver line regex in order to extract the semantic
version part from a full version line, use thesemver_line_regexargument to
adjust the regular expression to your needs.Custom template fileBeside the default supportedtemplate filesusers can
also provide custom template files.This is the list of currently available variablesNameDescriptionmajor_versionMajor version, incompatible API changesminor_versionMinor version, add functionality (backwards-compatible)patch_versionPatch version, bug fixes (backwards-compatible)prerelease_datapre-release data, if availablebuild_dataBuild metadata, if availablefile_nameUser specified name of rendered filefile_name_without_suffixUser specified name of rendered file without suffixtemplate_nameName of rendered template filetemplate_name_without_suffixName of rendered template file without suffixCustom keywordProvided by the user via--additional_template_dataadditional_data="{\"creation_datetime\": \"$(date+"%Y-%m-%dT%H:%M:%S")\", \"machine_name\": \"$(whoami)\"}"changelog2version\--changelog_filechangelog.md\--version_fileexamples/version_info.c\--template_fileexamples/version_info.c.template\--additional_template_data"${additional_data}"\--debug# or less fancychangelog2version\--changelog_filechangelog.md\--version_fileexamples/version_info.c\--template_fileexamples/version_info.c.template\--additional_template_data'{"creation_datetime": "2022-08-05T21:11:12", "machine_name": "Death Star"}'\--debugExecuting the created example fileexamples/version_info.cwill 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 StarAdditional version info contentTo 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 thePython Core metadata specificationsandPEP440changelog2version\--changelog_filechangelog.md\--version_fileexamples/version.py\--version_file_typepy\--additional_version_info="rc1234"\--debug#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

__version_info__ = ("0", "5", "0")
__version__ = '.'.join(__version_info__) + '-rc1234'ContributingUnittestsRun the unittests locally with the following command after installing this
package in a virtual environment or by usingtoxto create one on each run.# install the package with all its development dependenciespipinstall.[dev]# run all testsnose2--configtests/unittest.cfg# run only one specific testsnose2tests.test_extract_version.TestExtractVersion.test_version_line_regexGenerate the coverage files withpythoncreate_report_dirs.py
coveragehtmlThe coverage report is placed atreports/coverage/html/index.htmlCreditsBased on thePyPa sample project. Also a big thank you to
the creators and maintainers ofSemVer.orgfor their
documentation andregex example