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

docs(algolia): add custom attributes to backend and core methods #9730

Merged
merged 5 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
37 changes: 34 additions & 3 deletions .github/workflows/upload-algolia-api.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,40 @@ def _create_api_record_from_method_line(base_url, method):
"objectID": f"{base_url}{anchor}",
"href": f"{base_url}{anchor}",
"title": name,
"text": desc,
"crumbs": ["Expression API", "API", f"{section} expressions"],
"backend": "core",
"core": 1,
"crumbs": ["Expression API", "API", f"{section} expression"],
}
if desc:
record["text"] = desc

return record


def adjust_backend_custom_attributes(backend_records):
"""Adjusts attributes of the Algolia records.

Two custom attribute changes:
One is the name of the backend, which we can possibly use for grouping
or filtering results.

The other is a marker of whether the record is part of the core
expression API, which we can use to sort results so that generic table
expressions appear above backend-specific ones in the case of
name-collisions.

We also strip out the "text" attribute if it's empty
"""
backend_name = backend_records[0]["title"].split(".", 1)[0]
for record in backend_records:
record["backend"] = backend_name
record["core"] = 0
if not record["text"]:
record.pop("text")

return backend_records


def main():
client = SearchClient.create(app_id, api_key)
index = client.init_index(index_name)
Expand Down Expand Up @@ -106,8 +133,12 @@ def main():
# Here, we load those records and upload them to the Algolia index
records = []
for record_json in glob.glob("docs/backends/*.json"):
print(f"Loading {record_json} methods...") # noqa:T201
with open(record_json) as f:
records.extend(json.load(f))
backend_records = json.load(f)
backend_records = adjust_backend_custom_attributes(backend_records)
records.extend(backend_records)
print(f"Uploading {len(records)} records to {index.name=}") # noqa:T201
index.save_objects(records)


Expand Down
6 changes: 5 additions & 1 deletion docs/backends/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ def find_member_with_docstring(member):
return member

cls = member.parent
for base in cls.resolved_bases:
resolved_bases = cls.resolved_bases
# If we're a SQLBackend (likely) then also search through to `BaseBackend``
if (sqlbackend := resolved_bases[0]).name == "SQLBackend":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a more generic fix for this, like altering the lookup code to traverse the class hierarchy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I think it's upstream in quartodoc. I'm going to take a peak at what's involved

resolved_bases.extend(sqlbackend.resolved_bases)
for base in resolved_bases:
try:
parent_member = get_callable(base, member.name)
except KeyError:
Expand Down