-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into andrew/clippy
- Loading branch information
Showing
65 changed files
with
3,312 additions
and
755 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
d5e444d0a71409ae3701d4249ad877f1fb9e2235 # introduced `rustfmt.toml` and ran formatter; ignoring large formatting changes | ||
45e2944e252ccdd563dc20edd9b29762e05cec1d # auto-fix prefer `Self` over explicit type |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""This module is used for Sphinx documentation only. We procedurally generate Python functions to allow | ||
Sphinx to generate documentation pages for every SQL function. | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
from inspect import Parameter as _Parameter | ||
from inspect import Signature as _Signature | ||
|
||
from daft.daft import list_sql_functions as _list_sql_functions | ||
|
||
|
||
def _create_sql_function(func_name: str, docstring: str, arg_names: list[str]): | ||
def sql_function(*args, **kwargs): | ||
raise NotImplementedError("This function is for documentation purposes only and should not be called.") | ||
|
||
sql_function.__name__ = func_name | ||
sql_function.__qualname__ = func_name | ||
sql_function.__doc__ = docstring | ||
sql_function.__signature__ = _Signature([_Parameter(name, _Parameter.POSITIONAL_OR_KEYWORD) for name in arg_names]) # type: ignore[attr-defined] | ||
|
||
# Register the function in the current module | ||
globals()[func_name] = sql_function | ||
|
||
|
||
__all__ = [] | ||
|
||
for sql_function_stub in _list_sql_functions(): | ||
_create_sql_function(sql_function_stub.name, sql_function_stub.docstring, sql_function_stub.arg_names) | ||
__all__.append(sql_function_stub.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ API Documentation | |
Table of Contents <self> | ||
creation | ||
dataframe | ||
sql | ||
expressions | ||
schema | ||
datatype | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
SQL | ||
=== | ||
|
||
.. autofunction:: daft.sql | ||
|
||
.. autofunction:: daft.sql_expr | ||
|
||
SQL Functions | ||
------------- | ||
|
||
This is a full list of functions that can be used from within SQL. | ||
|
||
|
||
.. sql-autosummary:: | ||
:toctree: doc_gen/sql_funcs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import inspect | ||
import os | ||
|
||
from sphinx.ext.autosummary import Autosummary | ||
from sphinx.util import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
TOCTREE = "doc_gen/sql_funcs" | ||
SQL_MODULE_NAME = "daft.sql._sql_funcs" | ||
|
||
STUB_TEMPLATE = """ | ||
.. currentmodule:: None | ||
.. autofunction:: {module_name}.{name} | ||
""" | ||
|
||
|
||
class SQLAutosummary(Autosummary): | ||
def run(self): | ||
func_names = get_sql_func_names() | ||
# Run the normal autosummary stuff, override self.content | ||
self.content = [f"~{SQL_MODULE_NAME}.{f}" for f in func_names] | ||
nodes = super().run() | ||
return nodes | ||
|
||
def get_sql_module_name(self): | ||
return self.arguments[0] | ||
|
||
|
||
def get_sql_func_names(): | ||
# Import the SQL functions module | ||
module = __import__(SQL_MODULE_NAME, fromlist=[""]) | ||
|
||
names = [] | ||
for name, obj in inspect.getmembers(module): | ||
if inspect.isfunction(obj) and not name.startswith("_"): | ||
names.append(name) | ||
|
||
return names | ||
|
||
|
||
def generate_stub(name: str): | ||
"""Generates a stub string for a SQL function""" | ||
stub = name + "\n" | ||
stub += "=" * len(name) + "\n\n" | ||
stub += STUB_TEMPLATE.format(module_name=SQL_MODULE_NAME, name=name) | ||
return stub | ||
|
||
|
||
def generate_files(app): | ||
# Determine where to write .rst files to | ||
output_dir = os.path.join(app.srcdir, "api_docs", TOCTREE) | ||
os.makedirs(output_dir, exist_ok=True) | ||
|
||
# Write stubfiles | ||
func_names = get_sql_func_names() | ||
for name in func_names: | ||
stub_content = generate_stub(name) | ||
filename = f"{SQL_MODULE_NAME}.{name}.rst" | ||
filepath = os.path.join(output_dir, filename) | ||
with open(filepath, "w") as f: | ||
f.write(stub_content) | ||
|
||
# HACK: Not sure if this is ok? | ||
app.env.found_docs.add(filepath) | ||
|
||
|
||
def setup(app): | ||
app.add_directive("sql-autosummary", SQLAutosummary) | ||
|
||
# Generate and register files when the builder is initialized | ||
app.connect("builder-inited", generate_files) | ||
|
||
return { | ||
"version": "0.1", | ||
"parallel_read_safe": True, | ||
"parallel_write_safe": True, | ||
} |
Oops, something went wrong.