From 802804ace459d3d460e615bcb610aa8e348f8a21 Mon Sep 17 00:00:00 2001
From: Phillip Cloud <417981+cpcloud@users.noreply.github.com>
Date: Wed, 2 Mar 2022 17:10:03 -0500
Subject: [PATCH] docs(backends): implement gen_matrix script
---
docs/backends/99_support_matrix.md | 3 ++
docs/stylesheets/extra.css | 24 ++++++++++
gen_matrix.py | 70 ++++++++++++++++++++++++++++++
mkdocs.yml | 19 ++++----
poetry-overrides.nix | 6 +++
pyproject.toml | 1 +
6 files changed, 114 insertions(+), 9 deletions(-)
create mode 100644 docs/backends/99_support_matrix.md
create mode 100644 gen_matrix.py
diff --git a/docs/backends/99_support_matrix.md b/docs/backends/99_support_matrix.md
new file mode 100644
index 000000000000..a8fa2ec3224c
--- /dev/null
+++ b/docs/backends/99_support_matrix.md
@@ -0,0 +1,3 @@
+# Operation Support Matrix
+
+
diff --git a/docs/stylesheets/extra.css b/docs/stylesheets/extra.css
index 0fcd4b2d0b9c..2191f57efcce 100644
--- a/docs/stylesheets/extra.css
+++ b/docs/stylesheets/extra.css
@@ -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;
+}
diff --git a/gen_matrix.py b/gen_matrix.py
new file mode 100644
index 000000000000..23de1cde4dcf
--- /dev/null
+++ b/gen_matrix.py
@@ -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('
', 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('
', file=f)
diff --git a/mkdocs.yml b/mkdocs.yml
index 3bb094a3b35e..8297497fa894 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -30,6 +30,9 @@ plugins:
- exclude:
glob:
- backends/template.md
+ - gen-files:
+ scripts:
+ - gen_matrix.py
- mkdocstrings:
enable_inventory: true
handlers:
@@ -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
@@ -108,7 +110,6 @@ markdown_extensions:
- pymdownx.superfences
- pymdownx.tabbed:
alternate_style: true
- - tables
- toc
extra:
project_name: "ibis"
diff --git a/poetry-overrides.nix b/poetry-overrides.nix
index 8a3acaadd8b1..af24aaa0b7ce 100644
--- a/poetry-overrides.nix
+++ b/poetry-overrides.nix
@@ -80,4 +80,10 @@ self: super:
];
}
);
+
+ mkdocs-gen-files = super.mkdocs-gen-files.overridePythonAttrs (attrs: {
+ nativeBuildInputs = (attrs.nativeBuildInputs or [ ]) ++ [
+ self.poetry
+ ];
+ });
}
diff --git a/pyproject.toml b/pyproject.toml
index eba729a39d06..90aa4b34a386 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -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 = [