Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic list with overviews of inlcuded area definitions for the documentation #2167

Merged
merged 21 commits into from
Jun 13, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ doc/source/_build/*
satpy/version.py
doc/source/api/*.rst
doc/source/reader_table.rst
doc/source/area_def_list.rst

# lock files
*.lock
Expand Down
1 change: 1 addition & 0 deletions doc/rtd_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies:
- xarray
- zarr
- xarray-datatree
- cartopy
- pip:
- graphviz
- pytest-lazy-fixtures
Expand Down
11 changes: 11 additions & 0 deletions doc/source/_static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,15 @@ $(document).ready( function () {
},
"order": [[0, 'asc']]
} );

$('table.area-table').DataTable( {
"paging": true,
"pageLength": 15,
"layout": {
'topStart': 'info',
'topEnd': 'search',
'bottomEnd': 'paging',
'bottomStart': null
}
} );
} );
34 changes: 31 additions & 3 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@
sys.path.append(os.path.abspath("../../"))
sys.path.append(os.path.abspath(os.path.dirname(__file__)))

from reader_table import generate_reader_table # noqa: E402
from pyresample.area_config import ( # noqa: E402
_create_area_def_from_dict,
_read_yaml_area_file_content,
generate_area_def_rst_list,
)
from reader_table import generate_reader_table, rst_table_header, rst_table_row # noqa: E402

import satpy # noqa: E402
from satpy.resample import get_area_file # noqa: E402

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -80,6 +86,26 @@ def __getattr__(cls, name):
with open("reader_table.rst", mode="w") as f:
f.write(generate_reader_table())

# create table from area definition yaml file
area_file = get_area_file()[0]

area_dict = _read_yaml_area_file_content(area_file)
area_table = [rst_table_header("Area Definitions", header=["Name", "Description", "Projection"],
widths="auto", class_name="area-table")]

for aname, params in area_dict.items():
area = _create_area_def_from_dict(aname, params)
if not hasattr(area, "_repr_html_"):
continue

area_table.append(rst_table_row([f"`{aname}`_", area.description,
area.proj_dict.get("proj")]))

with open("area_def_list.rst", mode="w") as f:
f.write("".join(area_table))
f.write("\n\n")
f.write(generate_area_def_rst_list(area_file))

# -- General configuration -----------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be extensions
Expand Down Expand Up @@ -194,11 +220,13 @@ def __getattr__(cls, name):

html_css_files = [
"theme_overrides.css", # override wide tables in RTD theme
"https://cdn.datatables.net/v/dt/dt-2.0.0/datatables.min.css",
# "https://cdn.datatables.net/v/dt/dt-2.0.0/datatables.min.css",
"https://cdn.datatables.net/v/dt/dt-2.0.8/r-3.0.2/datatables.min.css"
]

html_js_files = [
"https://cdn.datatables.net/v/dt/dt-2.0.0/datatables.min.js",
# "https://cdn.datatables.net/v/dt/dt-2.0.0/datatables.min.js",
"https://cdn.datatables.net/v/dt/dt-2.0.8/r-3.0.2/datatables.min.js",
"main.js",
]

Expand Down
12 changes: 7 additions & 5 deletions doc/source/reader_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,31 @@
return row


def rst_table_header(name=None, header=None, header_rows=1, widths="auto"): # noqa: D417
def rst_table_header(name=None, header=None, header_rows=1, widths="auto", class_name="datatable"):
"""Create header for rst table.

Args:
name (str): Name of the table
header (list[str]): Column names
header-rows (int): Number of header rows
width (optional[list[int]]): Width of each column as a list. If not specified
header_rows (int): Number of header rows
widths (optional[list[int]]): Width of each column as a list. If not specified
defaults to auto and will therefore determined by the backend
(see <https://docutils.sourceforge.io/docs/ref/rst/directives.html#table>)
class_name (str): The CSS class name for the table. A corresponding js function should be in main.js in
in the "statis" directory.

Returns:
str
"""
if isinstance(widths, list):
widths = " ".join([str(w) for w in widths])

header = rst_table_row(header)

table_header = (f".. list-table:: {name}\n"
f" :header-rows: {header_rows}\n"
f" :widths: {widths}\n"
f" :class: datatable\n\n"
f" :class: {class_name}\n\n"

Check warning on line 66 in doc/source/reader_table.py

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Excess Number of Function Arguments

rst_table_header has 5 arguments, threshold = 4. This function has too many arguments, indicating a lack of encapsulation. Avoid adding more arguments.
f"{header}")

return table_header
Expand All @@ -74,7 +76,7 @@
str
"""
table = [rst_table_header("Satpy Readers", header=["Description", "Reader name", "Status", "fsspec support"],
widths=[45, 25, 30, 30])]
widths="auto")]

reader_configs = available_readers(as_dict=True, yaml_loader=BaseLoader)
for rc in reader_configs:
Expand Down
Loading
Loading