From 6fb231828ea845e7f0b80e52280f3efb98a25545 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Mon, 11 Sep 2023 13:55:56 -0400 Subject: [PATCH 01/18] Reference HEAD in Makefile (more portable than head) This fixes "fatal: ambiguous argument 'head'", which occurs on some systems, inclding GNU/Linux systems, with "git rev-parse head". --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 389337d08..f3a5d3749 100644 --- a/Makefile +++ b/Makefile @@ -9,9 +9,9 @@ clean: release: clean # Check if latest tag is the current head we're releasing echo "Latest tag = $$(git tag | sort -nr | head -n1)" - echo "HEAD SHA = $$(git rev-parse head)" + echo "HEAD SHA = $$(git rev-parse HEAD)" echo "Latest tag SHA = $$(git tag | sort -nr | head -n1 | xargs git rev-parse)" - @test "$$(git rev-parse head)" = "$$(git tag | sort -nr | head -n1 | xargs git rev-parse)" + @test "$$(git rev-parse HEAD)" = "$$(git tag | sort -nr | head -n1 | xargs git rev-parse)" make force_release force_release: clean From 335d03b174569b4bc840e2020886a5f65adc56b7 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Mon, 11 Sep 2023 14:54:04 -0400 Subject: [PATCH 02/18] Have Makefile use git tag to sort the tags --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f3a5d3749..592f5658d 100644 --- a/Makefile +++ b/Makefile @@ -8,10 +8,10 @@ clean: release: clean # Check if latest tag is the current head we're releasing - echo "Latest tag = $$(git tag | sort -nr | head -n1)" + echo "Latest tag = $$(git tag -l '[0-9]*' --sort=-v:refname | head -n1)" echo "HEAD SHA = $$(git rev-parse HEAD)" - echo "Latest tag SHA = $$(git tag | sort -nr | head -n1 | xargs git rev-parse)" - @test "$$(git rev-parse HEAD)" = "$$(git tag | sort -nr | head -n1 | xargs git rev-parse)" + echo "Latest tag SHA = $$(git tag -l '[0-9]*' --sort=-v:refname | head -n1 | xargs git rev-parse)" + @test "$$(git rev-parse HEAD)" = "$$(git tag -l '[0-9]*' --sort=-v:refname | head -n1 | xargs git rev-parse)" make force_release force_release: clean From b1c61d933d36a8e7fb6fb4109d2b07bd06bfbf32 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Wed, 13 Sep 2023 05:44:16 -0400 Subject: [PATCH 03/18] Make "git tag" sort our SemVer-ish tags correctly This sorts numerically for each of major, minor, and patch, rather than, e.g., rating 2.1.15 as a higher version than 2.1.2. It also rates things like X-beta and X-rc as lower versions than X, but X-patched (not SemVer, but present in this project) as higher versions than X. --- Makefile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 592f5658d..4e1927a9c 100644 --- a/Makefile +++ b/Makefile @@ -8,10 +8,14 @@ clean: release: clean # Check if latest tag is the current head we're releasing - echo "Latest tag = $$(git tag -l '[0-9]*' --sort=-v:refname | head -n1)" - echo "HEAD SHA = $$(git rev-parse HEAD)" - echo "Latest tag SHA = $$(git tag -l '[0-9]*' --sort=-v:refname | head -n1 | xargs git rev-parse)" - @test "$$(git rev-parse HEAD)" = "$$(git tag -l '[0-9]*' --sort=-v:refname | head -n1 | xargs git rev-parse)" + @config_opts="$$(printf ' -c versionsort.suffix=-%s' alpha beta pre rc RC)" && \ + latest_tag=$$(git $$config_opts tag -l '[0-9]*' --sort=-v:refname | head -n1) && \ + head_sha=$$(git rev-parse HEAD) latest_tag_sha=$$(git rev-parse "$$latest_tag") && \ + printf '%-14s = %s\n' 'Latest tag' "$$latest_tag" \ + 'HEAD SHA' "$$head_sha" \ + 'Latest tag SHA' "$$latest_tag_sha" && \ + test "$$head_sha" = "$$latest_tag_sha" + make force_release force_release: clean From cc202cc0fcbbb365e86a8dbc99bb5d6381619671 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Wed, 13 Sep 2023 06:13:44 -0400 Subject: [PATCH 04/18] Improve when and how Makefile suggests virtual env The avoids showing the message when the build command was already run in a virtual environment. It also keeps the command failing, so the subsequent twine command is not attempted. (Just adding "|| echo ..." caused the command to succeed, because "echo ..." itself succeeds except in the rare case it cannot write to standard output.) --- Makefile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4e1927a9c..1c2c03a88 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,13 @@ release: clean force_release: clean # IF we're in a virtual environment, add build tools test -z "$$VIRTUAL_ENV" || pip install -U build twine - python3 -m build --sdist --wheel || echo "Use a virtual-env with 'python -m venv env && source env/bin/activate' instead" + + # Build the sdist and wheel that will be uploaded to PyPI. + python3 -m build --sdist --wheel || \ + test -z "$$VIRTUAL_ENV" && \ + echo "Use a virtual-env with 'python -m venv env && source env/bin/activate' instead" && \ + false + + # Upload to PyPI and push the tag. twine upload dist/* git push --tags origin main From b54c34647bf6281d7f5f757d9850484bdb25f800 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Wed, 13 Sep 2023 06:33:10 -0400 Subject: [PATCH 05/18] Use "python" in the virtual env, "python3" outside This changes the build command to run with "python" when in a virtual environment, since all virtual environments support this even when "python" outside it is absent or refers to the wrong version. On Windows, virtual environments don't contain a python3 command, but a global python3 command may be present, so the errors are confusing. This fixes that by avoiding such errors altogether. --- Makefile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 1c2c03a88..cd5eba36b 100644 --- a/Makefile +++ b/Makefile @@ -23,10 +23,13 @@ force_release: clean test -z "$$VIRTUAL_ENV" || pip install -U build twine # Build the sdist and wheel that will be uploaded to PyPI. - python3 -m build --sdist --wheel || \ - test -z "$$VIRTUAL_ENV" && \ + if test -n "$$VIRTUAL_ENV"; then \ + python -m build --sdist --wheel; \ + else \ + python3 -m build --sdist --wheel || \ echo "Use a virtual-env with 'python -m venv env && source env/bin/activate' instead" && \ - false + false; \ + fi # Upload to PyPI and push the tag. twine upload dist/* From ae9405a339e7b01fb539e1837e4c3f450250cfb7 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Wed, 13 Sep 2023 06:41:03 -0400 Subject: [PATCH 06/18] LF line endings for scripts that may need them This fixes how init-tests-after-clone.sh appears in .gitattributes so it gets LF (Unix-style) line endings on all systems as intended, and adds Makefile to be treated the same way. --- .gitattributes | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index 6d2618f2f..739b2be29 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,3 @@ test/fixtures/* eol=lf -init-tests-after-clone.sh +init-tests-after-clone.sh eol=lf +Makefile eol=lf From f5da163bed2ababec006c0806187070341cc390e Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Wed, 13 Sep 2023 07:45:26 -0400 Subject: [PATCH 07/18] Have "make release" check other release preconditions As documented in the release instructions in README.md. --- Makefile | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index cd5eba36b..52d080788 100644 --- a/Makefile +++ b/Makefile @@ -7,13 +7,29 @@ clean: rm -rf build/ dist/ .eggs/ .tox/ release: clean - # Check if latest tag is the current head we're releasing - @config_opts="$$(printf ' -c versionsort.suffix=-%s' alpha beta pre rc RC)" && \ + # Check that VERSION and changes.rst exist and have no uncommitted changes + test -f VERSION + test -f doc/source/changes.rst + git status -s VERSION doc/source/changes.rst + @test -z "$$(git status -s VERSION doc/source/changes.rst)" + + # Check that ALL changes are commited (can comment out if absolutely necessary) + git status -s + @test -z "$$(git status -s)" + + # Check that latest tag matches version and is the current head we're releasing + @version_file="$$(cat VERSION)" && \ + changes_file="$$(awk '/^[0-9]/ {print $$0; exit}' doc/source/changes.rst)" && \ + config_opts="$$(printf ' -c versionsort.suffix=-%s' alpha beta pre rc RC)" && \ latest_tag=$$(git $$config_opts tag -l '[0-9]*' --sort=-v:refname | head -n1) && \ head_sha=$$(git rev-parse HEAD) latest_tag_sha=$$(git rev-parse "$$latest_tag") && \ - printf '%-14s = %s\n' 'Latest tag' "$$latest_tag" \ + printf '%-14s = %s\n' 'VERSION file' "$$version_file" \ + 'changes.rst' "$$changes_file" \ + 'Latest tag' "$$latest_tag" \ 'HEAD SHA' "$$head_sha" \ 'Latest tag SHA' "$$latest_tag_sha" && \ + test "$$version_file" = "$$changes_file" && \ + test "$$latest_tag" = "$$version_file" && \ test "$$head_sha" = "$$latest_tag_sha" make force_release From 5cf7f9777bc3f5bb92c57116071fd2bed3ac0b70 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Wed, 13 Sep 2023 09:05:36 -0400 Subject: [PATCH 08/18] Fix non-venv branch always failing cc202cc put an end to the problem where, when run outside a virtual environment, it would always "succeed", because all "|| echo ..." required to succeed was for the echo command reporting the error to succeed. Unfortunately, that commit created the oppposite problem, causing that case to always fail! This commit fixes it, so it fails when there is an error, and succeeds when there is no error. --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 52d080788..fdefb0439 100644 --- a/Makefile +++ b/Makefile @@ -43,8 +43,7 @@ force_release: clean python -m build --sdist --wheel; \ else \ python3 -m build --sdist --wheel || \ - echo "Use a virtual-env with 'python -m venv env && source env/bin/activate' instead" && \ - false; \ + { echo "Use a virtual-env with 'python -m venv env && source env/bin/activate' instead" && false; }; \ fi # Upload to PyPI and push the tag. From 6495d84142b60ba81a5b4268a0dfc0785c22d60a Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Thu, 14 Sep 2023 04:24:17 -0400 Subject: [PATCH 09/18] Extract checks from release target to script This extracts the check logic from the release target in Makefile to a new script, check-version.sh. The code is also modified, mainly to account for different ways output is displayed and errors are reported and treated in a Makefile versus a standalone shell script. (The .sh suffix is for consistency with the naming of init-tests-after-clone.sh and is *not* intended to suggest sourcing the script; this script should be executed, not sourced.) --- .gitattributes | 1 + Makefile | 26 +------------------------- check-version.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 25 deletions(-) create mode 100755 check-version.sh diff --git a/.gitattributes b/.gitattributes index 739b2be29..eb503040b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,4 @@ test/fixtures/* eol=lf init-tests-after-clone.sh eol=lf +check-version.sh eol=lf Makefile eol=lf diff --git a/Makefile b/Makefile index fdefb0439..d11dd4de9 100644 --- a/Makefile +++ b/Makefile @@ -7,31 +7,7 @@ clean: rm -rf build/ dist/ .eggs/ .tox/ release: clean - # Check that VERSION and changes.rst exist and have no uncommitted changes - test -f VERSION - test -f doc/source/changes.rst - git status -s VERSION doc/source/changes.rst - @test -z "$$(git status -s VERSION doc/source/changes.rst)" - - # Check that ALL changes are commited (can comment out if absolutely necessary) - git status -s - @test -z "$$(git status -s)" - - # Check that latest tag matches version and is the current head we're releasing - @version_file="$$(cat VERSION)" && \ - changes_file="$$(awk '/^[0-9]/ {print $$0; exit}' doc/source/changes.rst)" && \ - config_opts="$$(printf ' -c versionsort.suffix=-%s' alpha beta pre rc RC)" && \ - latest_tag=$$(git $$config_opts tag -l '[0-9]*' --sort=-v:refname | head -n1) && \ - head_sha=$$(git rev-parse HEAD) latest_tag_sha=$$(git rev-parse "$$latest_tag") && \ - printf '%-14s = %s\n' 'VERSION file' "$$version_file" \ - 'changes.rst' "$$changes_file" \ - 'Latest tag' "$$latest_tag" \ - 'HEAD SHA' "$$head_sha" \ - 'Latest tag SHA' "$$latest_tag_sha" && \ - test "$$version_file" = "$$changes_file" && \ - test "$$latest_tag" = "$$version_file" && \ - test "$$head_sha" = "$$latest_tag_sha" - + ./check-version.sh make force_release force_release: clean diff --git a/check-version.sh b/check-version.sh new file mode 100755 index 000000000..5d3157033 --- /dev/null +++ b/check-version.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# +# This script checks if we appear ready to build and publish a new release. +# See the release instructions in README.md for the steps to make this pass. + +set -eEfuo pipefail +trap 'printf "%s: Check failed. Stopping.\n" "$0" >&2' ERR + +readonly version_path='VERSION' +readonly changes_path='doc/source/changes.rst' + +printf 'Checking current directory.\n' +test "$(cd -- "$(dirname -- "$0")" && pwd)" = "$(pwd)" # Ugly, but portable. + +printf 'Checking that %s and %s exist and have no committed changes.\n' \ + "$version_path" "$changes_path" +test -f "$version_path" +test -f "$changes_path" +git status -s -- "$version_path" "$changes_path" +test -z "$(git status -s -- "$version_path" "$changes_path")" + +# This section can be commented out, if absolutely necessary. +printf 'Checking that ALL changes are committed.\n' +git status -s +test -z "$(git status -s)" + +printf 'Gathering current version, latest tag, and current HEAD commit info.\n' +version_version="$(cat "$version_path")" +changes_version="$(awk '/^[0-9]/ {print $0; exit}' "$changes_path")" +config_opts="$(printf ' -c versionsort.suffix=-%s' alpha beta pre rc RC)" +latest_tag="$(git $config_opts tag -l '[0-9]*' --sort=-v:refname | head -n1)" +head_sha="$(git rev-parse HEAD)" +latest_tag_sha="$(git rev-parse "$latest_tag")" + +# Display a table of all the current version, tag, and HEAD commit information. +printf '%-14s = %s\n' 'VERSION file' "$version_version" \ + 'changes.rst' "$changes_version" \ + 'Latest tag' "$latest_tag" \ + 'HEAD SHA' "$head_sha" \ + 'Latest tag SHA' "$latest_tag_sha" + +# Check that latest tag matches version and is the current HEAD we're releasing +test "$version_version" = "$changes_version" +test "$latest_tag" = "$version_version" +test "$head_sha" = "$latest_tag_sha" +printf 'OK, everything looks good.\n' From 4b1c56409e905b852e3c93de142e109b147eee5e Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Thu, 14 Sep 2023 05:38:24 -0400 Subject: [PATCH 10/18] Extract build from force_release target to script This moves the conditional build dependency installation logic and build logic from the force_release Makefile target to a shell script build-release.sh, which force_release calls. The code is changed to clean it up, and also to account for differences between how output is displayed and errors reported in Makefiles and shell scripts. (As in check-version.sh, the .sh suffix does not signify anything about how the script is to be used: like the other shell scripts in the project, this should be executed, no sourced.) --- .gitattributes | 3 ++- Makefile | 13 +------------ build-release.sh | 22 ++++++++++++++++++++++ check-version.sh | 3 ++- 4 files changed, 27 insertions(+), 14 deletions(-) create mode 100755 build-release.sh diff --git a/.gitattributes b/.gitattributes index eb503040b..a66dc90ca 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,5 @@ test/fixtures/* eol=lf init-tests-after-clone.sh eol=lf -check-version.sh eol=lf Makefile eol=lf +check-version.sh eol=lf +build-release.sh eol=lf diff --git a/Makefile b/Makefile index d11dd4de9..38090244c 100644 --- a/Makefile +++ b/Makefile @@ -11,17 +11,6 @@ release: clean make force_release force_release: clean - # IF we're in a virtual environment, add build tools - test -z "$$VIRTUAL_ENV" || pip install -U build twine - - # Build the sdist and wheel that will be uploaded to PyPI. - if test -n "$$VIRTUAL_ENV"; then \ - python -m build --sdist --wheel; \ - else \ - python3 -m build --sdist --wheel || \ - { echo "Use a virtual-env with 'python -m venv env && source env/bin/activate' instead" && false; }; \ - fi - - # Upload to PyPI and push the tag. + ./build-release.sh twine upload dist/* git push --tags origin main diff --git a/build-release.sh b/build-release.sh new file mode 100755 index 000000000..ebb45e062 --- /dev/null +++ b/build-release.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# +# This script builds a release. If run in a venv, it auto-installs its tools. +# You may want to run "make release" instead of running this script directly. + +set -eEu + +if test -n "${VIRTUAL_ENV:-}"; then + deps=(build twine) # Install twine along with build, as we need it later. + printf 'Virtual environment detected. Adding packages: %s\n' "${deps[*]}" + pip install -U "${deps[@]}" + printf 'Starting the build.\n' + python -m build --sdist --wheel +else + suggest_venv() { + venv_cmd='python -m venv env && source env/bin/activate' + printf "Use a virtual-env with '%s' instead.\n" "$venv_cmd" + } + trap suggest_venv ERR # This keeps the original exit (error) code. + printf 'Starting the build.\n' + python3 -m build --sdist --wheel # Outside a venv, use python3. +fi diff --git a/check-version.sh b/check-version.sh index 5d3157033..802492d93 100755 --- a/check-version.sh +++ b/check-version.sh @@ -1,7 +1,8 @@ #!/usr/bin/env bash # -# This script checks if we appear ready to build and publish a new release. +# This script checks if we are in a consistent state to build a new release. # See the release instructions in README.md for the steps to make this pass. +# You may want to run "make release" instead of running this script directly. set -eEfuo pipefail trap 'printf "%s: Check failed. Stopping.\n" "$0" >&2' ERR From 729372f6f87639f0c4d8211ee7d173100117a257 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Thu, 14 Sep 2023 07:16:08 -0400 Subject: [PATCH 11/18] Prevent buggy interaction between MinGW and WSL This changes the hashbangs in Makefile helper scripts to be static. Often, "#!/usr/bin/env bash" is a better hashbang for bash scripts than "#!/bin/bash", because it automatically works on Unix-like systems that are not GNU/Linux and do not have bash in /bin, but on which it has been installed in another $PATH directory, such as /usr/local/bin. (It can also be helpful on macOS, where /bin/bash is usually an old version of bash, while a package manager such as brew may have been used to install a newer version elsewhere.) Windows systems with WSL installed often have a deprecated bash.exe in the System32 directory that runs commands and scripts inside an installed WSL system. (wsl.exe should be used instead.) Anytime that bash is used due to a "#!/usr/bin/env bash" hashbang, it is wrong, because that only happens if the caller is some Unix-style script running natively or otherwise outside WSL. Normally this is not a reason to prefer a "#!/bin/bash" hashbang, because normally any environment in which one can run a script in a way that determines its interpreter from its hashbang is an environment in which a native (or otherwise appropriate) bash precedes the System32 bash in a PATH search. However, MinGW make, a popular make implementation used on Windows, is an exception. The goal of this change is not to sacrifice support for some Unix-like systems to better support Windows, which wouldn't necessarily be justified. Rather, this is to avoid extremely confusing wrong behavior that in some cases would have bizarre effects that are very hard to detect. I discovered this problem because the VIRTUAL_ENV variable was not inheried by the bash interpreter (because it was, fortunately, not passed through to WSL). But if "python3 -m build" finds a global "build" package, things might get much further before any problem is noticed. --- build-release.sh | 2 +- check-version.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build-release.sh b/build-release.sh index ebb45e062..cbf0e91a9 100755 --- a/build-release.sh +++ b/build-release.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/bash # # This script builds a release. If run in a venv, it auto-installs its tools. # You may want to run "make release" instead of running this script directly. diff --git a/check-version.sh b/check-version.sh index 802492d93..e74ec2606 100755 --- a/check-version.sh +++ b/check-version.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/bash # # This script checks if we are in a consistent state to build a new release. # See the release instructions in README.md for the steps to make this pass. From ba84db487a31c593fe0618a63f80709e405039c9 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Thu, 14 Sep 2023 08:11:42 -0400 Subject: [PATCH 12/18] Fix message wording that was opposite of intended This also makes a correct but confusing comment clearer. --- check-version.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/check-version.sh b/check-version.sh index e74ec2606..373403c0e 100755 --- a/check-version.sh +++ b/check-version.sh @@ -13,7 +13,7 @@ readonly changes_path='doc/source/changes.rst' printf 'Checking current directory.\n' test "$(cd -- "$(dirname -- "$0")" && pwd)" = "$(pwd)" # Ugly, but portable. -printf 'Checking that %s and %s exist and have no committed changes.\n' \ +printf 'Checking that %s and %s exist and have no uncommitted changes.\n' \ "$version_path" "$changes_path" test -f "$version_path" test -f "$changes_path" @@ -40,7 +40,7 @@ printf '%-14s = %s\n' 'VERSION file' "$version_version" \ 'HEAD SHA' "$head_sha" \ 'Latest tag SHA' "$latest_tag_sha" -# Check that latest tag matches version and is the current HEAD we're releasing +# Check that the latest tag and current version match the HEAD we're releasing. test "$version_version" = "$changes_version" test "$latest_tag" = "$version_version" test "$head_sha" = "$latest_tag_sha" From de40e6864d5cbf8cd604b6f718b876c4d8c5a323 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Thu, 14 Sep 2023 08:57:34 -0400 Subject: [PATCH 13/18] Ignore some other virtual environment directories Like ".venv" and "venv", ".env" and "env" are common, plus "env" appears in the example command shown for making a virtual environment for the purpose of building a release, under some circumstances when "make release" or "make force_release" fail. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 72da84eee..0bd307639 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ *.py[co] *.swp *~ +.env/ +env/ .venv/ venv/ /*.egg-info From 693d041869497137085171cdabbaf43e33fb9c84 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 15 Sep 2023 07:40:36 +0200 Subject: [PATCH 14/18] make `.gitattributes` file more generic That way shell scripts will be handled correctly by default, anywhere. --- .gitattributes | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.gitattributes b/.gitattributes index a66dc90ca..3f3d2f050 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,3 @@ test/fixtures/* eol=lf -init-tests-after-clone.sh eol=lf -Makefile eol=lf -check-version.sh eol=lf -build-release.sh eol=lf +*.sh eol=lf +/Makefile eol=lf From 962f747d9c2a877e70886f2ebee975b9be4bb672 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 15 Sep 2023 07:47:31 +0200 Subject: [PATCH 15/18] submodules don't contribute to the release; ignore their changes --- check-version.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/check-version.sh b/check-version.sh index 373403c0e..81112b326 100755 --- a/check-version.sh +++ b/check-version.sh @@ -22,8 +22,8 @@ test -z "$(git status -s -- "$version_path" "$changes_path")" # This section can be commented out, if absolutely necessary. printf 'Checking that ALL changes are committed.\n' -git status -s -test -z "$(git status -s)" +git status -s --ignore-submodules +test -z "$(git status -s --ignore-submodules)" printf 'Gathering current version, latest tag, and current HEAD commit info.\n' version_version="$(cat "$version_path")" From d18d90a2c04abeff4bcc8d642fcd33be1c1eb35b Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 15 Sep 2023 07:53:55 +0200 Subject: [PATCH 16/18] Use 'echo' where possible to avoid explicit newlines --- check-version.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/check-version.sh b/check-version.sh index 81112b326..d29d457c0 100755 --- a/check-version.sh +++ b/check-version.sh @@ -5,27 +5,26 @@ # You may want to run "make release" instead of running this script directly. set -eEfuo pipefail -trap 'printf "%s: Check failed. Stopping.\n" "$0" >&2' ERR +trap 'echo "$0: Check failed. Stopping." >&2' ERR readonly version_path='VERSION' readonly changes_path='doc/source/changes.rst' -printf 'Checking current directory.\n' +echo 'Checking current directory.' test "$(cd -- "$(dirname -- "$0")" && pwd)" = "$(pwd)" # Ugly, but portable. -printf 'Checking that %s and %s exist and have no uncommitted changes.\n' \ - "$version_path" "$changes_path" +echo "Checking that $version_path and $changes_path exist and have no uncommitted changes." test -f "$version_path" test -f "$changes_path" git status -s -- "$version_path" "$changes_path" test -z "$(git status -s -- "$version_path" "$changes_path")" # This section can be commented out, if absolutely necessary. -printf 'Checking that ALL changes are committed.\n' +echo 'Checking that ALL changes are committed.' git status -s --ignore-submodules test -z "$(git status -s --ignore-submodules)" -printf 'Gathering current version, latest tag, and current HEAD commit info.\n' +echo 'Gathering current version, latest tag, and current HEAD commit info.' version_version="$(cat "$version_path")" changes_version="$(awk '/^[0-9]/ {print $0; exit}' "$changes_path")" config_opts="$(printf ' -c versionsort.suffix=-%s' alpha beta pre rc RC)" @@ -44,4 +43,4 @@ printf '%-14s = %s\n' 'VERSION file' "$version_version" \ test "$version_version" = "$changes_version" test "$latest_tag" = "$version_version" test "$head_sha" = "$latest_tag_sha" -printf 'OK, everything looks good.\n' +echo 'OK, everything looks good.' From 5919f8d04bccfaf0c98ae032437635d1a2de656b Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 15 Sep 2023 08:06:51 +0200 Subject: [PATCH 17/18] Be explicit on how to interpret the data table --- check-version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check-version.sh b/check-version.sh index d29d457c0..6d10d6785 100755 --- a/check-version.sh +++ b/check-version.sh @@ -24,7 +24,6 @@ echo 'Checking that ALL changes are committed.' git status -s --ignore-submodules test -z "$(git status -s --ignore-submodules)" -echo 'Gathering current version, latest tag, and current HEAD commit info.' version_version="$(cat "$version_path")" changes_version="$(awk '/^[0-9]/ {print $0; exit}' "$changes_path")" config_opts="$(printf ' -c versionsort.suffix=-%s' alpha beta pre rc RC)" @@ -33,6 +32,7 @@ head_sha="$(git rev-parse HEAD)" latest_tag_sha="$(git rev-parse "$latest_tag")" # Display a table of all the current version, tag, and HEAD commit information. +echo $'\nThe VERSION must be the same in all locations, and so must the HEAD and tag SHA' printf '%-14s = %s\n' 'VERSION file' "$version_version" \ 'changes.rst' "$changes_version" \ 'Latest tag' "$latest_tag" \ From 1e0b3f91f6dffad6bfc262528c14bf459c6a63c8 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 15 Sep 2023 08:32:30 +0200 Subject: [PATCH 18/18] refinements to `build-reelase.sh` - use `echo` where feasible to avoid explicit newlines - use `function` syntax out of habit - deduplicate release invocation - make `venv` based invocation less verbose - make help-text in non-venv more prominent --- build-release.sh | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/build-release.sh b/build-release.sh index cbf0e91a9..5840e4472 100755 --- a/build-release.sh +++ b/build-release.sh @@ -5,18 +5,22 @@ set -eEu +function release_with() { + $1 -m build --sdist --wheel +} + if test -n "${VIRTUAL_ENV:-}"; then deps=(build twine) # Install twine along with build, as we need it later. - printf 'Virtual environment detected. Adding packages: %s\n' "${deps[*]}" - pip install -U "${deps[@]}" - printf 'Starting the build.\n' - python -m build --sdist --wheel + echo "Virtual environment detected. Adding packages: ${deps[*]}" + pip install --quiet --upgrade "${deps[@]}" + echo 'Starting the build.' + release_with python else - suggest_venv() { + function suggest_venv() { venv_cmd='python -m venv env && source env/bin/activate' - printf "Use a virtual-env with '%s' instead.\n" "$venv_cmd" + printf "HELP: To avoid this error, use a virtual-env with '%s' instead.\n" "$venv_cmd" } trap suggest_venv ERR # This keeps the original exit (error) code. - printf 'Starting the build.\n' - python3 -m build --sdist --wheel # Outside a venv, use python3. + echo 'Starting the build.' + release_with python3 # Outside a venv, use python3. fi