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
This commit is contained in:
maliakal_d 2024-11-21 10:46:20 +01:00 committed by GitHub
parent c57e835a41
commit d9e8e1c1c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 105 additions and 50 deletions

View File

@ -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})

1
VERSION Normal file
View File

@ -0,0 +1 @@
0.0.0

View File

@ -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

View File

@ -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 \

14
conda-recipe/build_pylib.sh Executable file
View File

@ -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

View File

@ -4,4 +4,5 @@ python:
- 3.10
- 3.11
- 3.12
- 3.13

View File

@ -1,10 +1,14 @@
{% 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
@ -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:

View File

@ -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()

View File

@ -10,14 +10,15 @@ import sys
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 @@ setup(
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,

View File

@ -22,6 +22,7 @@ defs = _slsdet.slsDetectorDefs
from .enums import *
from .defines import *
IpAddr = _slsdet.IpAddr
MacAddr = _slsdet.MacAddr
scanParameters = _slsdet.scanParameters
@ -29,12 +30,14 @@ currentSrcParameters = _slsdet.currentSrcParameters
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()

View File

@ -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);

View File

@ -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"

View File

@ -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

36
update_version.py Normal file
View File

@ -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)