Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Aug 2, 2024
1 parent ebcfa61 commit d3fe21a
Showing 1 changed file with 70 additions and 44 deletions.
114 changes: 70 additions & 44 deletions new_version.sh → new_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# This file is a maintainer tool to bump the versions inside openPMD-api's
# source directory at all places where necessary.
#
import datetime
from pathlib import Path
import re
import sys
Expand All @@ -33,7 +32,8 @@
rebase/merge/conflict resolves and without unstaged changes.""")

# check source dir
REPO_DIR = Path(__file__).parent.parent.parent.absolute()
# REPO_DIR = Path(__file__).parent.parent.parent.absolute()
REPO_DIR = Path(__file__).parent.absolute()
print(f"\nYour current source directory is: {REPO_DIR}")

REPLY = input("Are you sure you want to continue? [Y/n] ")
Expand All @@ -46,25 +46,34 @@
# New Version #################################################################

# AMReX development HEAD
amrex_gh = requests.get('https://api.github.com/repos/AMReX-Codes/amrex/commits/development')
amrex_HEAD = amrex_gh.json()["sha"]
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) ")
if SUFFIX != "":
SUFFIX_STR = f"-{SUFFIX}"

VERSION_STR_NOSUFFIX=f"{MAJOR}.{MINOR}{PATCH}"
VERSION_STR=f"{MAJOR}.{MINOR}.{PATCH}{SUFFIX_STR}"
VERSION_STR=f"{MAJOR}.{MINOR}.{PATCH}"

echo
echo "Your new version is: ${VERSION_STR}"
echo
print()
print(f"Your new version is: {VERSION_STR}")

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)
if match:
OLD_VERSION_STR = match.group(1)
break

print(f"The old version is: {OLD_VERSION_STR}")
print()

read -p "Is this information correct? Will now start updating! [y/N] " -r
echo

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.")
sys.exit(1)


# Ask for new #################################################################
Expand All @@ -73,24 +82,24 @@
Please answer the following questions about the version number
you want to require from AMReX:\n""")

print(f"Currently, WarpX builds against this AMReX commit/branch/sha: {amrex_branch}")
print(f"AMReX HEAD commit (development branch): {amrex_HEAD}")
amrex_new_branch = input(f"Update AMReX commit/branch/sha: ").strip()
if not amrex_new_branch:
amrex_new_branch = amrex_branch
print(f"--> Nothing entered, will keep: {amrex_branch}")
print()

print(f"Currently, a pre-installed AMReX is required at least at version: {amrex_minimal}")
today = datetime.date.today().strftime("%y.%m")
amrex_new_minimal = input(f"New minimal AMReX version (e.g. {today})? ").strip()
if not amrex_new_minimal:
amrex_new_minimal = amrex_minimal
print(f"--> Nothing entered, will keep: {amrex_minimal}")

print()
print(f"New AMReX commit/branch/sha: {amrex_new_branch}")
print(f"New minimal AMReX version: {amrex_new_minimal}\n")
# print(f"Currently, WarpX builds against this AMReX commit/branch/sha: {amrex_branch}")
print(f"openPMD HEAD commit (dev branch): {openpmd_HEAD}")
# amrex_new_branch = input(f"Update AMReX commit/branch/sha: ").strip()
# if not amrex_new_branch:
# amrex_new_branch = amrex_branch
# print(f"--> Nothing entered, will keep: {amrex_branch}")
# print()

# print(f"Currently, a pre-installed AMReX is required at least at version: {amrex_minimal}")
# today = datetime.date.today().strftime("%y.%m")
# amrex_new_minimal = input(f"New minimal AMReX version (e.g. {today})? ").strip()
# if not amrex_new_minimal:
# amrex_new_minimal = amrex_minimal
# print(f"--> Nothing entered, will keep: {amrex_minimal}")

# print()
# print(f"New AMReX commit/branch/sha: {amrex_new_branch}")
# print(f"New minimal AMReX version: {amrex_new_minimal}\n")

REPLY = input("Is this information correct? Will now start updating! [y/N] ")
print()
Expand All @@ -102,18 +111,35 @@
# Updates #####################################################################

# run_test.sh (used also for Azure Pipelines)
run_test_path = str(REPO_DIR.joinpath("run_test.sh"))
with open(run_test_path, encoding='utf-8') as f:
run_test_content = f.read()
# branch/commit/tag (git fetcher) version
# cd amrex && git checkout COMMIT_TAG_OR_BRANCH && cd -
run_test_content = re.sub(
r'(.*cd\s+amrex.+git checkout\s+--detach\s+)(.+)(\s+&&\s.*)',
r'\g<1>{}\g<3>'.format(amrex_new_branch),
run_test_content, flags = re.MULTILINE)

with open(run_test_path, "w", encoding='utf-8') as f:
f.write(run_test_content)
cmakelists_path = str(REPO_DIR.joinpath("CMakeLists.txt"))
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),
cmakelists_content,
flags = re.MULTILINE
)

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:
content = f.read()
content = re.sub(
re.escape(OLD_VERSION_STR),
VERSION_STR,
content
)

with open(filename, "w", encoding='utf-8') as f:
f.write(content)

for file in ['docs/source/dev/linking.rst', 'README.md']:
generic_replace(file)
sys.exit(0)

# CI: legacy build check in .github/workflows/cuda.yml
ci_gnumake_path = str(REPO_DIR.joinpath(".github/workflows/cuda.yml"))
Expand Down

0 comments on commit d3fe21a

Please sign in to comment.