Skip to content

Commit

Permalink
first stab at getting reports included
Browse files Browse the repository at this point in the history
  • Loading branch information
gadfort committed Aug 5, 2023
1 parent 7a67aa8 commit b7d390f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
8 changes: 6 additions & 2 deletions scgallery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
38 changes: 35 additions & 3 deletions scgallery/gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -34,6 +35,7 @@ def __init__(self, path=None):
}

self.__status = []
self.__report_chips = {}

self.__jobname = None
self.__resume = False
Expand Down Expand Up @@ -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']
Expand All @@ -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'))
Expand All @@ -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 = []
Expand Down Expand Up @@ -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

Expand Down
15 changes: 5 additions & 10 deletions scgallery/report.py
Original file line number Diff line number Diff line change
@@ -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'


Expand All @@ -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 = {}
Expand All @@ -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(),
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b7d390f

Please sign in to comment.