automated versioning

This commit is contained in:
mazzol_a
2025-05-05 08:29:17 +02:00
parent 12ae1424fb
commit 81f2a737e9
5 changed files with 61 additions and 3 deletions

View File

@ -1,12 +1,17 @@
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.15)
project(aare project(aare
VERSION 1.0.0
DESCRIPTION "Data processing library for PSI detectors" DESCRIPTION "Data processing library for PSI detectors"
HOMEPAGE_URL "https://github.com/slsdetectorgroup/aare" HOMEPAGE_URL "https://github.com/slsdetectorgroup/aare"
LANGUAGES C CXX LANGUAGES C CXX
) )
# Read VERSION file into project version
set(VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/VERSION")
file(READ "${VERSION_FILE}" VERSION_CONTENT)
string(STRIP "${VERSION_CONTENT}" PROJECT_VERSION_STRING)
set(PROJECT_VERSION ${PROJECT_VERSION_STRING})
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)

1
VERSION Normal file
View File

@ -0,0 +1 @@
0.0.0

View File

@ -1,6 +1,10 @@
source:
path: ../
{% set version = load_file_regex(load_file = 'VERSION', regex_pattern = '(\d+(?:\.\d+)*(?:[\+\w\.]+))').group(1) %}
package: package:
name: aare name: aare
version: 2025.4.22 #TODO! how to not duplicate this? version: {{version}}
source: source:
path: .. path: ..

View File

@ -1,10 +1,16 @@
[tool.scikit-build.metadata.version]
provider = "scikit_build_core.metadata.regex"
input = "VERSION"
regex = '^(?P<version>\d+(?:\.\d+)*(?:[\.\+\w]+)?)$'
result = "{version}"
[build-system] [build-system]
requires = ["scikit-build-core>=0.10", "pybind11", "numpy"] requires = ["scikit-build-core>=0.10", "pybind11", "numpy"]
build-backend = "scikit_build_core.build" build-backend = "scikit_build_core.build"
[project] [project]
name = "aare" name = "aare"
version = "2025.4.22" dynamic = ["version"]
requires-python = ">=3.11" requires-python = ">=3.11"
dependencies = [ dependencies = [
"numpy", "numpy",

42
update_version.py Normal file
View File

@ -0,0 +1,42 @@
# SPDX-License-Identifier: LGPL-3.0-or-other
# Copyright (C) 2021 Contributors to the Aare Package
"""
Script to update VERSION file with semantic versioning if provided as an argument, or with 0.0.0 if no argument is provided.
"""
import sys
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
if len(sys.argv) < 2:
return "0.0.0"
version = sys.argv[1]
try:
v = Version(version) # normalizcheck if version follows PEP 440 specification
#replace -
return version.replace("-", ".")
except InvalidVersion as e:
print(f"Invalid version {version}. Version format must follow semantic versioning format of python PEP 440 version identification specification.")
sys.exit(1)
def write_version_to_file(version):
version_file_path = os.path.join(SCRIPT_DIR, "VERSION")
with open(version_file_path, "w") as version_file:
version_file.write(version)
print(f"Version {version} written to VERSION file.")
# Main script
if __name__ == "__main__":
version = get_version()
write_version_to_file(version)