normalized version to PEP 440 specification in update_version.py

This commit is contained in:
mazzol_a 2025-04-24 08:45:18 +02:00 committed by Dhanya Thattil
parent f3be955763
commit 96f39d5028
3 changed files with 10 additions and 10 deletions

View File

@ -1,7 +1,7 @@
source: source:
path: ../.. path: ../..
{% set version = load_file_regex(load_file = 'VERSION', regex_pattern = '(\d+\.\d+\.\d+(?:[\.\-][\.\w\-]+)?)').group(1) %} {% set version = load_file_regex(load_file = 'VERSION', regex_pattern = '(\d+(?:\.\d+)*+(?:[\+\w\.]+))').group(1) %}
package: package:
name: sls_detector_software name: sls_detector_software
version: {{ version }} #2025.3.19 version: {{ version }} #2025.3.19
@ -50,8 +50,6 @@ outputs:
- libgcc-ng - libgcc-ng
- name: slsdetgui - name: slsdetgui
script: copy_gui.sh script: copy_gui.sh
requirements: requirements:

View File

@ -1,7 +1,7 @@
source: source:
path: ../.. path: ../..
{% set version = load_file_regex(load_file = 'VERSION', regex_pattern = '(\d+\.\d+\.\d+(?:[\.\w\-]+)?)').group(1) %} {% set version = load_file_regex(load_file = 'VERSION', regex_pattern = '(\d+(?:\.\d+)*+(?:[\+\w\.]+))').group(1) %}
package: package:
name: slsdet name: slsdet
version: {{ version }} # version: {{ version }} #

View File

@ -7,6 +7,7 @@ Script to update VERSION file with semantic versioning if provided as an argumen
import sys import sys
import re import re
import toml import toml
from packaging.version import Version, InvalidVersion
def get_version(): def get_version():
@ -16,21 +17,22 @@ def get_version():
version = sys.argv[1] version = sys.argv[1]
# Validate that the version argument matches semantic versioning format (X.Y.Z) try:
if not re.match(r'^\d+\.\d+\.\d+(?:[\-\.][\.\w\-]+)?+$', version): v = Version(version) # normalize according to PEP 440 specification
print("Error: Version argument must be in semantic versioning format (X.Y.Z[./-][postfix])") return v
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) sys.exit(1)
return version
def write_version_to_file(version): def write_version_to_file(version):
with open("VERSION", "w") as version_file: with open("VERSION", "w") as version_file:
version_file.write(version) version_file.write(str(version))
print(f"Version {version} written to VERSION file.") print(f"Version {version} written to VERSION file.")
def update_pyproject_toml_file(version): def update_pyproject_toml_file(version):
pyproject = toml.load("pyproject.toml") pyproject = toml.load("pyproject.toml")
pyproject["project"]["version"] = version pyproject["project"]["version"] = str(version)
toml.dump(pyproject, open("pyproject.toml", "w")) #write back toml.dump(pyproject, open("pyproject.toml", "w")) #write back
print(f"Version in pyproject.toml set to {version}") print(f"Version in pyproject.toml set to {version}")