Skip to content

Commit a1d7a94

Browse files
EZoniax3l
andauthored
Implement same dependency/release update workflow as WarpX (#474)
Requested by @ax3l on Slack (to be used in #378): > Do you mind adding the Tools/Release/update_dependencies.py script (simply in /) to pyAMReX, too? Do not need the other automations for now. WarpX references: - BLAST-WarpX/warpx#5965 - BLAST-WarpX/warpx#5993 - BLAST-WarpX/warpx#6038 To-do: - [x] AMReX - [x] pybind11 --------- Co-authored-by: Axel Huebl <[email protected]>
1 parent 1c2853b commit a1d7a94

File tree

8 files changed

+206
-8
lines changed

8 files changed

+206
-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

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
include README.md LICENSE
22
include pyproject.toml
33
include requirements.txt requirements_mpi.txt
4+
include dependencies.json
45
global-include CMakeLists.txt *.cmake *.in
56
recursive-include cmake *
67
recursive-include src *

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
@@ -87,14 +88,20 @@ def download_with_headers(url, filename):
8788
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)"
8889
author = "AMReX collaboration"
8990

91+
# Parse pyAMReX version information
92+
dependencies_file = "../../dependencies.json"
93+
with open(dependencies_file, "r") as file:
94+
dependencies_data = json.load(file)
95+
pyamrex_version = dependencies_data.get("version_pyamrex")
96+
9097
# The version info for the project you're documenting, acts as replacement for
9198
# |version| and |release|, also used in various other places throughout the
9299
# built documents.
93100
#
94101
# The short X.Y version.
95-
version = "25.09"
102+
version = pyamrex_version
96103
# The full version, including alpha/beta/rc tags.
97-
release = "25.09"
104+
release = pyamrex_version
98105

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

0 commit comments

Comments
 (0)