import numpy as np
from pathlib import Path
from importlib import import_module


exclude = ['examplecells.py', 'plotstyle.py', 'spectral.py']
data_cells = []
model_cells = []
for pf in sorted(Path('.').glob('*.py'), key=lambda x: x.stem):
    if pf.name in exclude:
        continue
    print(pf.name)
    figure = import_module(pf.stem)
    if hasattr(figure, 'example_cell'):
        name = figure.example_cell
        while isinstance(name, list):
            name = name[0]
        print(f'    found example_cell:  {name}')
        data_cells.append(name)
    if hasattr(figure, 'example_cells'):
        for name in figure.example_cells:
            while isinstance(name, list):
                name = name[0]
            print(f'    found example_cells: {name}')
            data_cells.append(name)
    if hasattr(figure, 'model_cell'):
        name = figure.model_cell
        while isinstance(name, list):
            name = name[0]
        print(f'    found model_cell:    {name}')
        model_cells.append(name)
    if hasattr(figure, 'model_cells'):
        for name in figure.model_cells:
            while isinstance(name, list):
                name = name[0]
            print(f'    found model_cells:   {name}')
            model_cells.append(name)

print()
print('The following cell data are used in the plots:')
for cell in np.unique(data_cells):
    print(cell)
print()
print('The following cell models are used in the plots:')
for cell in np.unique(model_cells):
    print(cell)