Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 6 additions & 28 deletions github_scripts/suite_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@

import re
import os
import shutil
import sqlite3
import subprocess
import yaml
from collections import defaultdict
from pathlib import Path
from typing import Dict, List, Optional, Set, Union
from git_bdiff import GitBDiff, GitInfo
from get_git_sources import clone_repo, sync_repo


class SuiteData:
Expand All @@ -36,12 +34,12 @@ class SuiteData:
"-v-",
)

def __init__(self, suite_path=None) -> None:
def __init__(self, suite_path: Path = None) -> None:
self.dependencies = {}
self.rose_data = {}
self.suite_path = suite_path
self.source_root = suite_path / "share" / "source"
self.task_states = {}
self.temp_directory = None

def get_um_failed_configs(self) -> Set[str]:
"""
Expand All @@ -65,7 +63,7 @@ def read_um_section(self, change: str) -> str:
"""
Read through a UM file searching for line
"""
change = self.temp_directory / "um" / change
change = self.source_root / "um" / change
lines = change.read_text()
lines = lines.lower()
try:
Expand Down Expand Up @@ -118,7 +116,7 @@ def get_um_owners(self, filename: str) -> Dict:
Read UM Code Owners file and write to a dictionary
"""

fpath = self.temp_directory / "um" / filename
fpath = self.source_root / "um" / filename
owners_text = fpath.read_text()

in_owners = False
Expand Down Expand Up @@ -179,7 +177,7 @@ def populate_gitbdiff(self) -> None:
if not data["gitinfo"].is_main():
parent = "main"
self.dependencies[dependency]["gitbdiff"] = GitBDiff(
repo=self.temp_directory / dependency, parent=parent
repo=self.source_root / dependency, parent=parent
).files()
else:
self.dependencies[dependency]["gitbdiff"] = []
Expand All @@ -191,23 +189,9 @@ def populate_gitinfo(self) -> None:

for dependency in self.dependencies:
self.dependencies[dependency]["gitinfo"] = GitInfo(
self.temp_directory / dependency
self.source_root / dependency
)

def clone_sources(self) -> None:
"""
Clone the sources defined in the dependencies file, to allow reading of files
and creation of diffs.
If the source is not a github url, then copy it using rsync
"""

for dependency, data in self.dependencies.items():
loc = self.temp_directory / dependency
if data["source"].endswith(".git"):
clone_repo(data["source"], data["ref"], loc)
else:
sync_repo(data["source"], data["ref"], loc)

def determine_primary_source(self) -> str:
"""
Work out what repo launched the suite based on the what sources are available in
Expand Down Expand Up @@ -418,9 +402,3 @@ def run_command(
)
if rval:
return result

def cleanup(self) -> None:
"""
Remove self.temp_directory
"""
shutil.rmtree(self.temp_directory)
19 changes: 8 additions & 11 deletions github_scripts/suite_report_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from collections import defaultdict
from contextlib import contextmanager
from pathlib import Path
from tempfile import mkdtemp
from typing import Dict, List, Set, Tuple

from suite_data import SuiteData
Expand Down Expand Up @@ -79,8 +78,6 @@ def __init__(self, suite_path: Path) -> None:
self.rose_data: Dict[str, str] = self.read_rose_conf()
self.dependencies: Dict[str, Dict] = self.read_dependencies()
self.primary_source: str = self.determine_primary_source()
self.temp_directory = Path(mkdtemp())
self.clone_sources()
self.populate_gitinfo()
self.populate_gitbdiff()
self.trac_log = []
Expand All @@ -90,7 +87,7 @@ def parse_local_source(self, source: str) -> Tuple[str, str]:
Find the branch name or hash and remote reference for a given source
"""

source = self.temp_directory / source
source = self.source_root / source

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

args, _ = parser.parse_known_args()

# Check log file is writable, set as None if not (this will output to stdout)
if args.log_path and not os.access(args.log_path, os.W_OK):
# Default log_path as suite_path if not set, then check log file is writable
# set as None if not (this will output to stdout)
if not args.log_path:
args.log_path = args.suite_path
if not os.access(args.log_path, os.W_OK):
args.log_path = None

return args
Expand All @@ -376,11 +376,8 @@ def main() -> None:
args = parse_args()

suite_report = SuiteReport(args.suite_path)
try:
suite_report.create_log()
suite_report.write_log(args.log_path)
finally:
suite_report.cleanup()
suite_report.create_log()
suite_report.write_log(args.log_path)


if __name__ == "__main__":
Expand Down
Loading