From d9e8e1c1c2cc2a867a87d86f638d4926dc5a32da Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 21 Nov 2024 10:46:20 +0100 Subject: [PATCH] dev: version from file to cmake and python (#1025) - renamed conda-recipe folder - added a check to see if build and install folder exists in build.sh (conda recipe) - created VERSION file that has '0.0.0'for developer but can be updated using update_version.py that takes in a version. The script checks for semantic versioning and updates VERSION file - VERSION file also copied along with py files to slsdet in python cmakelist and build_pylib.sh (for conda), also copied in root folder for installations (for no coding purpose) - init.py and setup.py reads this file to get the version (a bit differently to find the VERSION file) - VERSION file read into cmake to get the version and also added to compile definition. So RELEASE removed from versionAPI.h (using SLS_DET_VERSION compile definiton instead) and also removed updateRelease script. - conda getting project version from environment variable SLS_DET_VERSION that is set in build_pylib.sh prior. - added 3.13 python to conda build - anything related to ctb removed from release notes as users will always use developer - sets 0.0.0 to VERSION file by running update_version.py without an argument --- CMakeLists.txt | 12 ++++++- RELEASE.txt | 2 +- VERSION | 1 + conda-recepie/build_pylib.sh | 6 ---- {conda-recepie => conda-recipe}/build.sh | 8 +++-- conda-recipe/build_pylib.sh | 14 ++++++++ .../conda_build_config.yaml | 3 +- .../copy_ctbgui.sh | 0 {conda-recepie => conda-recipe}/copy_gui.sh | 0 {conda-recepie => conda-recipe}/copy_lib.sh | 0 .../copy_moench.sh | 0 {conda-recepie => conda-recipe}/meta.yaml | 14 ++++---- {conda-recepie => conda-recipe}/run_test.sh | 0 python/CMakeLists.txt | 6 ++-- python/setup.py | 18 ++++++---- python/slsdet/__init__.py | 17 +++++---- slsDetectorSoftware/src/Detector.cpp | 2 +- slsSupportLib/include/sls/versionAPI.h | 1 - updateReleaseVersion.sh | 15 -------- update_version.py | 36 +++++++++++++++++++ 20 files changed, 105 insertions(+), 50 deletions(-) create mode 100644 VERSION delete mode 100755 conda-recepie/build_pylib.sh rename {conda-recepie => conda-recipe}/build.sh (86%) create mode 100755 conda-recipe/build_pylib.sh rename {conda-recepie => conda-recipe}/conda_build_config.yaml (83%) rename {conda-recepie => conda-recipe}/copy_ctbgui.sh (100%) rename {conda-recepie => conda-recipe}/copy_gui.sh (100%) rename {conda-recepie => conda-recipe}/copy_lib.sh (100%) rename {conda-recepie => conda-recipe}/copy_moench.sh (100%) rename {conda-recepie => conda-recipe}/meta.yaml (95%) rename {conda-recepie => conda-recipe}/run_test.sh (100%) delete mode 100644 updateReleaseVersion.sh create mode 100644 update_version.py diff --git a/CMakeLists.txt b/CMakeLists.txt index ecef8ad771..9891715fc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,15 @@ # Copyright (C) 2021 Contributors to the SLS Detector Package cmake_minimum_required(VERSION 3.14) project(slsDetectorPackage) -set(PROJECT_VERSION 9.0.0) + +# Read VERSION file into project version +set(VERSION_FILE "${CMAKE_SOURCE_DIR}/VERSION") +file(READ "${VERSION_FILE}" VERSION_CONTENT) +string(STRIP "${VERSION_CONTENT}" PROJECT_VERSION_STRING) +set(PROJECT_VERSION ${PROJECT_VERSION_STRING}) + +# Pass it to the compiler +add_compile_definitions(SLS_DET_VERSION="${PROJECT_VERSION}") set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") @@ -347,3 +355,5 @@ if(SLS_MASTER_PROJECT) set(PROJECT_LIBRARIES slsSupportShared slsDetectorShared slsReceiverShared) include(cmake/package_config.cmake) endif() + +install(FILES ${CMAKE_SOURCE_DIR}/VERSION DESTINATION ${CMAKE_INSTALL_PREFIX}) \ No newline at end of file diff --git a/RELEASE.txt b/RELEASE.txt index 92d8fb1a97..497e1d568d 100644 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -211,4 +211,4 @@ This document describes the differences between vx.x.x and vx.0.2 ------- dhanya.thattil@psi.ch - erik.frojdh@psi.ch \ No newline at end of file + erik.frojdh@psi.ch diff --git a/VERSION b/VERSION new file mode 100644 index 0000000000..bd52db81d0 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.0 \ No newline at end of file diff --git a/conda-recepie/build_pylib.sh b/conda-recepie/build_pylib.sh deleted file mode 100755 index f7cbdc4963..0000000000 --- a/conda-recepie/build_pylib.sh +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-License-Identifier: LGPL-3.0-or-other -# Copyright (C) 2021 Contributors to the SLS Detector Package - -echo "|<-------- starting python build" -cd python -${PYTHON} setup.py install diff --git a/conda-recepie/build.sh b/conda-recipe/build.sh similarity index 86% rename from conda-recepie/build.sh rename to conda-recipe/build.sh index b8f77843ed..251b044778 100755 --- a/conda-recepie/build.sh +++ b/conda-recipe/build.sh @@ -1,8 +1,12 @@ # SPDX-License-Identifier: LGPL-3.0-or-other # Copyright (C) 2021 Contributors to the SLS Detector Package -mkdir build -mkdir install +if [ ! -d "build" ]; then + mkdir build +fi +if [ ! -d "install" ]; then + mkdir install +fi cd build cmake .. \ -DCMAKE_PREFIX_PATH=$CONDA_PREFIX \ diff --git a/conda-recipe/build_pylib.sh b/conda-recipe/build_pylib.sh new file mode 100755 index 0000000000..b2a2fb05f4 --- /dev/null +++ b/conda-recipe/build_pylib.sh @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: LGPL-3.0-or-other +# Copyright (C) 2021 Contributors to the SLS Detector Package + +echo "|<-------- starting python build" + +cd python + +# copy VERSION into slsdet for installation +cp ../VERSION slsdet/VERSION + +# to be used to get project version in meta.yaml +export SLS_DET_VERSION=$(cat python/slsdet/VERSION) + +${PYTHON} setup.py install diff --git a/conda-recepie/conda_build_config.yaml b/conda-recipe/conda_build_config.yaml similarity index 83% rename from conda-recepie/conda_build_config.yaml rename to conda-recipe/conda_build_config.yaml index b1396f187a..0f51da0170 100644 --- a/conda-recepie/conda_build_config.yaml +++ b/conda-recipe/conda_build_config.yaml @@ -4,4 +4,5 @@ python: - 3.10 - 3.11 - 3.12 - + - 3.13 + diff --git a/conda-recepie/copy_ctbgui.sh b/conda-recipe/copy_ctbgui.sh similarity index 100% rename from conda-recepie/copy_ctbgui.sh rename to conda-recipe/copy_ctbgui.sh diff --git a/conda-recepie/copy_gui.sh b/conda-recipe/copy_gui.sh similarity index 100% rename from conda-recepie/copy_gui.sh rename to conda-recipe/copy_gui.sh diff --git a/conda-recepie/copy_lib.sh b/conda-recipe/copy_lib.sh similarity index 100% rename from conda-recepie/copy_lib.sh rename to conda-recipe/copy_lib.sh diff --git a/conda-recepie/copy_moench.sh b/conda-recipe/copy_moench.sh similarity index 100% rename from conda-recepie/copy_moench.sh rename to conda-recipe/copy_moench.sh diff --git a/conda-recepie/meta.yaml b/conda-recipe/meta.yaml similarity index 95% rename from conda-recepie/meta.yaml rename to conda-recipe/meta.yaml index da620c8599..854fac56b9 100755 --- a/conda-recepie/meta.yaml +++ b/conda-recipe/meta.yaml @@ -1,15 +1,19 @@ +{% set version = environ.get('SLS_DET_VERSION', '0.0.0') %} + + package: name: sls_detector_software - version: {{ environ.get('GIT_DESCRIBE_TAG', '') }} + version: "{{ version }}" + source: - - path: .. + path: .. build: number: 0 binary_relocation: True - rpaths: + rpaths: - lib/ requirements: @@ -61,13 +65,11 @@ outputs: - libstdcxx-ng - libgcc-ng - run: - libstdcxx-ng - libgcc-ng - name: slsdet - script: build_pylib.sh requirements: @@ -92,11 +94,11 @@ outputs: - numpy - {{ pin_subpackage('slsdetlib', exact=True) }} - test: imports: - slsdet + - name: slsdetgui script: copy_gui.sh requirements: diff --git a/conda-recepie/run_test.sh b/conda-recipe/run_test.sh similarity index 100% rename from conda-recepie/run_test.sh rename to conda-recipe/run_test.sh diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index a5ba4134d1..e47777e4b5 100755 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -49,7 +49,6 @@ set( PYTHON_FILES slsdet/temperature.py slsdet/lookup.py slsdet/utils.py - ) foreach(FILE ${PYTHON_FILES}) @@ -58,7 +57,6 @@ foreach(FILE ${PYTHON_FILES}) endforeach(FILE ${PYTHON_FILES}) - configure_file( scripts/basic.py ${CMAKE_BINARY_DIR}/basic.py ) @@ -66,6 +64,9 @@ configure_file( scripts/test_virtual.py ${CMAKE_BINARY_DIR}/test_virtual.py ) +configure_file( ${CMAKE_SOURCE_DIR}/VERSION + ${CMAKE_BINARY_DIR}/bin/slsdet/VERSION +) if(SLS_INSTALL_PYTHONEXT) install(TARGETS _slsdet @@ -74,4 +75,5 @@ if(SLS_INSTALL_PYTHONEXT) ) install(FILES ${PYTHON_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/python/slsdet) + install(FILES ../VERSION DESTINATION ${CMAKE_INSTALL_PREFIX}/python/slsdet) endif() \ No newline at end of file diff --git a/python/setup.py b/python/setup.py index 29663e4059..1be1ac809f 100755 --- a/python/setup.py +++ b/python/setup.py @@ -10,14 +10,15 @@ from setuptools import setup, find_packages from pybind11.setup_helpers import Pybind11Extension, build_ext - -import subprocess -def get_git_tag(): +def read_version(): try: - return subprocess.check_output(['git', 'describe', '--tags', '--abbrev=0']).strip().decode('utf-8') - except subprocess.CalledProcessError: - return 'developer' -__version__ = get_git_tag() + version_file = os.path.join(os.path.dirname(__file__), 'slsdet', 'VERSION') + with open(version_file, "r") as f: + return f.read().strip() + except: + raise RuntimeError("VERSION file not found in slsdet package from setup.py.") + +__version__ = read_version() def get_conda_path(): @@ -67,6 +68,9 @@ def get_conda_path(): description='Detector API for SLS Detector Group detectors', long_description='', packages=find_packages(exclude=['contrib', 'docs', 'tests']), + package_data={ + 'slsdet': ['VERSION'], + }, ext_modules=ext_modules, cmdclass={"build_ext": build_ext}, zip_safe=False, diff --git a/python/slsdet/__init__.py b/python/slsdet/__init__.py index 7cd0b383a6..96a734ff91 100755 --- a/python/slsdet/__init__.py +++ b/python/slsdet/__init__.py @@ -22,6 +22,7 @@ from .enums import * from .defines import * + IpAddr = _slsdet.IpAddr MacAddr = _slsdet.MacAddr scanParameters = _slsdet.scanParameters @@ -29,12 +30,14 @@ DurationWrapper = _slsdet.DurationWrapper pedestalParameters = _slsdet.pedestalParameters - -import subprocess -def get_git_tag(): +import os +def read_version(): try: - return subprocess.check_output(['git', 'describe', '--tags', '--abbrev=0']).strip().decode('utf-8') - except subprocess.CalledProcessError: - return 'developer' -__version__ = get_git_tag() + version_file = os.path.join(os.path.dirname(__file__), 'VERSION') + with open(version_file, "r") as f: + return f.read().strip() + except: + raise RuntimeError("VERSION file not found in slsdet package from init.py") + +__version__ = read_version() diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index a8e2ad2e29..b2d24bf1e6 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -137,7 +137,7 @@ void Detector::setVirtualDetectorServers(int numServers, int Detector::getShmId() const { return pimpl->getDetectorIndex(); } -std::string Detector::getPackageVersion() const { return RELEASE; } +std::string Detector::getPackageVersion() const { return SLS_DET_VERSION; } std::string Detector::getClientVersion() const { Version v(APILIB); diff --git a/slsSupportLib/include/sls/versionAPI.h b/slsSupportLib/include/sls/versionAPI.h index 2b2e5898d6..8472aef745 100644 --- a/slsSupportLib/include/sls/versionAPI.h +++ b/slsSupportLib/include/sls/versionAPI.h @@ -1,7 +1,6 @@ // SPDX-License-Identifier: LGPL-3.0-or-other // Copyright (C) 2021 Contributors to the SLS Detector Package /** API versions */ -#define RELEASE "developer" #define APIRECEIVER "developer 0x241014" #define APILIB "developer 0x241021" #define APICTB "developer 0x241107" diff --git a/updateReleaseVersion.sh b/updateReleaseVersion.sh deleted file mode 100644 index 8f38ae191b..0000000000 --- a/updateReleaseVersion.sh +++ /dev/null @@ -1,15 +0,0 @@ -# SPDX-License-Identifier: LGPL-3.0-or-other -# Copyright (C) 2021 Contributors to the SLS Detector Package - -API_FILE=$PWD/slsSupportLib/include/sls/versionAPI.h -CURR_BRANCH=$(cat $API_FILE | grep RELEASE | awk '{print $3}' ) - -# default branch is developer -if [ $# -eq 0 ]; then - declare -a NEW_BRANCH="developer" -else - declare -a NEW_BRANCH=${1} -fi - -# update branch -sed -i s/$CURR_BRANCH/\"$NEW_BRANCH\"/g $API_FILE diff --git a/update_version.py b/update_version.py new file mode 100644 index 0000000000..c074ae5422 --- /dev/null +++ b/update_version.py @@ -0,0 +1,36 @@ +# SPDX-License-Identifier: LGPL-3.0-or-other +# Copyright (C) 2021 Contributors to the SLS Detector 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 re + +def get_version(): + + # Check at least one argument is passed + if len(sys.argv) < 2: + return "0.0.0" + + version = sys.argv[1] + + # Validate that the version argument matches semantic versioning format (X.Y.Z) + if not re.match(r'^\d+\.\d+\.\d+$', version): + print("Error: Version argument must be in semantic versioning format (X.Y.Z)") + sys.exit(1) + + return version + + +def write_version_to_file(version): + with open("VERSION", "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) \ No newline at end of file