Skip to content

Commit 212bf53

Browse files
authored
Merge branch 'main' into rebase_add_basic_tests
2 parents 13157c0 + 288ed88 commit 212bf53

8 files changed

Lines changed: 56 additions & 35 deletions

File tree

gh_review_project/cr_deadline.py

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
# -----------------------------------------------------------------------------
23
# (C) Crown copyright Met Office. All rights reserved.
34
# The file LICENCE, distributed with this code, contains details of the terms

gh_review_project/finish_milestone.py

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
# -----------------------------------------------------------------------------
23
# (C) Crown copyright Met Office. All rights reserved.
34
# The file LICENCE, distributed with this code, contains details of the terms

gh_review_project/set_milestone.py

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
# -----------------------------------------------------------------------------
23
# (C) Crown copyright Met Office. All rights reserved.
34
# The file LICENCE, distributed with this code, contains details of the terms

gh_review_project/workload.py

100644100755
Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
# -----------------------------------------------------------------------------
23
# (C) Crown copyright Met Office. All rights reserved.
34
# The file LICENCE, distributed with this code, contains details of the terms
@@ -144,21 +145,31 @@ def build_table(data: ProjectData, reviewer_list: list, repos: list) -> PrettyTa
144145
return table
145146

146147

147-
def print_table(title: str, table: PrettyTable, sortTotal: bool) -> None:
148+
def print_table(
149+
title: str, table: PrettyTable, sortTotal: bool, html_output: str = ""
150+
) -> None:
148151
"""
149152
Print a pretty table and its title.
150153
151154
title: str Title of table to be printed first
152155
table: PrettyTable table to be printed
153156
"""
154-
print(title)
155-
# table.set_style(TableStyle.MARKDOWN) #requires newer version
157+
156158
table.align["Reviewer"] = "l"
157159

158160
if sortTotal:
159161
table.sortby = "Total"
160162

161-
print(table)
163+
if not html_output:
164+
print(title)
165+
print(table)
166+
return
167+
168+
table.format = True
169+
html_table = table.get_html_string()
170+
with open(html_output, "a") as f:
171+
f.write(f"<h1>{title}</h1>")
172+
f.write(html_table)
162173

163174

164175
def parse_args():
@@ -192,6 +203,12 @@ def parse_args():
192203
help="Filepath to test data for either capture the project status, "
193204
"or use as input data.",
194205
)
206+
parser.add_argument(
207+
"--html",
208+
default="",
209+
help="html file to output table contents to. If not set, an ascii formatted "
210+
"table will be outputted to stdout",
211+
)
195212

196213
args = parser.parse_args()
197214

@@ -236,8 +253,17 @@ def main(total: bool, test: bool, capture_project: bool, file: Path):
236253
tables["LFRic"] = build_table(data, reviewers, repo_list)
237254

238255
# Print tables
256+
# Check html path is valid
257+
if args.html:
258+
html_path = Path(args.html)
259+
if html_path.is_dir():
260+
raise ValueError("--html option cannot be a directory")
261+
html_dir = html_path.parent
262+
html_dir.mkdir(parents=True, exist_ok=True)
263+
html_path.unlink(missing_ok=True)
264+
239265
for name, table in tables.items():
240-
print_table(name, table, total)
266+
print_table(name, table, total, args.html)
241267

242268

243269
if __name__ == "__main__":

github_scripts/get_git_sources.py

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,16 @@ def datetime_str() -> str:
9191

9292

9393
def clone_and_merge(
94-
dependency: str,
95-
opts: Union[list, dict],
96-
loc: Path,
97-
use_mirrors: bool,
98-
mirror_loc: Path,
94+
opts: Union[list, dict], loc: Path, use_mirrors: bool, mirror_loc: Path
9995
) -> None:
10096
"""
10197
Wrapper script for calling get_source and merge_source for a single dependency
10298
103-
dependency: name of the dependency
10499
opts: dict or list of dicts for a dependency in the dependencies file
105100
loc: path to location to clone to
106101
use_mirrors: bool, use local git mirrors if true
107102
mirror_loc: path to local git mirrors
108103
"""
109-
110104
if not isinstance(opts, list):
111105
opts = [opts]
112106

