diff --git a/.github/ISSUE_TEMPLATE/release.md b/.github/ISSUE_TEMPLATE/release.md index daa36d476..104c67119 100644 --- a/.github/ISSUE_TEMPLATE/release.md +++ b/.github/ISSUE_TEMPLATE/release.md @@ -10,7 +10,13 @@ Release check-list: If it was not already done: - [ ] Choose the version number, e.g. `vX.Y.Z` (can be `vX.Y.Zrc?` for Release Candidates) following semantic versioning: https://semver.org/ -- [ ] Update the version in pyproject.toml to `X.Y.Z` (or `X.Y.Zrc?`) +- [ ] Update the project version to `X.Y.Z` (or `X.Y.Zrc?`) by running: + +```bash +VERSION=X.Y.Z make set_version +# or +VERSION=X.Y.Zrc? make set_version +``` Then: - [ ] For non RC releases: check the release milestone issues, cut out what can't be completed in time and change the milestones for these issues @@ -26,6 +32,12 @@ This is the release markdown template you should copy and update: To continue the release cycle: - [ ] Choose the version number for next release, e.g. `vA.B.C` (can be `vA.B.Crc?` for Release Candidates) following semantic versioning: https://semver.org/ -- [ ] Update the version in pyproject.toml to `A.B.C` (or `A.B.Crc?`) +- [ ] Update the project version to `A.B.C` (or `A.B.Crc?`) by running: + +```bash +VERSION=A.B.C make set_version +# or +VERSION=A.B.Crc? make set_version +``` All done! diff --git a/Makefile b/Makefile index 6569e25c7..478c5ad39 100644 --- a/Makefile +++ b/Makefile @@ -71,7 +71,9 @@ pcc: --no-print-directory pcc_internal .PHONY: pcc -pcc_internal: check_python_format check_finalize_nb python_linting mypy_ci pydocstyle shell_lint +PCC_DEPS := check_python_format check_finalize_nb python_linting mypy_ci pydocstyle shell_lint +PCC_DEPS += check_version_coherence +pcc_internal: $(PCC_DEPS) .PHONY: pcc_internal pytest: @@ -214,3 +216,23 @@ shell_lint: find \( -path "./.venv" -o -path "./.docker_venv" \) -prune -o -type f -name "*.sh" -print | \ xargs shellcheck .PHONY: shell_lint + +set_version: + @if [[ "$$VERSION" == "" ]]; then \ + echo "VERSION env variable is empty. Please set to desired version."; \ + exit 1; \ + fi; + ./script/make_utils/set_version.sh --version "$${VERSION}" --src-dir "$(SRC_DIR)" +.PHONY: set_version + +check_version_coherence: + @SRC_VER=$$(poetry run python -c "from $(SRC_DIR) import __version__; print(__version__);");\ + PROJECT_VER=($$(poetry version)); \ + PROJECT_VER="$${PROJECT_VER[1]}"; \ + echo "Source version: $${SRC_VER}"; \ + echo "Project version: $${PROJECT_VER}"; \ + if [[ "$${SRC_VER}" != "$${PROJECT_VER}" ]]; then \ + echo "Version mismatch between source and pyproject.toml re-run make set_version"; \ + exit 1; \ + fi +.PHONY: check_version_coherence diff --git a/concrete/__init__.py b/concrete/__init__.py index dd0d3d4c0..5200aadd1 100644 --- a/concrete/__init__.py +++ b/concrete/__init__.py @@ -1,2 +1,3 @@ """Package top import.""" from . import common, numpy +from .version import __version__ diff --git a/concrete/version.py b/concrete/version.py new file mode 100644 index 000000000..c194a9e64 --- /dev/null +++ b/concrete/version.py @@ -0,0 +1,4 @@ +"""Package version module.""" +# Auto-generated by "make set_version" do not modify + +__version__ = "0.2.0rc1" diff --git a/script/make_utils/set_version.sh b/script/make_utils/set_version.sh new file mode 100755 index 000000000..0c75efa91 --- /dev/null +++ b/script/make_utils/set_version.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash + +VERSION_TO_SET= +SRC_DIR= + +while [ -n "$1" ] +do + case "$1" in + "--version" ) + shift + VERSION_TO_SET="$1" + ;; + + "--src-dir" ) + shift + SRC_DIR="$1" + ;; + + *) + echo "Unknown param : $1" + exit 1 + ;; + esac + shift +done + +if [[ "${VERSION_TO_SET}" == "" ]]; then + echo "--version is required. Aborting" + exit 1 +fi + +if [[ "${SRC_DIR}" == "" ]]; then + echo "--src-dir is required. Aborting" + exit 1 +fi + +rx='^(v)?([0-9]+\.){2}[0-9]+(rc[0-9]+)?$' + +if [[ ! "${VERSION_TO_SET}" =~ $rx ]]; then + echo "ERROR: Unable to validate version: '${VERSION_TO_SET}'" + exit 1 +fi + +echo "INFO: Version ${VERSION_TO_SET}" + +VERSION_TO_SET="${VERSION_TO_SET/v/}" +echo "${VERSION_TO_SET}" + +poetry version "${VERSION_TO_SET}" + +VERSION_FILE="${SRC_DIR}/version.py" + +rm "${VERSION_FILE}" + +{ + echo '"""Package version module."""' + echo '# Auto-generated by "make set_version" do not modify' + echo '' + echo "__version__ = \"${VERSION_TO_SET}\"" +} >> "${VERSION_FILE}"