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 d3fe21a commit f4d5eae
Showing 1 changed file with 76 additions and 39 deletions.
115 changes: 76 additions & 39 deletions new_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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.")
Expand All @@ -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}")
Expand Down Expand Up @@ -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:
Expand All @@ -161,41 +192,47 @@ 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
tests_gpu_ini_path = str(REPO_DIR.joinpath("Regression/WarpX-GPU-tests.ini"))
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."""
)

0 comments on commit f4d5eae

Please sign in to comment.