Skip to content

Commit

Permalink
docs: bring back backend API documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Sep 8, 2023
1 parent e9f9155 commit df981d5
Show file tree
Hide file tree
Showing 19 changed files with 171 additions and 3 deletions.
21 changes: 21 additions & 0 deletions docs/backends/_templates/api.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
```{python}
#| echo: false
#| output: asis
from _utils import get_backend, render_methods
# defined in the backend qmd, e.g., ../bigquery.qmd
module = BACKEND.lower()
backend = get_backend(module)
print(f"## `{module}.Backend` {{ #{backend.canonical_path} }}")
methods = sorted(
key for key, value in backend.members.items()
if value.is_function
if not value.name.startswith("_")
if value.name != "do_connect"
)
render_methods(backend, *methods, level=4)
```
34 changes: 32 additions & 2 deletions docs/backends/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,39 @@ def get_callable(obj, name):
return obj.functions[name]


def find_member_with_docstring(member):
"""Find the first inherited member with a docstring."""
if member.docstring is not None:
return member

cls = member.parent
for base in cls.resolved_bases:
try:
parent_member = get_callable(base, member.name)
except KeyError:
continue
else:
if parent_member.docstring is not None:
return parent_member
return member


def render_method(*, member, renderer: MdRenderer) -> Iterator[str]:
yield f"{'#' * renderer.crnt_header_level} {member.name} {{ #{member.path} }}"
yield renderer.render(member)
header_level = renderer.crnt_header_level
header = "#" * header_level
name = member.name
try:
params = renderer.render(member.parameters)
except AttributeError:
params = None
yield "\n"
yield f"{header} {name} {{ #{member.path} }}"
yield "\n"
if params is not None:
yield f"`{name}({params})`"
yield "\n"

yield renderer.render(find_member_with_docstring(member))


