Skip to content

Commit 9e80907

Browse files
committed
Use a valid Python version for the package
Entirely drop the approach of running Maven's string-filters and rather parse the package version from 'pom.xml' and postprocess it in case it is a SNAPSHOT, using the distance to the last release tag.
1 parent 617978b commit 9e80907

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

poetry-build.sh

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,44 @@ if [ -n "$STATUS" ]; then
1919
exit 1
2020
fi
2121

22-
# clean up old poetry artifacts:
22+
### clean up old poetry artifacts:
2323
rm -rf dist/
24-
# clean up old maven artifacts:
25-
rm -rf target/
26-
# clean up potential leftovers from previous runs of this script:
24+
### clean up potential leftovers from previous runs of this script:
2725
rm -rf sjlogging/
2826

29-
# call maven to perform the "string-filtering" which will substitute the version
30-
# placeholder in __init__.py by the (maven-derived) version string:
31-
mvn process-resources
32-
33-
# move the string-filtered source tree to the project root, so poetry will pick
34-
# it up automatically from there (without explicit configuration):
35-
mv target/classes/sjlogging/ .
36-
37-
# let poetry build the wheel (and tar.gz)
27+
# move the source tree to the project root, so poetry will pick it up
28+
# automatically from there (without explicit configuration):
29+
mv src/main/resources/sjlogging .
30+
31+
### parse the version from 'pom.xml':
32+
PACKAGE_VERSION=$(xmlstarlet sel --template -m _:project -v _:version pom.xml)
33+
34+
### make sure to have a valid Python package version:
35+
case $PACKAGE_VERSION in
36+
*-SNAPSHOT*)
37+
echo "POM version [$PACKAGE_VERSION] is a snapshot!"
38+
PACKAGE_VERSION=${PACKAGE_VERSION/-SNAPSHOT/}
39+
### calculate the distance to the last release tag:
40+
LAST_TAG=$(git tag --list 'jython-scijava-logging-*' | sort | tail -n1)
41+
# echo "Last git tag: '$LAST_TAG'"
42+
COMMITS_SINCE=$(git rev-list "${LAST_TAG}..HEAD" | wc -l)
43+
# echo "Nr of commits since last tag: $COMMITS_SINCE"
44+
HEAD_ID=$(git rev-parse --short HEAD)
45+
# echo "HEAD commit hash: $HEAD_ID"
46+
PACKAGE_VERSION="${PACKAGE_VERSION}.dev${COMMITS_SINCE}+${HEAD_ID}"
47+
;;
48+
esac
49+
50+
echo "Using package version: [$PACKAGE_VERSION]"
51+
52+
### put the version into the project file and the package source:
53+
sed -i "s/\${project.version}/${PACKAGE_VERSION}/" pyproject.toml
54+
sed -i "s/\${project.version}/${PACKAGE_VERSION}/" sjlogging/__init__.py
55+
56+
### let poetry build wheel and tar.gz:
3857
poetry build -vv
3958

40-
# remove the string-filtered source tree:
59+
### clean up the moved source tree and restore the previous state:
4160
rm -rf sjlogging/
61+
git restore pyproject.toml
62+
git restore src/main/resources/sjlogging/

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors = ["Niko Ehrenfeuchter <nikolaus.ehrenfeuchter@unibas.ch>"]
66
description = "Jython package for using SciJava's LogService for logging."
77
name = "sjlogging"
88
readme = "README.md"
9-
version = "0.5.2"
9+
version = '${project.version}'
1010

1111
[tool.poetry.dependencies]
1212
python = ">=2.7"

0 commit comments

Comments
 (0)