From da760b2b934af55e5e0f691591245af66c59e773 Mon Sep 17 00:00:00 2001 From: mazzol_a Date: Tue, 22 Apr 2025 14:00:45 +0200 Subject: [PATCH] version number automated for python build --- conda-recipes/build_conda.sh | 8 ++++++++ conda-recipes/main-library/meta.yaml | 6 +++--- conda-recipes/python-client/meta.yaml | 4 ++-- pyproject.toml | 18 +++++++++--------- update_version.py | 22 +++++++++++++++++++++- 5 files changed, 43 insertions(+), 15 deletions(-) create mode 100755 conda-recipes/build_conda.sh diff --git a/conda-recipes/build_conda.sh b/conda-recipes/build_conda.sh new file mode 100755 index 000000000..6915f89a9 --- /dev/null +++ b/conda-recipes/build_conda.sh @@ -0,0 +1,8 @@ + +SCRIPTDIR=$(cd "$(dirname "$0")" && pwd) +VERSION=$(cat $SCRIPTDIR/../VERSION) +export VERSION + +echo "building conda package version: $VERSION" + +conda build . diff --git a/conda-recipes/main-library/meta.yaml b/conda-recipes/main-library/meta.yaml index 2ddc76a6f..232f89b20 100755 --- a/conda-recipes/main-library/meta.yaml +++ b/conda-recipes/main-library/meta.yaml @@ -1,8 +1,8 @@ +#{% set version = load_file('VERSION').strip %} package: name: sls_detector_software - version: 2025.3.19 - - + version: {{ environ.get('VERSION') }} #2025.3.19 + source: path: ../.. diff --git a/conda-recipes/python-client/meta.yaml b/conda-recipes/python-client/meta.yaml index 3b710151c..c5e2cbb38 100644 --- a/conda-recipes/python-client/meta.yaml +++ b/conda-recipes/python-client/meta.yaml @@ -1,7 +1,7 @@ + package: name: slsdet - version: 2025.3.19 #TODO! how to not duplicate this? - + version: 0.0.0 source: path: ../.. diff --git a/pyproject.toml b/pyproject.toml index 3d128f18e..5e11fdc45 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,27 +1,27 @@ [build-system] -requires = ["scikit-build-core>=0.10", "pybind11", "numpy"] +requires = [ "scikit-build-core>=0.10", "pybind11", "numpy",] build-backend = "scikit_build_core.build" [project] name = "slsdet" version = "2025.3.19" - [tool.cibuildwheel] before-all = "uname -a" -[tool.scikit-build] -build.verbose = true -cmake.build-type = "Release" -install.components = ["python"] +[tool.scikit-build.build] +verbose = true +[tool.scikit-build.cmake] +build-type = "Release" + +[tool.scikit-build.install] +components = [ "python",] [tool.scikit-build.cmake.define] -#Only build the control software and python ext SLS_USE_RECEIVER = "OFF" SLS_USE_RECEIVER_BINARIES = "OFF" SLS_USE_TEXTCLIENT = "OFF" SLS_BUILD_SHARED_LIBRARIES = "OFF" - SLS_USE_PYTHON = "ON" -SLS_INSTALL_PYTHONEXT = "ON" \ No newline at end of file +SLS_INSTALL_PYTHONEXT = "ON" diff --git a/update_version.py b/update_version.py index c074ae542..f5c28c5af 100644 --- a/update_version.py +++ b/update_version.py @@ -6,6 +6,10 @@ Script to update VERSION file with semantic versioning if provided as an argumen import sys import re +import os +import toml +import yaml +from jinja2 import Template, Undefined def get_version(): @@ -28,9 +32,25 @@ def write_version_to_file(version): version_file.write(version) print(f"Version {version} written to VERSION file.") +def define_environment_variable(version): + os.environ["VERSION"] = version + +def update_pyproject_toml_file(version): + pyproject = toml.load("pyproject.toml") + pyproject["project"]["version"] = version + toml.dump(pyproject, open("pyproject.toml", "w")) #write back + print(f"Version in pyproject.toml set to {version}") + +class NullUndefined(Undefined): + def __getattr__(self, key): + return '' + + # Main script if __name__ == "__main__": version = get_version() - write_version_to_file(version) \ No newline at end of file + write_version_to_file(version) + define_environment_variable(version) + update_pyproject_toml_file(version)