diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 94182d7..466c047 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -54,7 +54,7 @@ jobs: - name: install iris-grib run: | source $CONDA/bin/activate base - conda install -y -c conda-forge iris-grib + conda install -q -y -c conda-forge iris-grib - name: generate index working-directory: indexing run: | diff --git a/indexing/INDEX_template.md b/indexing/INDEX_template.md index 0b0da8d..4a7687c 100755 --- a/indexing/INDEX_template.md +++ b/indexing/INDEX_template.md @@ -1,18 +1,21 @@ -{% for prefix, data in content.items()%} +{% for prefix, data in content.items() %}
{{ prefix }} - {% for filepath, link_path, cube_strs, warnings, exceptions in data %} - # [{{ filepath }}]({{ link_path }}) + {% for filepath, link_path, items, is_png, warnings, exceptions in data|sort(attribute="path") %} + #### [{{ filepath }}]({{ link_path }}) - {% for cube_str in cube_strs %} + {% if is_png %} + ![{{ link_path }}]({{ link_path }}) + {% else %} + {% for item in items %} ``` - {{ cube_str | indent(first=False) }} + {{ item | indent(first=False) }} ``` {% endfor %} - + {% endif %} {%if warnings %} ``` {% for warning_str in warnings %} diff --git a/indexing/generate_index.py b/indexing/generate_index.py index e432477..e5c0039 100644 --- a/indexing/generate_index.py +++ b/indexing/generate_index.py @@ -1,13 +1,13 @@ +import warnings from collections import defaultdict -from jinja2 import Environment, FileSystemLoader -import os from pathlib import Path from typing import List, NamedTuple -import warnings import iris +from jinja2 import Environment, FileSystemLoader +from PIL import Image -IGNORE_SUFFIXES = [".py", ".rst", ".txt", ".md"] +IGNORE_SUFFIXES = [".cdl", ".gz", ".md", ".npz", ".py", ".rst", ".txt"] TEST_DATA_ROOT = Path(__file__).parent / Path("../test_data") TEMPLATE_FILE = Path(__file__).parent / Path("INDEX_template.md") @@ -17,7 +17,8 @@ class FileInfo(NamedTuple): path: Path link_path: Path - cube_strs: List[str] + items: List[str] + is_png: bool warnings: List[str] exceptions: List[str] @@ -33,22 +34,34 @@ def getDataFilepaths(path: Path) -> List[Path]: def getFileInfos(filepaths: List[Path]) -> List[FileInfo]: file_infos = defaultdict(list) - for filepath in filepaths: + for filepath in sorted(filepaths): - cube_strs = [] + items = [] + is_png = False warning_list = [] exception_list = [] with warnings.catch_warnings(record=True) as ww: + print(f"{str(filepath)}") try: - cubelist = iris.load(str(filepath)) - except Exception as e: - print(f"Error loading {filepath}") - exception_list.append(f"{type(e).__name__}: {e}") - print(exception_list[-1] + "\n") - else: - for cube in cubelist: - cube_strs.append(str(cube)) + image = Image.open(str(filepath)) + if image.format == "PNG": + is_png = True + items = None + image.close() + except IOError: + pass + + if not is_png: + try: + cubelist = iris.load(str(filepath)) + except Exception as e: + print(f"Error loading {filepath!r}") + exception_list.append(f"{type(e).__name__}: {e}") + print(exception_list[-1] + "\n") + else: + for cube in cubelist: + items.append(str(cube)) for warning in ww: warning_list.append(f"{warning._category_name}: {warning.message}") @@ -59,7 +72,8 @@ def getFileInfos(filepaths: List[Path]) -> List[FileInfo]: FileInfo( filepath.relative_to(TEST_DATA_ROOT), filepath.relative_to(OUTPUT_FILE.parent), - cube_strs, + items, + is_png, warning_list, exception_list, )