Skip to content

Commit

Permalink
docs(backends): implement gen_matrix script
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and kszucs committed Mar 10, 2022
1 parent be53c4f commit 802804a
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 9 deletions.
3 changes: 3 additions & 0 deletions docs/backends/99_support_matrix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Operation Support Matrix

<div class="support-matrix" markdown>
24 changes: 24 additions & 0 deletions docs/stylesheets/extra.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,27 @@
.download-button {
text-align: center;
}
.support-matrix .md-typeset__table {
display: table;
min-width: 100%;
}
.support-matrix .md-typeset table:not([class]) {
display: table;
min-width: 100%;
}

.md-typeset__scrollwrap {
overflow-x: unset;
}
body > div.md-container > main > div > div.md-content > article > div > div > div > table > thead > tr > th:nth-child(1) {
min-width: 9.2rem;
}

.md-typeset table:not([class]) th {
text-align: center;
padding: 0.9375em 0.5em;
}
.md-typeset table:not([class]) td {
text-align: center;
padding: 0.9375em 0.5em;
}
70 changes: 70 additions & 0 deletions gen_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import collections
import importlib
import operator
from pathlib import Path

import mkdocs_gen_files
import tabulate
import tomli

import ibis
import ibis.expr.operations as ops


def get_backends():
pyproject = tomli.loads(Path("pyproject.toml").read_text())
backends = pyproject["tool"]["poetry"]["plugins"]["ibis.backends"]
return [
(backend, getattr(ibis, backend))
for backend in sorted(backends.keys())
]


def get_leaf_classes(op):
for child_class in op.__subclasses__():
if not child_class.__subclasses__():
yield child_class
else:
yield from get_leaf_classes(child_class)


with mkdocs_gen_files.open(
Path("backends") / "99_support_matrix.md",
"w",
) as f:
print("# Operation Support Matrix", file=f)
print('<div class="support-matrix" markdown>', file=f)

support = collections.defaultdict(list)

possible_ops = sorted(
set(get_leaf_classes(ops.ValueOp)), key=operator.attrgetter("__name__")
)

for op in possible_ops:
support["operation"].append(f"`{op.__name__}`")
for name, backend in get_backends():
try:
translator = backend.compiler.translator_class
ops = translator._registry.keys() | translator._rewrites.keys()
supported = op in ops
except AttributeError:
if name in ("dask", "pandas"):
execution = importlib.import_module(
f"ibis.backends.{name}.execution"
)
execute_node = execution.execute_node
ops = {op for op, *_ in execute_node.funcs.keys()}
supported = op in ops or any(
issubclass(op, other) for other in ops
)
else:
continue
if supported:
support[name].append(":material-check-decagram:{ .verified }")
else:
support[name].append(":material-cancel:{ .cancel }")

table = tabulate.tabulate(support, headers="keys", tablefmt="pipe")
print(table, file=f)
print('</div>', file=f)
19 changes: 10 additions & 9 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ plugins:
- exclude:
glob:
- backends/template.md
- gen-files:
scripts:
- gen_matrix.py
- mkdocstrings:
enable_inventory: true
handlers:
Expand Down Expand Up @@ -75,18 +78,17 @@ plugins:
show_root_heading: true
show_root_toc_entry: true
show_source: false
- mkdocs-jupyter:
execute: true
ignore:
- "*.py"
execute_ignore: "tutorial/*Geospatial*.ipynb"
include_source: true
theme: dark
# - mkdocs-jupyter:
# execute: true
# ignore:
# - "*.py"
# execute_ignore: "tutorial/*Geospatial*.ipynb"
# include_source: true
# theme: dark
- literate-nav
markdown_extensions:
- admonition
- attr_list
- codehilite
- def_list
- footnotes
- md_in_html
Expand All @@ -108,7 +110,6 @@ markdown_extensions:
- pymdownx.superfences
- pymdownx.tabbed:
alternate_style: true
- tables
- toc
extra:
project_name: "ibis"
Expand Down
6 changes: 6 additions & 0 deletions poetry-overrides.nix
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,10 @@ self: super:
];
}
);

mkdocs-gen-files = super.mkdocs-gen-files.overridePythonAttrs (attrs: {
nativeBuildInputs = (attrs.nativeBuildInputs or [ ]) ++ [
self.poetry
];
});
}
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ sqlalchemy = ">=1.3,<1.5"
types-requests = ">=2.27.8,<3"
sqlparse = "^0.4.2"
pytest-repeat = "^0.9.1"
mkdocs-gen-files = "^0.3.4"

[tool.poetry.extras]
all = [
Expand Down

0 comments on commit 802804a

Please sign in to comment.