Skip to content

Commit db23d6e

Browse files
committed
Implement same dependency/release update workflow as WarpX
1 parent 256864a commit db23d6e

File tree

7 files changed

+186
-8
lines changed

7 files changed

+186
-8
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
# Parse pyAMReX version information
2+
file(READ "${CMAKE_CURRENT_LIST_DIR}/dependencies.json" dependencies_data)
3+
string(JSON pyamrex_version GET "${dependencies_data}" version_pyamrex)
4+
15
# Preamble ####################################################################
26
#
37
cmake_minimum_required(VERSION 3.24.0)
4-
project(pyAMReX VERSION 25.09)
8+
project(pyAMReX VERSION ${pyamrex_version})
59

610
include(${pyAMReX_SOURCE_DIR}/cmake/pyAMReXFunctions.cmake)
711

cmake/dependencies/AMReX.cmake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ macro(find_amrex)
6767
message(STATUS "Searching for pre-installed AMReX ...")
6868
# https://amrex-codes.github.io/amrex/docs_html/BuildingAMReX.html#importing-amrex-into-your-cmake-project
6969
# not strictly required yet to compile pyAMReX: EB
70-
find_package(AMReX 25.09 CONFIG REQUIRED COMPONENTS PARTICLES PIC)
70+
find_package(AMReX ${amrex_version} CONFIG REQUIRED COMPONENTS PARTICLES PIC)
7171
message(STATUS "AMReX: Found version '${AMReX_VERSION}'")
7272