def render_methods(obj, *methods: str, level: int) -> None:
Expand Down
7 changes: 7 additions & 0 deletions docs/backends/bigquery.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,10 @@ gcloud auth login
For any authentication problems, or information on other ways of authenticating,
see the [`gcloud` CLI authorization
guide](https://cloud.google.com/sdk/docs/authorizing).

```{python}
#| echo: false
BACKEND = "BigQuery"
```

{{< include ./_templates/api.qmd >}}
7 changes: 7 additions & 0 deletions docs/backends/clickhouse.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,10 @@ or
con = ibis.connect("clickhouse://play:clickhouse@play.clickhouse.com:443?secure=True")
con.table("opensky")
```

```{python}
#| echo: false
BACKEND = "ClickHouse"
```

{{< include ./_templates/api.qmd >}}
7 changes: 7 additions & 0 deletions docs/backends/dask.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,10 @@ con = ibis.dask.connect() # <1>
1. Adjust connection parameters as needed.

:::

```{python}
#| echo: false
BACKEND = "Dask"
```

{{< include ./_templates/api.qmd >}}
7 changes: 7 additions & 0 deletions docs/backends/datafusion.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,10 @@ from _utils import render_methods, get_backend
backend = get_backend("datafusion")
render_methods(backend, "read_csv", "read_parquet", "read_delta", level=4)
```

```{python}
#| echo: false
BACKEND = "DataFusion"
```

{{< include ./_templates/api.qmd >}}
7 changes: 7 additions & 0 deletions docs/backends/druid.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,10 @@ passing a properly formatted Druid connection URL to `ibis.connect`
```python
con = ibis.connect("druid://localhost:8082/druid/v2/sql")
```

```{python}
#| echo: false
BACKEND = "Druid"
```

{{< include ./_templates/api.qmd >}}
7 changes: 7 additions & 0 deletions docs/backends/duckdb.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,10 @@ backend = get_backend("duckdb")
methods = [f"read_{kind}" for kind in ("csv", "parquet", "delta", "json", "in_memory", "sqlite", "postgres")]
render_methods(backend, *methods, level=4)
```

```{python}
#| echo: false
BACKEND = "DuckDB"
```

{{< include ./_templates/api.qmd >}}
7 changes: 7 additions & 0 deletions docs/backends/mssql.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,10 @@ passing a properly formatted MSSQL connection URL to `ibis.connect`
```python
con = ibis.connect(f"mssql://{user}:{password}@{host}:{port}")
```

```{python}
#| echo: false
BACKEND = "MSSQL"
```

{{< include ./_templates/api.qmd >}}
7 changes: 7 additions & 0 deletions docs/backends/mysql.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,10 @@ passing a properly formatted MySQL connection URL to `ibis.connect`
```python
con = ibis.connect(f"mysql://{user}:{password}@{host}:{port}/{database}")
```

```{python}
#| echo: false
BACKEND = "MySQL"
```

{{< include ./_templates/api.qmd >}}
7 changes: 7 additions & 0 deletions docs/backends/oracle.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,10 @@ show parameter sec_case_sensitive_logon;
If the returned value is `FALSE` then Ibis will _not_ connect.

For more information, see this [issue](https://github.com/oracle/python-oracledb/issues/26).

```{python}
#| echo: false
BACKEND = "Oracle"
```

{{< include ./_templates/api.qmd >}}
7 changes: 7 additions & 0 deletions docs/backends/pandas.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,10 @@ def add_two_with_none(x, y=None):
y = 2.0
return x + y
```

```{python}
#| echo: false
BACKEND = "Pandas"
```

{{< include ./_templates/api.qmd >}}
7 changes: 7 additions & 0 deletions docs/backends/polars.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,10 @@ methods = ("read_csv", "read_parquet", "read_delta")
backend = get_backend("polars")
render_methods(backend, *methods, level=4)
```

```{python}
#| echo: false
BACKEND = "Polars"
```

{{< include ./_templates/api.qmd >}}
7 changes: 7 additions & 0 deletions docs/backends/postgresql.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,10 @@ passing a properly formatted Postgres connection URL to `ibis.connect`
```python
con = ibis.connect(f"postgres://{user}:{password}@{host}:{port}/{database}")
```

```{python}
#| echo: false
BACKEND = "Postgres"
```

{{< include ./_templates/api.qmd >}}
7 changes: 7 additions & 0 deletions docs/backends/pyspark.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,10 @@ methods = ("read_csv", "read_parquet")
backend = get_backend("pyspark")
render_methods(backend, *methods, level=4)
```

```{python}
#| echo: false
BACKEND = "PySpark"
```

{{< include ./_templates/api.qmd >}}
7 changes: 7 additions & 0 deletions docs/backends/snowflake.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,10 @@ methods = ("read_csv", "read_parquet", "read_json")
backend = get_backend("snowflake")
render_methods(backend, *methods, level=4)
```

```{python}
#| echo: false
BACKEND = "Snowflake"
```

{{< include ./_templates/api.qmd >}}
7 changes: 7 additions & 0 deletions docs/backends/sqlite.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,10 @@ The URL can be `sqlite://` which will connect to an ephemeral in-memory database
```python
con = ibis.connect("sqlite://")
```

```{python}
#| echo: false
BACKEND = "SQLite"
```

{{< include ./_templates/api.qmd >}}
7 changes: 7 additions & 0 deletions docs/backends/trino.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,10 @@ from _utils import render_do_connect
render_do_connect("trino")
```

```{python}
#| echo: false
BACKEND = "Trino"
```

{{< include ./_templates/api.qmd >}}
7 changes: 6 additions & 1 deletion docs/styles.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
section#connection-parameters {
section#parameters {
/* scroll when child contents overflow the width */
overflow-x: auto;
}

section#parameters-1 {
/* scroll when child contents overflow the width */
overflow-x: auto;
}

0 comments on commit df981d5

Please sign in to comment.