Skip to content

Commit 1b1ee8a

Browse files
authored
Update release scripts (#27)
Use bump-my-version, and use uvx for tooling where possible. You still need to have your own links/elinks/lynx and SWIG to regenerate the pycbf sources. Also, fail with a useful message if the repository was not checked out recursively.
1 parent 8f30840 commit 1b1ee8a

File tree

7 files changed

+1001
-184
lines changed

7 files changed

+1001
-184
lines changed

.bumpversion.cfg

Lines changed: 0 additions & 17 deletions
This file was deleted.

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
data/ filter=lfs diff=lfs merge=lfs -text
22
*.cif filter=lfs diff=lfs merge=lfs -text
33
*.cbf filter=lfs diff=lfs merge=lfs -text
4+
uv.lock binary

make_release.sh

Lines changed: 50 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ print_help() {
2121
echo "--no-tag Don't create a tag for the release commit"
2222
echo "--no-edit Don't pause to allow CHANGELOG editing"
2323
echo "--do Actually run. Safety so that no arguments doesnt commit"
24-
# echo "--dry-run, -n Don't do anything"
24+
# echo "--dry-run, -n Don't do anything"
2525
echo
2626
echo "ARG.... Arguments to pass to bump2version"
2727
}
@@ -54,35 +54,35 @@ _positionals=()
5454
while [[ $# -gt 0 ]]; do
5555
_key="$1"
5656
case "$_key" in
57-
-h|--help)
58-
print_help
59-
exit 0
60-
;;
61-
-h*)
62-
print_help
63-
exit 0
64-
;;
65-
-n|--dry-run)
66-
DRY_RUN=true
67-
;;
68-
--allow-nonmain)
69-
ALLOW_NONMAIN=true
70-
;;
71-
--allow-dirty)
72-
ALLOW_DIRTY=true
73-
;;
74-
--no-tag)
75-
NO_TAG=true
76-
;;
77-
--no-edit)
78-
NO_EDIT=true
79-
;;
80-
--do)
81-
DO=true
82-
;;
83-
*)
84-
_positionals+=("$1")
85-
;;
57+
-h | --help)
58+
print_help
59+
exit 0
60+
;;
61+
-h*)
62+
print_help
63+
exit 0
64+
;;
65+
-n | --dry-run)
66+
DRY_RUN=true
67+
;;
68+
--allow-nonmain)
69+
ALLOW_NONMAIN=true
70+
;;
71+
--allow-dirty)
72+
ALLOW_DIRTY=true
73+
;;
74+
--no-tag)
75+
NO_TAG=true
76+
;;
77+
--no-edit)
78+
NO_EDIT=true
79+
;;
80+
--do)
81+
DO=true
82+
;;
83+
*)
84+
_positionals+=("$1")
85+
;;
8686
esac
8787
shift
8888
done
@@ -123,40 +123,31 @@ fi
123123
_start_commit="$(git rev-parse HEAD)"
124124

125125
echo "Starting release process"
126-
bump2version_args=(release --list)
126+
bump2version_args=(bump release)
127127
if [[ $ALLOW_DIRTY == true ]]; then
128128
bump2version_args+=(--allow-dirty)
129129
fi
130-
if ! _output="$(set -x; bump2version "${bump2version_args[@]}")"; then
131-
echo "${R}Error: Bump2version failed"
130+
if ! _output="$(
131+
set -x
132+
uvx bump-my-version "${bump2version_args[@]}"
133+
)"; then
134+
echo "${R}Error: Bumpbump-my-version2version failed"
132135
echo "$_output" $NC
133136
exit 1
134137
fi
135138

136-
new_version="$(echo "$_output" | grep new_version | sed -r s,"^.*=",,)"
139+
read_version() {
140+
uv run --no-project --with=toml python3 -c "import toml, pathlib; print(toml.loads(pathlib.Path('pyproject.toml').read_text())['project']['version'])"
141+
}
142+
143+
new_version="$(read_version)"
137144
echo "New version: $BOLD$M$new_version$NC"
138145

139146
echo "Regenerating SWIG files$W"
140147
silently ./regenerate_pycbf.py
141148