7373
if(AMReX_GPU_BACKEND STREQUAL CUDA)
@@ -86,7 +86,13 @@ option(pyAMReX_amrex_internal "Download & build AMReX" ON)
8686
set(pyAMReX_amrex_repo "https://github.com/AMReX-Codes/amrex.git"
8787
CACHE STRING
8888
"Repository URI to pull and build AMReX from if(pyAMReX_amrex_internal)")
89-
set(pyAMReX_amrex_branch "25.09"
89+
90+
# Parse AMReX version and commit information
91+
file(READ "${pyAMReX_SOURCE_DIR}/dependencies.json" dependencies_data)
92+
string(JSON amrex_version GET "${dependencies_data}" version_amrex)
93+
string(JSON amrex_commit GET "${dependencies_data}" commit_amrex)
94+
95+
set(pyAMReX_amrex_branch ${amrex_commit}
9096
CACHE STRING
9197
"Repository branch for pyAMReX_amrex_repo if(pyAMReX_amrex_internal)")
9298

cmake/dependencies/pybind11.cmake

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function(find_pybind11)
4141
mark_as_advanced(FETCHCONTENT_UPDATES_DISCONNECTED_FETCHEDpybind11)
4242
endif()
4343
elseif(NOT pyAMReX_pybind11_internal)
44-
find_package(pybind11 3.0.0 CONFIG REQUIRED)
44+
find_package(pybind11 ${pybind11_version} CONFIG REQUIRED)
4545
message(STATUS "pybind11: Found version '${pybind11_VERSION}'")
4646
endif()
4747
endfunction()
@@ -56,7 +56,13 @@ option(pyAMReX_pybind11_internal "Download & build pybind11" ON)
5656
set(pyAMReX_pybind11_repo "https://github.com/pybind/pybind11.git"
5757
CACHE STRING
5858
"Repository URI to pull and build pybind11 from if(pyAMReX_pybind11_internal)")
59-
set(pyAMReX_pybind11_branch "v3.0.0"
59+
60+
# Parse AMReX version and commit information
61+
file(READ "${pyAMReX_SOURCE_DIR}/dependencies.json" dependencies_data)
62+
string(JSON pybind11_version GET "${dependencies_data}" version_pybind11)
63+
string(JSON pybind11_commit GET "${dependencies_data}" commit_pybind11)
64+
65+
set(pyAMReX_pybind11_branch ${pybind11_commit}
6066
CACHE STRING
6167
"Repository branch for pyAMReX_pybind11_repo if(pyAMReX_pybind11_internal)")
6268

dependencies.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version_pyamrex": "25.09",
3+
"version_amrex": "25.09",
4+
"version_pybind11": "3.0.0",
5+
"commit_amrex": "95822df1a393b39aeca5e590328e228513132159",
6+
"commit_pybind11": "v3.0.0"
7+
}

docs/source/conf.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
# add these directories to sys.path here. If the directory is relative to the
2323
# documentation root, use os.path.abspath to make it absolute, like shown here.
2424
#
25+
import json
2526
import os
2627
import shutil
2728
import subprocess
@@ -72,14 +73,20 @@
7273
copyright = "2023, The Regents of the University of California, through Lawrence Berkeley National Laboratory, National Renewable Energy Laboratory Alliance for Sustainable Energy, LLC and Lawrence Livermore National Security, LLC (subject to receipt of any required approvals from the U.S. Dept. of Energy)"
7374
author = "AMReX collaboration"
7475

76+
# Parse pyAMReX version information
77+
dependencies_file = "../../dependencies.json"
78+
with open(dependencies_file, "r") as file:
79+
dependencies_data = json.load(file)
80+
pyamrex_version = dependencies_data.get("version_pyamrex")
81+
7582
# The version info for the project you're documenting, acts as replacement for
7683
# |version| and |release|, also used in various other places throughout the
7784
# built documents.
7885
#
7986
# The short X.Y version.
80-
version = "25.09"
87+
version = pyamrex_version
8188
# The full version, including alpha/beta/rc tags.
82-
release = "25.09"
89+
release = pyamrex_version
8390

8491
# The language for content autogenerated by Sphinx. Refer to documentation
8592
# for a list of supported languages.

setup.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Authors: Axel Huebl
66
# License: BSD-3-Clause-LBNL
77
#
8+
import json
89
import os
910
import platform
1011
import re
@@ -213,12 +214,18 @@ def build_extension(self, ext):
213214
if AMReX_MPI == "ON":
214215
install_requires.append("mpi4py>=2.1.0")
215216

217+
# Parse pyAMReX version information
218+
dependencies_file = "dependencies.json"
219+
with open(dependencies_file, "r") as file:
220+
dependencies_data = json.load(file)
221+
pyamrex_version = dependencies_data.get("version_pyamrex")
222+
216223
# keyword reference:
217224
# https://packaging.python.org/guides/distributing-packages-using-setuptools
218225
setup(
219226
name="amrex",
220227
# note PEP-440 syntax: x.y.zaN but x.y.z.devN
221-
version="25.09",
228+
version=pyamrex_version,
222229
packages=["amrex"],
223230
# Python sources:
224231
package_dir={"": "src"},

update_dependencies.py

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#!/usr/bin/env python3
2+
#
3+
# This file is part of pyAMReX.
4+
#
5+
# License: BSD-3-Clause-LBNL
6+
7+
import argparse
8+
import datetime
9+
import json
10+
import os
11+
import sys
12+
from pathlib import Path
13+
14+
import requests
15+
16+
17+
def update(args):
18+
# list of repositories to update
19+
repo_dict = {}
20+
if args.all or args.amrex:
21+
repo_dict["amrex"] = {}
22+
repo_dict["amrex"]["commit"] = (
23+
"https://api.github.com/repos/AMReX-Codes/amrex/commits/development"
24+
)
25+
repo_dict["amrex"]["tags"] = (
26+
"https://api.github.com/repos/AMReX-Codes/amrex/tags"
27+
)
28+
if args.all or args.pyamrex:
29+
repo_dict["pyamrex"] = {}
30+
repo_dict["pyamrex"]["commit"] = (
31+
"https://api.github.com/repos/AMReX-Codes/pyamrex/commits/development"
32+
)
33+
repo_dict["pyamrex"]["tags"] = (
34+
"https://api.github.com/repos/AMReX-Codes/pyamrex/tags"
35+
)
36+
37+
# list of repositories labels for logging convenience
38+
repo_labels = {
39+
"amrex": "AMReX",
40+
"pyamrex": "pyAMReX",
41+
}
42+
43+
# read from JSON file with dependencies data
44+
repo_dir = Path(__file__).parent.absolute()
45+
dependencies_file = os.path.join(repo_dir, "dependencies.json")
46+
try:
47+
with open(dependencies_file, "r") as file:
48+
dependencies_data = json.load(file)
49+
except Exception as e:
50+
print(f"An unexpected error occurred: {e}")
51+
sys.exit()
52+
53+
# loop over repositories and update dependencies data
54+
for repo_name, repo_subdict in repo_dict.items():
55+
print(f"\nUpdating {repo_labels[repo_name]}...")
56+
# set keys to access dependencies data
57+
commit_key = f"commit_{repo_name}"
58+
version_key = f"version_{repo_name}"
59+
# get new commit information
60+
commit_response = requests.get(repo_subdict["commit"])
61+
commit_dict = commit_response.json()
62+
# set new commit
63+
repo_commit_sha = commit_dict["sha"]
64+
# get new version tag information
65+
tags_response = requests.get(repo_subdict["tags"])
66+
tags_list = tags_response.json()
67+
# filter out old-format tags for specific repositories
68+
if repo_name == "amrex":
69+
tags_list_filtered = [
70+
tag_dict
71+
for tag_dict in tags_list
72+
if (tag_dict["name"] != "boxlib" and tag_dict["name"] != "v2024")
73+
]
74+
# set new version tag
75+
if repo_name == "pyamrex":
76+
# current date version for the pyAMReX release update
77+
repo_version_tag = datetime.date.today().strftime("%y.%m")
78+
else:
79+
# latest available tag (index 0) for all other dependencies
80+
repo_version_tag = tags_list_filtered[0]["name"]
81+
# use version tag instead of commit sha for a release update
82+
new_commit_sha = repo_version_tag if args.release else repo_commit_sha
83+
# update commit
84+
if repo_name != "pyamrex":
85+
print(f"- old commit: {dependencies_data[commit_key]}")
86+
print(f"- new commit: {new_commit_sha}")
87+
if dependencies_data[commit_key] == new_commit_sha:
88+
print("Skipping commit update...")
89+
else:
90+
print("Updating commit...")
91+
dependencies_data[f"commit_{repo_name}"] = new_commit_sha
92+
# update version
93+
print(f"- old version: {dependencies_data[version_key]}")
94+
print(f"- new version: {repo_version_tag}")
95+
if dependencies_data[version_key] == repo_version_tag:
96+
print("Skipping version update...")
97+
else:
98+
print("Updating version...")
99+
dependencies_data[f"version_{repo_name}"] = repo_version_tag
100+
101+
# write to JSON file with dependencies data
102+
with open(dependencies_file, "w") as file:
103+
json.dump(dependencies_data, file, indent=4)
104+
105+
106+
if __name__ == "__main__":
107+
# define parser
108+
parser = argparse.ArgumentParser()
109+
110+
# add arguments: AMReX option
111+
parser.add_argument(
112+
"--amrex",
113+
help="Update AMReX only",
114+
action="store_true",
115+
dest="amrex",
116+
)
117+
118+
# add arguments: pyAMReX option
119+
parser.add_argument(
120+
"--pyamrex",
121+
help="Update pyAMReX only",
122+
action="store_true",
123+
dest="pyamrex",
124+
)
125+
126+
# add arguments: release option
127+
parser.add_argument(
128+
"--release",
129+
help="New release",
130+
action="store_true",
131+
dest="release",
132+
)
133+
134+
# parse arguments
135+
args = parser.parse_args()
136+
137+
# set args.all automatically
138+
args.all = False if (args.amrex or args.pyamrex) else True
139+
140+
# update
141+
update(args)

0 commit comments

Comments
 (0)