From b7d390f9630b638aa8c76862d4f3c8cba21f0268 Mon Sep 17 00:00:00 2001 From: Peter Gadfort Date: Sat, 5 Aug 2023 18:22:46 -0400 Subject: [PATCH] first stab at getting reports included --- scgallery/__init__.py | 8 ++++++-- scgallery/gallery.py | 38 +++++++++++++++++++++++++++++++++++--- scgallery/report.py | 15 +++++---------- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/scgallery/__init__.py b/scgallery/__init__.py index f1a6700..952ea41 100644 --- a/scgallery/__init__.py +++ b/scgallery/__init__.py @@ -4,11 +4,15 @@ # This only exists in installations __version__ = None -from .gallery import Gallery import os root = os.path.dirname(__file__) +gallery_template = os.path.join(root, 'templates') + +from .gallery import Gallery + __all__ = [ "Gallery", - "root" + "root", + "gallery_template" ] diff --git a/scgallery/gallery.py b/scgallery/gallery.py index baea38a..3c7fd5a 100755 --- a/scgallery/gallery.py +++ b/scgallery/gallery.py @@ -11,6 +11,7 @@ from scgallery.designs import all_designs as sc_all_designs from scgallery.rules import check_rules +from scgallery import report class Gallery: @@ -34,6 +35,7 @@ def __init__(self, path=None): } self.__status = [] + self.__report_chips = {} self.__jobname = None self.__resume = False @@ -189,6 +191,12 @@ def __finalize(self, design, chip): if not chip: return + report_data = { + "chip": chip, + "platform": chip.get('option', 'pdk') + } + self.__report_chips.setdefault(design, []).append(report_data) + chip.summary() rules_files = self.__designs[design]['rules'] @@ -213,16 +221,18 @@ def __finalize(self, design, chip): elif rules_files: chip.logger.info("Rules match") - self.__copy_chip_data(chip) + self.__copy_chip_data(chip, report_data) - def __copy_chip_data(self, chip): + def __copy_chip_data(self, chip, report_data): jobname = chip.get('option', 'jobname') png = os.path.join(chip._getworkdir(), f'{chip.design}.png') file_root = f'{chip.design}_{jobname}' if os.path.isfile(png): - shutil.copy(png, os.path.join(self.gallery(), f'{file_root}.png')) + img_path = os.path.join(self.gallery(), f'{file_root}.png') + shutil.copy(png, img_path) + report_data["path"] = img_path chip.archive(include=['reports', '*.log'], archive_name=os.path.join(self.gallery(), f'{file_root}.tgz')) @@ -231,6 +241,7 @@ def run(self): os.makedirs(self.gallery(), exist_ok=True) self.__status.clear() + self.__report_chips.clear() regular_jobs = [] runner_jobs = [] @@ -290,6 +301,27 @@ def _run_remote(chip, design): except Exception: pass + # Generate overview + overview_data = [] + print(self.__report_chips) + for design, design_datas in self.__report_chips.items(): + for design_data in design_datas: + if 'path' not in design_data: + continue + overview_data.append({ + "path": design_data["path"], + "platform": design_data["platform"], + "design": design + }) + report.generate_overview(overview_data, os.path.join(self.gallery(), "overview.html")) + + # Generate detailed view + detail_data = {} + for design, design_datas in self.__report_chips.items(): + for design_data in design_datas: + detail_data.setdefault(design, []).append(design_data['chip']) + report.generate_details(detail_data, os.path.join(self.gallery(), "details.html")) + self.summary() return not self.__status diff --git a/scgallery/report.py b/scgallery/report.py index 78862b3..33cc7a6 100644 --- a/scgallery/report.py +++ b/scgallery/report.py @@ -1,11 +1,11 @@ from jinja2 import Environment, FileSystemLoader -from scgallery import root +from scgallery import gallery_template import os import glob import base64 import siliconcompiler -jinja2_env = Environment(loader=FileSystemLoader(os.path.join(root, 'templates'))) +jinja2_env = Environment(loader=FileSystemLoader(gallery_template)) encoding = 'utf-8' @@ -20,7 +20,7 @@ def __get_favicon(): return __load_image(os.path.join(os.path.dirname(siliconcompiler.__file__), 'data', 'logo.png')) -def generate_overview(images_data): +def generate_overview(images_data, path): platforms = set() designs = set() data = {} @@ -31,7 +31,7 @@ def generate_overview(images_data): data.setdefault(image['platform'], {})[image['design']] = image image['data'] = __load_image(image['path']) - with open('overview.html', 'w', encoding=encoding) as wf: + with open(path, 'w', encoding=encoding) as wf: wf.write(jinja2_env.get_template('overview.html').render( sc_version=siliconcompiler.__version__, favicon=__get_favicon(), @@ -94,12 +94,7 @@ def __generate_design_detail(chips): images=images_data) -def generate_details(chips): - designs = {} - for design_chips in chips: - for chip in design_chips: - designs.setdefault(chip.design, []).append(chip) - +def generate_details(designs, path): pages = {} for design, design_chips in designs.items(): page_data = __generate_design_detail(design_chips)