142-
# On M1 mac, there are no wheels for numpy, and it doesn't build.
143-
# Numpy is only a runtime requirement so this is safe
144-
echo "Removing numpy from dependencies"
145-
silently cp pyproject.toml pyproject.toml.bak
146-
silently sed -i'' -e 's/numpy = ">=1.17"/# numpy = ">=1.17"/' pyproject.toml
147-
148-
echo "Installing base environment"
149-
silently poetry install
150-
151-
# Restore back for the build
152-
echo "Restoring original pyproject"
153-
silently mv pyproject.toml.bak pyproject.toml
154-
155-
echo "Re-running build for Cython"
156-
silently poetry build
157-
158149
echo "Running towncrier"
159-
silently towncrier --yes --version="$new_version"
150+
silently uvx towncrier build --yes --version="$new_version"
160151

161152
if [[ $NO_EDIT != true ]]; then
162153
echo "Pausing for CHANGELOG editing"
@@ -168,7 +159,6 @@ fi
168159
echo "Running pre-commit to clean up"
169160
quietly pre-commit run --all || true
170161

171-
172162
echo "${BOLD}Making commit$NC"
173163
quietly git add --update
174164
quietly git commit -n -m "pycbf $new_version"
@@ -181,29 +171,30 @@ fi
181171
echo "$NC"
182172
echo "Advancing to new development release"
183173

184-
if ! _output="$(set -x; bump2version minor --list)"; then
174+
if ! _output="$(
175+
set -x
176+
uvx bump-my-version bump minor
177+
)"; then
185178
echo "${R}Error: Advancing release tag to next development release"
186179
echo "$_output" $NC
187180
exit 1
188181
fi
189182

190-
new_dev_version="$(echo "$_output" | grep new_version | sed -r s,"^.*=",,)"
183+
new_dev_version="$(read_version)"
191184
echo "New development version: $BOLD$M$new_dev_version$NC"
192185

193186
echo "Regenerating SWIG files$W"
194187
silently ./regenerate_pycbf.py
195188

196-
echo "Re-running build for Cython"
197-
silently poetry build
198-
199189
echo "${BOLD}Making new development commit$NC"
200-
( set -x
190+
(
191+
set -x
201192
git add --update
202193
git commit -n -m "Advance to ${new_dev_version} development series"
203194
)
204195
echo
205196
echo "Successfully released $M$new_version$NC and advanced to $M$new_dev_version$NC"
206197
echo
207198
if [[ $NO_TAG != true ]]; then
208-
echo "Please remember to ${B}git push origin main v$new_version$NC"
199+
echo "Please remember to ${B}git push origin --atomic main v$new_version$NC"
209200
fi

newsfragments/27.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Update release scripts to use uvx and bump-my-version.

pyproject.toml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ Repository = "https://github.com/dials/pycbf"
2525

2626
[dependency-groups]
2727
dev = [
28+
"bump-my-version",
2829
"Cython~=3.1.1",
29-
"toml~=0.10.2",
30-
"pytest~=6.2.4",
3130
"dials-data",
32-
"bump2version~=1.0.1",
31+
"pytest",
32+
"toml~=0.10.2",
33+
"towncrier",
3334
]
3435

3536
[tool.ruff]
@@ -46,3 +47,18 @@ filename = "CHANGELOG.rst"
4647
[tool.pytest.ini_options]
4748
addopts = "--regression -ra"
4849
testpaths = ["tests"]
50+
51+
[tool.bumpversion]
52+
parse = "(?P<cbflib_version>\\d+\\.\\d+\\.\\d+)\\.(?P<minor>\\d+)\\.?(?P<release>[a-z]+)?"
53+
current_version = "0.9.6.7.dev"
54+
serialize = ["{cbflib_version}.{minor}.{release}", "{cbflib_version}.{minor}"]
55+
56+
[tool.bumpversion.parts.release]
57+
values = ["dev", "prod"]
58+
optional_value = "prod"
59+
first_value = "dev"
60+
61+
[[tool.bumpversion.files]]
62+
filename = "pyproject.toml"
63+
search = 'version = "{current_version}"'
64+
replace = 'version = "{new_version}"'

setup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
PYCBF_ROOT = Path(__file__).parent
4949
CBFLIB_INCLUDE = PYCBF_ROOT / "cbflib" / "include"
5050

51+
# Check we have checked out recursive
52+
if not any(PYCBF_ROOT.joinpath(x).is_file() for x in CBF_SOURCES):
53+
raise RuntimeError(
54+
"Error: No CBF sources found. Did you check out --recursive? Run 'git submodule update --init'"
55+
)
56+
5157
extensions = [
5258
Extension(
5359
"pycbf._pycbf",

0 commit comments

Comments
 (0)