chore: add __version__ and automated tools to update it

- also add a checker to verify that versions are in sync
This commit is contained in:
Arthur Meyre
2021-09-30 16:21:15 +02:00
parent edcbc0cffd
commit 6fc6991839
5 changed files with 102 additions and 3 deletions

View File

@@ -10,7 +10,13 @@ Release check-list:
<!-- Note that some of these steps will be automated in the future -->
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!

View File

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

View File

@@ -1,2 +1,3 @@
"""Package top import."""
from . import common, numpy
from .version import __version__

4
concrete/version.py Normal file
View File

@@ -0,0 +1,4 @@
"""Package version module."""
# Auto-generated by "make set_version" do not modify
__version__ = "0.2.0rc1"

View File

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