Repository: cryotools/cosipy (language: python)

Issue:
feat: add script to bump semantic versioning, makefile
Adds bash script to bump build version, and a make command ``make bump-version``.


Discussion / hints:

Fix patch:
diff --git a/Makefile b/Makefile
index dea13aa..65c707b 100644
--- a/Makefile
+++ b/Makefile
@@ -121,9 +121,8 @@ build:	--install-build-deps	## Build COSIPY package
 		$(PYTHON) -m build
 		@twine check dist/*
 
-# .PHONY
-# bump-version:
-# 		@grep -Po '\bversion\s*=\s*"\K.*?(?=")' pyproject.toml
+bump-version:
+		@bash bump_version.sh
 
 .PHONY:
 upload-pypi:	# Private: upload COSIPY package
diff --git a/bump_version.sh b/bump_version.sh
new file mode 100644
index 0000000..fae8c95
--- /dev/null
+++ b/bump_version.sh
@@ -0,0 +1,102 @@
+#!/bin/bash
+# 2024 Nicolas Gampierakis.
+
+# Applies semantic versioning across project
+
+DIRECTORY=""
+VERBOSE=0
+BRANCH=""
+
+DisplayHelp() {
+    intro_tag="$(basename "$0") [-h] -- semantic versioning tool"
+    options="OPTIONS
+    -h, --help              Display help.
+    -d, --directory [path]  Path to target directory, relative to current
+                                working directory.
+    -v, --verbose           Verbosity flag.
+    "
+    printf "\n%s\n\n%s\n" "$intro_tag" "$options"
+}
+
+#######################################
+# Get project version number
+#
+# Arguments:
+#   Keyword for version number in file.
+#   File path.
+#######################################
+get_version_number() {
+    match_string="${1}"
+    file_name="${2}"
+    version_number=$(grep -oP '\b'"${match_string}"'\s*=\s*"\K.*?(?=")' "${file_name}")
+}
+
+#######################################
+# Set project version number
+#
+# Arguments:
+#   Project root directory.
+#######################################
+set_version_number() {
+    toml_file="${1}pyproject.toml"
+    docs_file="${1}docs/source/conf.py"
+    version_number=""
+    get_version_number "version" "${toml_file}"
+    current_py_version="${version_number}"
+    get_version_number "release" "${docs_file}"
+    current_docs_version="${version_number}"
+    current_version="${current_py_version}"
+
+    new_version=${BRANCH#"release-"}
+    if [ "${new_version}" != "${current_version}" ]; then
+        printf "%s\n" "Current branch: ${BRANCH}" >&2
+        printf "%s\n" "Previous version number: ${current_version}" >&2
+        printf "%s\n" "New version number: ${new_version}" >&2
+        sed -i "s/${current_py_version}/${new_version}/g" "${toml_file}"
+        sed -i "s/${current_docs_version}/${new_version}/g" "${docs_file}"
+        git add "${toml_file}" "${docs_file}"
+        git commit -m "build: bump version number to ${new_version}"
+    else
+        printf "%s\n" "Current and new version numbers are identical: ${current_version}" >&2
+    fi
+}
+
+ARGS=$(getopt -o "hd:v" --long "help,directory:,verbose" -- "$@") || exit
+eval "set -- $ARGS"
+while true; do
+    case $1 in
+    -h | --help)
+        DisplayHelp
+        exit 0
+        ;;
+    -d | --directory)
+        DIRECTORY=$2
+        shift 2
+        ;;
+    -v | --verbose)
+        ((VERBOSE++))
+        shift
+        ;;
+    --)
+        shift
+        break
+        ;;
+    *) exit 1 ;; # error
+    esac
+done
+remaining=("$@")
+
+if [[ ! $DIRECTORY ]]; then
+    DIRECTORY="${PWD}/"
+else
+    DIRECTORY="${PWD}/${DIRECTORY}"
+fi
+readonly DIRECTORY
+
+BRANCH="$(git rev-parse --abbrev-ref HEAD)"
+if [[ "$BRANCH" != *"release-"* ]]; then
+    echo "Please switch to a release branch."
+    exit 1
+fi
+
+set_version_number "${DIRECTORY}"
diff --git a/docs/source/conf.py b/docs/source/conf.py
index 2534b28..b5e8b73 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -39,7 +39,7 @@
 project = "COSIPY"
 copyright = f"2019-{date.today().year}, COSIPY Contributors"
 author = "COSIPY Contributors"
-release = "2.0"
+release = "2.0.2"
 
 # -- General configuration ---------------------------------------------------
 
diff --git a/docs/source/utilities/cosipy.utilities.setup_cosipy.setup_cosipy.get_user_confirmation.rst b/docs/source/utilities/cosipy.utilities.setup_cosipy.setup_cosipy.get_user_confirmation.rst
new file mode 100644
index 0000000..4aaaf54
--- /dev/null
+++ b/docs/source/utilities/cosipy.utilities.setup_cosipy.setup_cosipy.get_user_confirmation.rst
@@ -0,0 +1,6 @@
+get\_user\_confirmation
+=======================
+
+.. currentmodule:: cosipy.utilities.setup_cosipy.setup_cosipy
+
+.. autofunction:: get_user_confirmation
\ No newline at end of file
diff --git a/docs/source/utilities/cosipy.utilities.setup_cosipy.setup_cosipy.rst b/docs/source/utilities/cosipy.utilities.setup_cosipy.setup_cosipy.rst
index 02d9905..0101a7e 100644
--- a/docs/source/utilities/cosipy.utilities.setup_cosipy.setup_cosipy.rst
+++ b/docs/source/utilities/cosipy.utilities.setup_cosipy.setup_cosipy.rst
@@ -1,4 +1,4 @@
-setup\_cosipy
+﻿setup\_cosipy
 =============
 
 .. currentmodule:: cosipy.utilities.setup_cosipy
@@ -21,8 +21,8 @@ setup\_cosipy
       copy_file_to_target
       get_sample_directory
       get_user_arguments
+      get_user_confirmation
       main
-      strtobool
    
    
 
diff --git a/docs/source/utilities/cosipy.utilities.setup_cosipy.setup_cosipy.strtobool.rst b/docs/source/utilities/cosipy.utilities.setup_cosipy.setup_cosipy.strtobool.rst
deleted file mode 100644
index 19094f5..0000000
--- a/docs/source/utilities/cosipy.utilities.setup_cosipy.setup_cosipy.strtobool.rst
+++ /dev/null
@@ -1,6 +0,0 @@
-strtobool
-=========
-
-.. currentmodule:: cosipy.utilities.setup_cosipy.setup_cosipy
-
-.. autofunction:: strtobool
\ No newline at end of file
diff --git a/pyproject.toml b/pyproject.toml
index 7f3ab1d..cbbacd7 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
 
 [project]
 name = "cosipymodel"
-version = "2.0.1"
+version = "2.0.2"
 authors = [
     { name = "COSIPY Contributors", email = "" },
 ]


Test patch:
diff --git a/cosipy/tests/conftest.py b/cosipy/tests/conftest.py
index 9a3dcf8..365450d 100644
--- a/cosipy/tests/conftest.py
+++ b/cosipy/tests/conftest.py
@@ -74,11 +74,11 @@ def conftest_hide_plot():
 
 
 @pytest.fixture(name="conftest_rng_seed", scope="function", autouse=False)
-def fixture_conftest_rng_seed() -> np.random.Generator:
+def fixture_conftest_rng_seed():
     """Set seed for random number generator to 444.
 
     Returns:
-        Random number generator with seed=444.
+        np.random.Generator: Random number generator with seed=444.
     """
 
     random_generator = np.random.default_rng(seed=444)