@@ -120,7 +114,6 @@ def clone_and_merge(
120114
values["source"],
121115
values["ref"],
122116
loc,
123-
dependency,
124117
use_mirrors,
125118
mirror_loc,
126119
)
@@ -130,7 +123,6 @@ def clone_and_merge(
130123
values["source"],
131124
values["ref"],
132125
loc,
133-
dependency,
134126
use_mirrors,
135127
mirror_loc,
136128
)
@@ -140,7 +132,6 @@ def get_source(
140132
source: str,
141133
ref: str,
142134
dest: Path,
143-
repo: str,
144135
use_mirrors: bool = False,
145136
mirror_loc: Path = Path(""),
146137
) -> None:
@@ -151,26 +142,25 @@ def get_source(
151142
if ".git" in source:
152143
if use_mirrors:
153144
logger.info(
154-
f"[{datetime_str()}] Cloning {repo} from {mirror_loc} at ref {ref}"
145+
f"[{datetime_str()}] Cloning {dest.name} from {mirror_loc} at ref {ref}"
155146
)
156-
mirror_repo = repo
157-
if "jules-internal" in source:
158-
mirror_repo = "jules-internal"
147+
mirror_repo = re.split("[:/]", source)[-1]
159148
mirror_loc = Path(mirror_loc) / "MetOffice" / mirror_repo
160149
clone_repo_mirror(source, ref, mirror_loc, dest)
161150
else:
162-
logger.info(f"[{datetime_str()}] Cloning {repo} from {source} at ref {ref}")
151+
logger.info(
152+
f"[{datetime_str()}] Cloning {dest.name} from {source} at ref {ref}"
153+
)
163154
clone_repo(source, ref, dest)
164155
else:
165-
logger.info(f"[{datetime_str()}] Syncing {repo} at ref {ref}")
156+
logger.info(f"[{datetime_str()}] Syncing {dest.name} at ref {ref}")
166157
sync_repo(source, ref, dest)
167158

168159

169160
def merge_source(
170161
source: Union[Path, str],
171162
ref: str,
172163
dest: Path,
173-
repo: str,
174164
use_mirrors: bool = False,
175165
mirror_loc: Path = Path(""),
176166
) -> None:
@@ -181,17 +171,12 @@ def merge_source(
181171

182172
logger.info(
183173
f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] Merging "
184-
f"{source} at ref {ref} into {repo}"
174+
f"{source} at ref {ref} into {dest.name}"
185175
)
186176

187-
if ".git" in str(source):
188-
if use_mirrors:
189-
remote_path = Path(mirror_loc) / "MetOffice" / repo
190-
fetch = determine_mirror_fetch(source, ref)
191-
else:
192-
remote_path = source
193-
fetch = ref
194-
else:
177+
if not any(
178+
[g for g in ["https:", "git@", "localmirrors:"] if str(source).startswith(g)]
179+
):
195180
if not ref:
196181
raise Exception(
197182
f"Cannot merge local source '{source}' with empty ref.\n"
@@ -200,6 +185,14 @@ def merge_source(
200185
)
201186
remote_path = source
202187
fetch = ref
188+
elif use_mirrors:
189+
mirror_repo = re.split("[:/]", source)[-1]
190+
remote_path = Path(mirror_loc) / "MetOffice" / mirror_repo
191+
fetch = determine_mirror_fetch(source, ref)
192+
else:
193+
# Not using a clone or the mirrors
194+
remote_path = source
195+
fetch = ref
203196

204197
run_command(f"git -C {dest} remote add local {remote_path}")
205198

@@ -210,7 +203,7 @@ def merge_source(
210203
if result.returncode:
211204
unmerged_files = get_unmerged(dest)
212205
if unmerged_files:
213-
handle_merge_conflicts(source, ref, dest, repo)
206+
handle_merge_conflicts(source, ref, dest, dest.name)
214207
else:
215208
raise subprocess.CalledProcessError(
216209
result.returncode, command, result.stdout, result.stderr

github_scripts/merge_sources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def main():
8282

8383
for dependency, sources in dependencies.items():
8484
dest = args.path / dependency
85-
clone_and_merge(dependency, sources, dest, args.mirrors, args.mirror_loc)
85+
clone_and_merge(sources, dest, args.mirrors, args.mirror_loc)
8686

8787

8888
if __name__ == "__main__":

github_scripts/rose_stem_extract_source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def main() -> None:
4545

4646
for dependency, sources in dependencies.items():
4747
loc = clone_loc / dependency
48-
clone_and_merge(dependency, sources, loc, use_mirrors, mirror_loc)
48+
clone_and_merge(sources, loc, use_mirrors, mirror_loc)
4949

5050

5151
if __name__ == "__main__":

github_scripts/tests/test_get_git_sources.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ def test_merge_sources(setup_sources):
126126
"https://github.com/MetOffice/SimSys_Scripts.git",
127127
"main",
128128
target_clone,
129-
"SimSys_Scripts",
130129
)
131130
is None
132131
)

0 commit comments

Comments
 (0)