Skip to content

Commit

Permalink
dev: version from file to cmake and python (#1025)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
thattil authored Nov 21, 2024
1 parent c57e835 commit d9e8e1c
Show file tree
Hide file tree
Showing 20 changed files with 105 additions and 50 deletions.
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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})
2 changes: 1 addition & 1 deletion RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,4 @@ This document describes the differences between vx.x.x and vx.0.2
-------

[email protected]
[email protected]
[email protected]
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.0
6 changes: 0 additions & 6 deletions conda-recepie/build_pylib.sh

This file was deleted.

8 changes: 6 additions & 2 deletions conda-recepie/build.sh → conda-recipe/build.sh
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
14 changes: 14 additions & 0 deletions conda-recipe/build_pylib.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ python:
- 3.10
- 3.11
- 3.12

- 3.13

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 8 additions & 6 deletions conda-recepie/meta.yaml → conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -61,13 +65,11 @@ outputs:
- libstdcxx-ng
- libgcc-ng


run:
- libstdcxx-ng
- libgcc-ng

- name: slsdet

script: build_pylib.sh

requirements:
Expand All @@ -92,11 +94,11 @@ outputs:
- numpy
- {{ pin_subpackage('slsdetlib', exact=True) }}


test:
imports:
- slsdet


- name: slsdetgui
script: copy_gui.sh
requirements:
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ set( PYTHON_FILES
slsdet/temperature.py
slsdet/lookup.py
slsdet/utils.py

)

foreach(FILE ${PYTHON_FILES})
Expand All @@ -58,14 +57,16 @@ foreach(FILE ${PYTHON_FILES})

endforeach(FILE ${PYTHON_FILES})


configure_file( scripts/basic.py
${CMAKE_BINARY_DIR}/basic.py
)
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
Expand All @@ -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()
18 changes: 11 additions & 7 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 10 additions & 7 deletions python/slsdet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,22 @@
from .enums import *
from .defines import *


IpAddr = _slsdet.IpAddr
MacAddr = _slsdet.MacAddr
scanParameters = _slsdet.scanParameters
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()

2 changes: 1 addition & 1 deletion slsDetectorSoftware/src/Detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion slsSupportLib/include/sls/versionAPI.h
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
15 changes: 0 additions & 15 deletions updateReleaseVersion.sh

This file was deleted.

36 changes: 36 additions & 0 deletions update_version.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit d9e8e1c

Please sign in to comment.