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
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
15 changes: 9 additions & 6 deletions indexing/INDEX_template.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
{% for prefix, data in content.items()%}
{% for prefix, data in content.items() %}

<details>

<summary>{{ prefix }}</summary>

{% 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 %}
Expand Down
46 changes: 30 additions & 16 deletions indexing/generate_index.py
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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]

Expand All @@ -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}")
Expand All @@ -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,
)
Expand Down