Skip to content

Commit 8e347b5

Browse files
Update suite_report to use cylc-run sources (#224)
1 parent fe10e71 commit 8e347b5

2 files changed

Lines changed: 14 additions & 39 deletions

File tree

github_scripts/suite_data.py

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@
1010

1111
import re
1212
import os
13-
import shutil
1413
import sqlite3
1514
import subprocess
1615
import yaml
1716
from collections import defaultdict
1817
from pathlib import Path
1918
from typing import Dict, List, Optional, Set, Union
2019
from git_bdiff import GitBDiff, GitInfo
21-
from get_git_sources import clone_repo, sync_repo
2220

2321

2422
class SuiteData:
@@ -36,12 +34,12 @@ class SuiteData:
3634
"-v-",
3735
)
3836

39-
def __init__(self, suite_path=None) -> None:
37+
def __init__(self, suite_path: Path = None) -> None:
4038
self.dependencies = {}
4139
self.rose_data = {}
4240
self.suite_path = suite_path
41+
self.source_root = suite_path / "share" / "source"
4342
self.task_states = {}
44-
self.temp_directory = None
4543

4644
def get_um_failed_configs(self) -> Set[str]:
4745
"""
@@ -65,7 +63,7 @@ def read_um_section(self, change: str) -> str:
6563
"""
6664
Read through a UM file searching for line
6765
"""
68-
change = self.temp_directory / "um" / change
66+
change = self.source_root / "um" / change
6967
lines = change.read_text()
7068
lines = lines.lower()
7169
try:
@@ -118,7 +116,7 @@ def get_um_owners(self, filename: str) -> Dict:
118116
Read UM Code Owners file and write to a dictionary
119117
"""
120118

121-
fpath = self.temp_directory / "um" / filename
119+
fpath = self.source_root / "um" / filename
122120
owners_text = fpath.read_text()
123121

124122
in_owners = False
@@ -179,7 +177,7 @@ def populate_gitbdiff(self) -> None:
179177
if not data["gitinfo"].is_main():
180178
parent = "main"
181179
self.dependencies[dependency]["gitbdiff"] = GitBDiff(
182-
repo=self.temp_directory / dependency, parent=parent
180+
repo=self.source_root / dependency, parent=parent
183181
).files()
184182
else:
185183
self.dependencies[dependency]["gitbdiff"] = []
@@ -191,23 +189,9 @@ def populate_gitinfo(self) -> None:
191189

192190
for dependency in self.dependencies:
193191
self.dependencies[dependency]["gitinfo"] = GitInfo(
194-
self.temp_directory / dependency
192+
self.source_root / dependency
195193
)
196194

197-
def clone_sources(self) -> None:
198-
"""
199-
Clone the sources defined in the dependencies file, to allow reading of files
200-
and creation of diffs.
201-
If the source is not a github url, then copy it using rsync
202-
"""
203-
204-
for dependency, data in self.dependencies.items():
205-
loc = self.temp_directory / dependency
206-
if data["source"].endswith(".git"):
207-
clone_repo(data["source"], data["ref"], loc)
208-
else:
209-
sync_repo(data["source"], data["ref"], loc)
210-
211195
def determine_primary_source(self) -> str:
212196
"""
213197
Work out what repo launched the suite based on the what sources are available in
@@ -418,9 +402,3 @@ def run_command(
418402
)
419403
if rval:
420404
return result
421-
422-
def cleanup(self) -> None:
423-
"""
424-
Remove self.temp_directory
425-
"""
426-
shutil.rmtree(self.temp_directory)

github_scripts/suite_report_git.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from collections import defaultdict
1717
from contextlib import contextmanager
1818
from pathlib import Path
19-
from tempfile import mkdtemp
2019
from typing import Dict, List, Set, Tuple
2120

2221
from suite_data import SuiteData
@@ -79,8 +78,6 @@ def __init__(self, suite_path: Path) -> None:
7978
self.rose_data: Dict[str, str] = self.read_rose_conf()
8079
self.dependencies: Dict[str, Dict] = self.read_dependencies()
8180
self.primary_source: str = self.determine_primary_source()
82-
self.temp_directory = Path(mkdtemp())
83-
self.clone_sources()
8481
self.populate_gitinfo()
8582
self.populate_gitbdiff()
8683
self.trac_log = []
@@ -90,7 +87,7 @@ def parse_local_source(self, source: str) -> Tuple[str, str]:
9087
Find the branch name or hash and remote reference for a given source
9188
"""
9289

93-
source = self.temp_directory / source
90+
source = self.source_root / source
9491

9592
branch_name = self.run_command(
9693
f"git -C {source} branch --show-current", rval=True
@@ -361,8 +358,11 @@ def parse_args() -> argparse.Namespace:
361358

362359
args, _ = parser.parse_known_args()
363360

364-
# Check log file is writable, set as None if not (this will output to stdout)
365-
if args.log_path and not os.access(args.log_path, os.W_OK):
361+
# Default log_path as suite_path if not set, then check log file is writable
362+
# set as None if not (this will output to stdout)
363+
if not args.log_path:
364+
args.log_path = args.suite_path
365+
if not os.access(args.log_path, os.W_OK):
366366
args.log_path = None
367367

368368
return args
@@ -376,11 +376,8 @@ def main() -> None:
376376
args = parse_args()
377377

378378
suite_report = SuiteReport(args.suite_path)
379-
try:
380-
suite_report.create_log()
381-
suite_report.write_log(args.log_path)
382-
finally:
383-
suite_report.cleanup()
379+
suite_report.create_log()
380+
suite_report.write_log(args.log_path)
384381

385382

386383
if __name__ == "__main__":

0 commit comments

Comments
 (0)