|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# |
| 3 | +# Copyright 2021 Axel Huebl |
| 4 | +# |
| 5 | +# This file is part of WarpX. |
| 6 | +# |
| 7 | + |
| 8 | +# This file is a maintainer tool to bump the pyAMReX version that we pull in |
| 9 | +# when building WarpX. |
| 10 | +# |
| 11 | +import datetime |
| 12 | +from pathlib import Path |
| 13 | +import re |
| 14 | +import sys |
| 15 | + |
| 16 | +import requests |
| 17 | + |
| 18 | +# Maintainer Inputs ########################################################### |
| 19 | + |
| 20 | +print("""Hi there, this is a WarpX maintainer tool to update the source |
| 21 | +code of WarpX to a new commit/release of pyAMReX. |
| 22 | +For it to work, you need write access on the source directory and |
| 23 | +you should be working in a clean git branch without ongoing |
| 24 | +rebase/merge/conflict resolves and without unstaged changes.""") |
| 25 | + |
| 26 | +# check source dir |
| 27 | +REPO_DIR = Path(__file__).parent.parent.parent.absolute() |
| 28 | +print(f"\nYour current source directory is: {REPO_DIR}") |
| 29 | + |
| 30 | +REPLY = input("Are you sure you want to continue? [y/N] ") |
| 31 | +print() |
| 32 | +if not REPLY in ["Y", "y"]: |
| 33 | + print("You did not confirm with 'y', aborting.") |
| 34 | + sys.exit(1) |
| 35 | + |
| 36 | + |
| 37 | +# Current Versions ############################################################ |
| 38 | + |
| 39 | +# pyAMReX development HEAD |
| 40 | +pyamrex_gh = requests.get('https://api.github.com/repos/AMReX-Codes/pyamrex/commits/development') |
| 41 | +pyamrex_HEAD = pyamrex_gh.json()["sha"] |
| 42 | + |
| 43 | +# WarpX references to pyAMReX: cmake/dependencies/pyAMReX.cmake |
| 44 | +pyamrex_cmake_path = str(REPO_DIR.joinpath("cmake/dependencies/pyAMReX.cmake")) |
| 45 | +# branch/commit/tag (git fetcher) version |
| 46 | +# set(WarpX_pyamrex_branch "development" ... |
| 47 | +pyamrex_branch = f"unknown (format issue in {pyamrex_cmake_path})" |
| 48 | +with open(pyamrex_cmake_path, encoding='utf-8') as f: |
| 49 | + r_minimal = re.findall(r'.*set\(WarpX_pyamrex_branch\s+"(.+)"\s+.*', |
| 50 | + f.read(), re.MULTILINE) |
| 51 | + if len(r_minimal) >= 1: |
| 52 | + pyamrex_branch = r_minimal[0] |
| 53 | + |
| 54 | +# minimal (external) version |
| 55 | +# find_package(AMReX YY.MM CONFIG ... |
| 56 | +pyamrex_minimal = f"unknown (format issue in {pyamrex_cmake_path})" |
| 57 | +with open(pyamrex_cmake_path, encoding='utf-8') as f: |
| 58 | + r_minimal = re.findall(r'.*find_package\(AMReX\s+(.+)\s+CONFIG\s+.*', |
| 59 | + f.read(), re.MULTILINE) |
| 60 | + if len(r_minimal) >= 1: |
| 61 | + pyamrex_minimal = r_minimal[0] |
| 62 | + |
| 63 | + |
| 64 | +# Ask for new ################################################################# |
| 65 | + |
| 66 | +print("""We will now run a few sed commands on your source directory. |
| 67 | +Please answer the following questions about the version number |
| 68 | +you want to require from pyAMReX:\n""") |
| 69 | + |
| 70 | +print(f"Currently, WarpX builds against this pyAMReX commit/branch/sha: {pyamrex_branch}") |
| 71 | +print(f"pyAMReX HEAD commit (development branch): {pyamrex_HEAD}") |
| 72 | +pyamrex_new_branch = input(f"Update pyAMReX commit/branch/sha: ").strip() |
| 73 | +if not pyamrex_new_branch: |
| 74 | + pyamrex_new_branch = pyamrex_branch |
| 75 | + print(f"--> Nothing entered, will keep: {pyamrex_branch}") |
| 76 | +print() |
| 77 | + |
| 78 | +print(f"Currently, a pre-installed pyAMReX is required at least at version: {pyamrex_minimal}") |
| 79 | +today = datetime.date.today().strftime("%y.%m") |
| 80 | +pyamrex_new_minimal = input(f"New minimal pyAMReX version (e.g. {today})? ").strip() |
| 81 | +if not pyamrex_new_minimal: |
| 82 | + pyamrex_new_minimal = pyamrex_minimal |
| 83 | + print(f"--> Nothing entered, will keep: {pyamrex_minimal}") |
| 84 | + |
| 85 | +print() |
| 86 | +print(f"New pyAMReX commit/branch/sha: {pyamrex_new_branch}") |
| 87 | +print(f"New minimal pyAMReX version: {pyamrex_new_minimal}\n") |
| 88 | + |
| 89 | +REPLY = input("Is this information correct? Will now start updating! [y/N] ") |
| 90 | +print() |
| 91 | +if not REPLY in ["Y", "y"]: |
| 92 | + print("You did not confirm with 'y', aborting.") |
| 93 | + sys.exit(1) |
| 94 | + |
| 95 | + |
| 96 | +# Updates ##################################################################### |
| 97 | + |
| 98 | +# WarpX references to pyAMReX: cmake/dependencies/pyAMReX.cmake |
| 99 | +with open(pyamrex_cmake_path, encoding='utf-8') as f: |
| 100 | + pyAMReX_cmake_content = f.read() |
| 101 | + |
| 102 | + # branch/commit/tag (git fetcher) version |
| 103 | + # set(WarpX_pyamrex_branch "development" ... |
| 104 | + pyAMReX_cmake_content = re.sub( |
| 105 | + r'(.*set\(WarpX_pyamrex_branch\s+")(.+)("\s+.*)', |
| 106 | + r'\g<1>{}\g<3>'.format(pyamrex_new_branch), |
| 107 | + pyAMReX_cmake_content, flags = re.MULTILINE) |
| 108 | + |
| 109 | + # minimal (external) version |
| 110 | + # find_package(AMReX YY.MM CONFIG ... |
| 111 | + pyAMReX_cmake_content = re.sub( |
| 112 | + r'(.*find_package\(pyAMReX\s+)(.+)(\s+CONFIG\s+.*)', |
| 113 | + r'\g<1>{}\g<3>'.format(pyamrex_new_minimal), |
| 114 | + pyAMReX_cmake_content, flags = re.MULTILINE) |
| 115 | + |
| 116 | +with open(pyamrex_cmake_path, "w", encoding='utf-8') as f: |
| 117 | + f.write(pyAMReX_cmake_content) |
| 118 | + |
| 119 | + |
| 120 | +# Epilogue #################################################################### |
| 121 | + |
| 122 | +print("""Done. Please check your source, e.g. via |
| 123 | + git diff |
| 124 | +now and commit the changes if no errors occurred.""") |
0 commit comments