From 948116c9e29751fc2a7d31906cdb7bc9e66da4e9 Mon Sep 17 00:00:00 2001 From: mazzol_a Date: Fri, 25 Apr 2025 10:48:16 +0200 Subject: [PATCH] added regex pattern matching to version in toml file --- conda-recipes/main-library/meta.yaml | 2 +- conda-recipes/python-client/meta.yaml | 2 +- pyproject.toml | 8 +++++++- update_version.py | 17 +++++++---------- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/conda-recipes/main-library/meta.yaml b/conda-recipes/main-library/meta.yaml index aa1fe2d68..63508e8fa 100755 --- a/conda-recipes/main-library/meta.yaml +++ b/conda-recipes/main-library/meta.yaml @@ -4,7 +4,7 @@ source: {% set version = load_file_regex(load_file = 'VERSION', regex_pattern = '(\d+(?:\.\d+)*(?:[\+\w\.]+))').group(1) %} package: name: sls_detector_software - version: {{ version }} #2025.3.19 + version: {{ version }} build: number: 0 diff --git a/conda-recipes/python-client/meta.yaml b/conda-recipes/python-client/meta.yaml index d3fed0b9a..c86f401ef 100644 --- a/conda-recipes/python-client/meta.yaml +++ b/conda-recipes/python-client/meta.yaml @@ -4,7 +4,7 @@ source: {% set version = load_file_regex(load_file = 'VERSION', regex_pattern = '(\d+(?:\.\d+)*(?:[\+\w\.]+))').group(1) %} package: name: slsdet - version: {{ version }} # + version: {{ version }} build: number: 0 diff --git a/pyproject.toml b/pyproject.toml index 776657c41..8deb25dde 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,16 @@ +[tool.scikit-build.metadata.version] +provider = "scikit_build_core.metadata.regex" +input = "VERSION" +regex = '^(?P\d+(?:\.\d+)*(?:[\.\+\w]+)?)$' +result = "{version}" + [build-system] requires = [ "scikit-build-core>=0.10", "pybind11", "numpy",] build-backend = "scikit_build_core.build" [project] name = "slsdet" -version = "0.0.0" +dynamic = ["version"] [tool.cibuildwheel] before-all = "uname -a" diff --git a/update_version.py b/update_version.py index 914797a1d..2b5609198 100644 --- a/update_version.py +++ b/update_version.py @@ -5,10 +5,13 @@ Script to update VERSION file with semantic versioning if provided as an argumen """ import sys -import re -import toml +import os + from packaging.version import Version, InvalidVersion + +SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) + def get_version(): # Check at least one argument is passed @@ -26,19 +29,13 @@ def get_version(): def write_version_to_file(version): - with open("VERSION", "w") as version_file: + version_file_path = os.path.join(SCRIPT_DIR, "VERSION") + with open(version_file_path, "w") as version_file: version_file.write(str(version)) print(f"Version {version} written to VERSION file.") -def update_pyproject_toml_file(version): - pyproject = toml.load("pyproject.toml") - pyproject["project"]["version"] = str(version) - toml.dump(pyproject, open("pyproject.toml", "w")) #write back - print(f"Version in pyproject.toml set to {version}") - # Main script if __name__ == "__main__": version = get_version() write_version_to_file(version) - update_pyproject_toml_file(version)