From f4d5eae2947f262966a38388b9c5a9311c1805b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Fri, 2 Aug 2024 15:07:26 +0200 Subject: [PATCH] wip --- new_version.py | 115 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 76 insertions(+), 39 deletions(-) diff --git a/new_version.py b/new_version.py index 57f891523b..8aa3b18366 100755 --- a/new_version.py +++ b/new_version.py @@ -25,11 +25,13 @@ # Maintainer Inputs ########################################################### -print("""Hi there, this is an openPMD maintainer tool to update the source +print( + """Hi there, this is an openPMD maintainer tool to update the source code of openPMD-api to a new version. For it to work, you need write access on the source directory and you should be working in a clean git branch without ongoing -rebase/merge/conflict resolves and without unstaged changes.""") +rebase/merge/conflict resolves and without unstaged changes.""" +) # check source dir # REPO_DIR = Path(__file__).parent.parent.parent.absolute() @@ -46,21 +48,25 @@ # New Version ################################################################# # AMReX development HEAD -openpmd_gh = requests.get('https://api.github.com/repos/openPMD/openPMD-api/commits/dev') +openpmd_gh = requests.get( + "https://api.github.com/repos/openPMD/openPMD-api/commits/dev" +) openpmd_HEAD = openpmd_gh.json()["sha"] MAJOR = input("MAJOR version? (e.g., 1) ") MINOR = input("MINOR version? (e.g., 0) ") PATCH = input("PATCH version? (e.g., 0) ") +SUFFIX = input("SUFFIX? (e.g., dev) ") -VERSION_STR=f"{MAJOR}.{MINOR}.{PATCH}" +VERSION_STR = f"{MAJOR}.{MINOR}.{PATCH}" +VERSION_STR_SUFFIX = VERSION_STR + (f"-{SUFFIX}" if SUFFIX else "") print() -print(f"Your new version is: {VERSION_STR}") +print(f"Your new version is: {VERSION_STR_SUFFIX}") -with open(str(REPO_DIR.joinpath('README.md')), encoding='utf-8') as f: +with open(str(REPO_DIR.joinpath("README.md")), encoding="utf-8") as f: for line in f: - match = re.search(r'find_package.*openPMD *([^ ]*) *CONFIG\).*', line) + match = re.search(r"find_package.*openPMD *([^ ]*) *CONFIG\).*", line) if match: OLD_VERSION_STR = match.group(1) break @@ -69,7 +75,7 @@ print() -REPLY=input("Is this information correct? Will now start updating! [y/N] ") +REPLY = input("Is this information correct? Will now start updating! [y/N] ") print() if not REPLY in ["Y", "y", ""]: print("You did not confirm with 'y', aborting.") @@ -78,9 +84,11 @@ # Ask for new ################################################################# -print("""We will now run a few sed commands on your source directory. +print( + """We will now run a few sed commands on your source directory. Please answer the following questions about the version number -you want to require from AMReX:\n""") +you want to require from AMReX:\n""" +) # print(f"Currently, WarpX builds against this AMReX commit/branch/sha: {amrex_branch}") print(f"openPMD HEAD commit (dev branch): {openpmd_HEAD}") @@ -112,47 +120,70 @@ # run_test.sh (used also for Azure Pipelines) cmakelists_path = str(REPO_DIR.joinpath("CMakeLists.txt")) -with open(cmakelists_path, encoding='utf-8') as f: +with open(cmakelists_path, encoding="utf-8") as f: cmakelists_content = f.read() cmakelists_content = re.sub( - r'^(project.*openPMD.*VERSION *)(.*)(\).*)$', - r'\g<1>{}\g<3>'.format(VERSION_STR_NOSUFFIX), + r"^(project.*openPMD.*VERSION *)(.*)(\).*)$", + r"\g<1>{}\g<3>".format(VERSION_STR), cmakelists_content, - flags = re.MULTILINE + flags=re.MULTILINE, ) -with open(cmakelists_path, "w", encoding='utf-8') as f: +with open(cmakelists_path, "w", encoding="utf-8") as f: f.write(cmakelists_content) + def generic_replace(filename): filename = str(REPO_DIR.joinpath(filename)) - with open(filename, encoding='utf-8') as f: + with open(filename, encoding="utf-8") as f: content = f.read() - content = re.sub( - re.escape(OLD_VERSION_STR), - VERSION_STR, - content - ) + content = re.sub(re.escape(OLD_VERSION_STR), VERSION_STR, content) - with open(filename, "w", encoding='utf-8') as f: + with open(filename, "w", encoding="utf-8") as f: f.write(content) -for file in ['docs/source/dev/linking.rst', 'README.md']: + +for file in ["docs/source/dev/linking.rst", "README.md"]: generic_replace(file) + +version_hpp_path = str(REPO_DIR.joinpath("include/openPMD/version.hpp")) +with open(version_hpp_path, encoding="utf-8") as f: + version_hpp_content = f.read() + + def replace(key, value): + global version_hpp_content + version_hpp_content = re.sub( + r"^(#define OPENPMDAPI_VERSION_{}) .*$".format(re.escape(key)), + r"\1 {}".format(value), + version_hpp_content, + flags=re.MULTILINE, + ) + + replace("MAJOR", MAJOR) + replace("MINOR", MINOR) + replace("PATCH", PATCH) + replace("LABEL", '"{}"'.format(SUFFIX)) + +with open(version_hpp_path, "w", encoding="utf-8") as f: + f.write(version_hpp_content) + + sys.exit(0) # CI: legacy build check in .github/workflows/cuda.yml ci_gnumake_path = str(REPO_DIR.joinpath(".github/workflows/cuda.yml")) -with open(ci_gnumake_path, encoding='utf-8') as f: +with open(ci_gnumake_path, encoding="utf-8") as f: ci_gnumake_content = f.read() # branch/commit/tag (git fetcher) version # cd ../amrex && git checkout COMMIT_TAG_OR_BRANCH && cd - ci_gnumake_content = re.sub( - r'(.*cd\s+\.\./amrex.+git checkout\s+--detach\s+)(.+)(\s+&&\s.*)', - r'\g<1>{}\g<3>'.format(amrex_new_branch), - ci_gnumake_content, flags = re.MULTILINE) + r"(.*cd\s+\.\./amrex.+git checkout\s+--detach\s+)(.+)(\s+&&\s.*)", + r"\g<1>{}\g<3>".format(amrex_new_branch), + ci_gnumake_content, + flags=re.MULTILINE, + ) -with open(ci_gnumake_path, "w", encoding='utf-8') as f: +with open(ci_gnumake_path, "w", encoding="utf-8") as f: f.write(ci_gnumake_content) if ConfigUpdater is not None: @@ -161,7 +192,7 @@ def generic_replace(filename): cp = ConfigUpdater() cp.optionxform = str cp.read(tests_ini_path) - cp['AMReX']['branch'].value = amrex_new_branch + cp["AMReX"]["branch"].value = amrex_new_branch cp.update_file() # WarpX-GPU-tests.ini @@ -169,33 +200,39 @@ def generic_replace(filename): cp = ConfigUpdater() cp.optionxform = str cp.read(tests_gpu_ini_path) - cp['AMReX']['branch'].value = amrex_new_branch + cp["AMReX"]["branch"].value = amrex_new_branch cp.update_file() # WarpX references to AMReX: cmake/dependencies/AMReX.cmake -with open(amrex_cmake_path, encoding='utf-8') as f: +with open(amrex_cmake_path, encoding="utf-8") as f: amrex_cmake_content = f.read() # branch/commit/tag (git fetcher) version # set(WarpX_amrex_branch "development" ... amrex_cmake_content = re.sub( r'(.*set\(WarpX_amrex_branch\s+")(.+)("\s+.*)', - r'\g<1>{}\g<3>'.format(amrex_new_branch), - amrex_cmake_content, flags = re.MULTILINE) + r"\g<1>{}\g<3>".format(amrex_new_branch), + amrex_cmake_content, + flags=re.MULTILINE, + ) # minimal (external) version # find_package(AMReX YY.MM CONFIG ... amrex_cmake_content = re.sub( - r'(.*find_package\(AMReX\s+)(.+)(\s+CONFIG\s+.*)', - r'\g<1>{}\g<3>'.format(amrex_new_minimal), - amrex_cmake_content, flags = re.MULTILINE) + r"(.*find_package\(AMReX\s+)(.+)(\s+CONFIG\s+.*)", + r"\g<1>{}\g<3>".format(amrex_new_minimal), + amrex_cmake_content, + flags=re.MULTILINE, + ) -with open(amrex_cmake_path, "w", encoding='utf-8') as f: +with open(amrex_cmake_path, "w", encoding="utf-8") as f: f.write(amrex_cmake_content) # Epilogue #################################################################### -print("""Done. Please check your source, e.g. via +print( + """Done. Please check your source, e.g. via git diff -now and commit the changes if no errors occurred.""") +now and commit the changes if no errors occurred.""" +)