From f752e1fa966b5f7a16125535499bb198cef455c9 Mon Sep 17 00:00:00 2001 From: David Bold Date: Thu, 5 Oct 2023 09:57:22 +0200 Subject: [PATCH 1/5] Add comments --- tools/pylib/_boutpp_build/backend.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/pylib/_boutpp_build/backend.py b/tools/pylib/_boutpp_build/backend.py index 51f0611b45..80b2e9eb3c 100644 --- a/tools/pylib/_boutpp_build/backend.py +++ b/tools/pylib/_boutpp_build/backend.py @@ -29,6 +29,7 @@ def getversion(): global version if version is None: with contextlib.suppress(KeyError): + # 0. Check whether version is set via environment variable version = os.environ["BOUT_PRETEND_VERSION"] return version @@ -37,8 +38,10 @@ def getversion(): try: try: + # 1. Check whether we are at a tag version = run2("git describe --exact-match --tags HEAD").strip() except subprocess.CalledProcessError: + # 2. default mode, try to derive version from previous tag tmp = run2( f"git describe --tags --match={_bout_previous_version}" ).strip() From 31368561609205b65b19f5bbec76b8ebc724e807 Mon Sep 17 00:00:00 2001 From: David Bold Date: Thu, 5 Oct 2023 09:57:59 +0200 Subject: [PATCH 2/5] Add fallback if the version has been bumped bot not tagged --- tools/pylib/_boutpp_build/backend.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/pylib/_boutpp_build/backend.py b/tools/pylib/_boutpp_build/backend.py index 80b2e9eb3c..1465177f6a 100644 --- a/tools/pylib/_boutpp_build/backend.py +++ b/tools/pylib/_boutpp_build/backend.py @@ -56,8 +56,20 @@ def getversion(): with open("_version.txt", "w") as f: f.write(version + "\n") except subprocess.CalledProcessError: - with open("_version.txt") as f: - version = f.read().strip() + try: + # 3. Check whether there is a _version - e.g. we have a tarball + with open("_version.txt") as f: + version = f.read().strip() + except FileNotFoundError: + # 4. Maybe not released yet, but version already bumped? + # Things are messy here, so always assume useLocalVersion + try: + # 4.1 us proper hash + hash = run2('git log -n 1 --pretty=format:"%h"') + except subprocess.CalledProcessError: + # 4.2 fallback + hash = "unknown" + version = _bout_previous_version + "-rc+" + hash return version From e662b44f3501ca7e295753f6e388dc861e27374d Mon Sep 17 00:00:00 2001 From: David Bold Date: Thu, 5 Oct 2023 09:58:30 +0200 Subject: [PATCH 3/5] $ must not be escaped in python --- tools/pylib/_boutpp_build/backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pylib/_boutpp_build/backend.py b/tools/pylib/_boutpp_build/backend.py index 1465177f6a..7e5dea2aa7 100644 --- a/tools/pylib/_boutpp_build/backend.py +++ b/tools/pylib/_boutpp_build/backend.py @@ -152,7 +152,7 @@ def build_wheel(wheel_directory, config_settings=None, metadata_directory=None): run( "cmake -S . -B _wheel_build/ -DBOUT_ENABLE_PYTHON=ON" + f" -DCMAKE_INSTALL_PREFIX={prefix} -DCMAKE_INSTALL_LIBDIR={prefix}" - + f" -DCMAKE_INSTALL_PYTHON_SITEARCH={trueprefix} -DCMAKE_INSTALL_RPATH=\$ORIGIN" + + f" -DCMAKE_INSTALL_PYTHON_SITEARCH={trueprefix} -DCMAKE_INSTALL_RPATH=$ORIGIN" + opts ) run(f"cmake --build _wheel_build/ -j {os.cpu_count()}") From 7d07d217860f7405484212d61903e4628e744265 Mon Sep 17 00:00:00 2001 From: David Bold Date: Thu, 5 Oct 2023 10:04:31 +0200 Subject: [PATCH 4/5] Write version also in fallback mode --- tools/pylib/_boutpp_build/backend.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/pylib/_boutpp_build/backend.py b/tools/pylib/_boutpp_build/backend.py index 7e5dea2aa7..657962478c 100644 --- a/tools/pylib/_boutpp_build/backend.py +++ b/tools/pylib/_boutpp_build/backend.py @@ -70,6 +70,8 @@ def getversion(): # 4.2 fallback hash = "unknown" version = _bout_previous_version + "-rc+" + hash + with open("_version.txt", "w") as f: + f.write(version + "\n") return version From 6318dd8209744303a456238874508c94afd8be4a Mon Sep 17 00:00:00 2001 From: David Bold Date: Thu, 5 Oct 2023 10:42:38 +0200 Subject: [PATCH 5/5] Fix version --- tools/pylib/_boutpp_build/backend.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/pylib/_boutpp_build/backend.py b/tools/pylib/_boutpp_build/backend.py index 657962478c..15dbc84e31 100644 --- a/tools/pylib/_boutpp_build/backend.py +++ b/tools/pylib/_boutpp_build/backend.py @@ -65,11 +65,11 @@ def getversion(): # Things are messy here, so always assume useLocalVersion try: # 4.1 us proper hash - hash = run2('git log -n 1 --pretty=format:"%h"') + hash = "g" + run2('git log -n 1 --pretty=format:"%h"') except subprocess.CalledProcessError: # 4.2 fallback hash = "unknown" - version = _bout_previous_version + "-rc+" + hash + version = _bout_previous_version + ".rc+" + hash with open("_version.txt", "w") as f: f.write(version + "\n") return version