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