diff options
| author | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-04-02 18:44:05 +0300 |
|---|---|---|
| committer | Mehmet Samet Duman <yongdohyun@projecttick.org> | 2026-04-02 18:44:05 +0300 |
| commit | 0b24459ac12b6cf9fd5a401d647796ca254a8fa8 (patch) | |
| tree | f2fd66e2476976a51e2a51330fd95dc6e87b24c1 /tomlplusplus/tools/version.py | |
| parent | b85e90fc3480da0e6a48da73201a0b22488cc650 (diff) | |
| parent | 1c8b7466e4946fcc3bf20484c0e1d001202cca5a (diff) | |
| download | Project-Tick-0b24459ac12b6cf9fd5a401d647796ca254a8fa8.tar.gz Project-Tick-0b24459ac12b6cf9fd5a401d647796ca254a8fa8.zip | |
Add 'tomlplusplus/' from commit '1c8b7466e4946fcc3bf20484c0e1d001202cca5a'
git-subtree-dir: tomlplusplus
git-subtree-mainline: b85e90fc3480da0e6a48da73201a0b22488cc650
git-subtree-split: 1c8b7466e4946fcc3bf20484c0e1d001202cca5a
Diffstat (limited to 'tomlplusplus/tools/version.py')
| -rw-r--r-- | tomlplusplus/tools/version.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tomlplusplus/tools/version.py b/tomlplusplus/tools/version.py new file mode 100644 index 0000000000..1d611d664b --- /dev/null +++ b/tomlplusplus/tools/version.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 +# This file is a part of toml++ and is subject to the the terms of the MIT license. +# Copyright (c) Mark Gillard <mark.gillard@outlook.com.au> +# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text. +# SPDX-License-Identifier: MIT + +import sys +import re +from argparse import ArgumentParser +from pathlib import Path + + + +def read_text_file(path): + print(rf'Reading {path}') + with open(path, r'r', encoding=r'utf-8') as f: + return f.read() + + + +def write_text_file(path, text): + print(rf'Writing {path}') + with open(path, r'w', encoding=r'utf-8', newline='\n') as f: + f.write(text) + + + +if __name__ == '__main__': + + args = ArgumentParser(r'version.py', description=r'Sets the project version in all the necessary places.') + args.add_argument(r'version', type=str) + args = args.parse_args() + + version = re.fullmatch(r'\s*[vV]?\s*([0-9]+)\s*[.,;]+\s*([0-9]+)\s*[.,;]+\s*([0-9]+)\s*', args.version) + if not version: + print(rf"Couldn't parse version triplet from '{args.version}'", file=sys.stderr) + sys.exit(1) + version = (int(version[1]), int(version[2]), int(version[3])) + version_str = rf'{version[0]}.{version[1]}.{version[2]}' + print(rf'version: {version_str}') + + root = Path(__file__).parent.parent.resolve() + + path = root / r'meson.build' + text = read_text_file(path) + text = re.sub(r'''(\s|^)version\s*:\s*['"].*?['"]''', rf"\1version: '{version_str}'", text, count=1) + write_text_file(path, text) + + path = root / r'CMakeLists.txt' + text = read_text_file(path) + text = re.sub(r'''(\s|^)VERSION\s+[0-9](?:[.][0-9]){2}''', rf"\1VERSION {version_str}", text, count=1, flags=re.I) + write_text_file(path, text) + + for path in (root / r'include/toml++/impl/version.hpp', root / r'toml.hpp'): + text = read_text_file(path) + text = re.sub(r'''(\s*#\s*define\s+TOML_LIB_MAJOR)\s+[0-9]+''', rf"\1 {version[0]}", text) + text = re.sub(r'''(\s*#\s*define\s+TOML_LIB_MINOR)\s+[0-9]+''', rf"\1 {version[1]}", text) + text = re.sub(r'''(\s*#\s*define\s+TOML_LIB_PATCH)\s+[0-9]+''', rf"\1 {version[2]}", text) + write_text_file(path, text) + + noop_sub = r'#$%^nbsp^%$#' + for file in (r'README.md', r'docs/pages/main_page.md'): + path = root / file + text = read_text_file(path) + text = re.sub(r'''(toml(?:plusplus|\+\+|pp)\s*[/:^]\s*)[0-9](?:[.][0-9]){2}''', rf"\1{noop_sub}{version_str}", text, flags=re.I) + text = re.sub(r'''(GIT_TAG\s+)(?:v\s*)?[0-9](?:[.][0-9]){2}''', rf"\1v{version_str}", text, flags=re.I) + text = text.replace(noop_sub, '') + write_text_file(path, text) |
