Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions docs/admin_client/admin_client_usage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Admin Client
============
.. toctree::
:maxdepth: 2

services_
types_

..
This should be the only handwritten RST file in this directory.
Everything else should be autogenerated.
10 changes: 10 additions & 0 deletions docs/admin_client/bigtable_instance_admin.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BigtableInstanceAdmin
---------------------------------------

.. automodule:: google.cloud.bigtable.admin_v2.services.bigtable_instance_admin
:members:
:inherited-members:

.. automodule:: google.cloud.bigtable.admin_v2.services.bigtable_instance_admin.pagers
:members:
:inherited-members:
10 changes: 10 additions & 0 deletions docs/admin_client/bigtable_table_admin.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BigtableTableAdmin
------------------------------------

.. automodule:: google.cloud.bigtable.admin_v2.overlay.services.bigtable_table_admin
:members:
:inherited-members:

.. automodule:: google.cloud.bigtable.admin_v2.services.bigtable_table_admin.pagers
:members:
:inherited-members:
7 changes: 7 additions & 0 deletions docs/admin_client/services_.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Services for Google Cloud Bigtable Admin v2 API
===============================================
.. toctree::
:maxdepth: 2

bigtable_instance_admin
bigtable_table_admin
10 changes: 10 additions & 0 deletions docs/admin_client/types_.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Types for Google Cloud Bigtable Admin v2 API
============================================

.. automodule:: google.cloud.bigtable.admin_v2.types
:members:
:show-inheritance:

.. automodule:: google.cloud.bigtable.admin_v2.overlay.types
:members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Client Types

data_client/data_client_usage
classic_client/usage
admin_client/admin_client_usage
Copy link
Contributor

Choose a reason for hiding this comment

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

I probably would have preferred to have the new docs as a separate PR to keep things focused, but probably not a big deal



Changelog
Expand Down
109 changes: 85 additions & 24 deletions docs/scripts/patch_devsite_toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"""


import glob
import yaml
import os
import shutil
Expand Down Expand Up @@ -153,6 +154,81 @@ def copy_markdown(self):
f"_build/html/docfx_yaml",
)

def validate_section(self, toc):
# Make sure each rst file is listed in the toc.
items_in_toc = [
d["items"] for d in toc[0]["items"] if d["name"] == self.title and ".rst"
][0]
items_in_dir = [f for f in os.listdir(self.dir_name) if f.endswith(".rst")]
# subtract 1 for index
assert len(items_in_toc) == len(items_in_dir) - 1
for file in items_in_dir:
if file != self.index_file_name:
base_name, _ = os.path.splitext(file)
assert any(d["href"] == f"{base_name}.md" for d in items_in_toc)
# make sure the markdown files are present in the docfx_yaml directory
md_files = [d["href"] for d in items_in_toc]
for file in md_files:
assert os.path.exists(f"_build/html/docfx_yaml/{file}")


class UIDFilteredTocSection(TocSection):
def __init__(self, toc_file_path, section_name, title, uid_prefix):
"""Creates a filtered section denoted by section_name in the toc_file_path to items with the given UID prefix.

The section is then renamed to the title.
"""
current_toc = yaml.safe_load(open(toc_file_path, "r"))
self.uid_prefix = uid_prefix

# Since we are looking for a specific section_name there should only
# be one match.
section_items = [
d for d in current_toc[0]["items"] if d["name"] == section_name
][0]["items"]
filtered_items = [d for d in section_items if d["uid"].startswith(uid_prefix)]
self.items = filtered_items
self.title = title

def copy_markdown(self):
"""
No-op because we are filtering on UIDs, not markdown files.
"""
pass

def validate_section(self, toc):
uids_in_toc = set()

# A UID-filtered TOC tree looks like the following:
# - items:
# <optional> items: <more stuff>
# name: <name>
# uid: <fully qualified path to a class>
#
# Walk through the TOC tree to find all UIDs recursively.
def find_uids_in_items(items):
uids_in_toc.add(items["uid"])
for subitem in items.get("items", []):
find_uids_in_items(subitem)

items_in_toc = [d["items"] for d in toc[0]["items"] if d["name"] == self.title][
0
]
for item in items_in_toc:
find_uids_in_items(item)

# Now that we have all the UIDs, first match all of them
# with corresponding .yml files.
for uid in uids_in_toc:
assert os.path.exists(f"_build/html/docfx_yaml/{uid}.yml")

# Also validate that every uid yml file that starts with the uid_prefix
# exists in the section.
for filename in glob.glob(
f"{self.uid_prefix}*.yml", root_dir="_build/html/docfx_yaml"
):
assert filename[:-4] in uids_in_toc


def validate_toc(toc_file_path, expected_section_list, added_sections):
current_toc = yaml.safe_load(open(toc_file_path, "r"))
Expand All @@ -164,38 +240,22 @@ def validate_toc(toc_file_path, expected_section_list, added_sections):
# make sure each customs ection is in the toc
for section in added_sections:
assert section.title in found_sections
# make sure each rst file in each custom section dir is listed in the toc
for section in added_sections:
items_in_toc = [
d["items"]
for d in current_toc[0]["items"]
if d["name"] == section.title and ".rst"
][0]
items_in_dir = [f for f in os.listdir(section.dir_name) if f.endswith(".rst")]
# subtract 1 for index
assert len(items_in_toc) == len(items_in_dir) - 1
for file in items_in_dir:
if file != section.index_file_name:
base_name, _ = os.path.splitext(file)
assert any(d["href"] == f"{base_name}.md" for d in items_in_toc)
# make sure the markdown files are present in the docfx_yaml directory
for section in added_sections:
items_in_toc = [
d["items"]
for d in current_toc[0]["items"]
if d["name"] == section.title and ".rst"
][0]
md_files = [d["href"] for d in items_in_toc]
for file in md_files:
assert os.path.exists(f"_build/html/docfx_yaml/{file}")
section.validate_section(current_toc)
print("Toc validation passed")


if __name__ == "__main__":
# Add secrtions for the async_data_client and classic_client directories
toc_path = "_build/html/docfx_yaml/toc.yml"

custom_sections = [
TocSection(dir_name="data_client", index_file_name="data_client_usage.rst"),
UIDFilteredTocSection(
toc_file_path=toc_path,
section_name="Bigtable",
title="Admin Client",
uid_prefix="google.cloud.bigtable.admin_v2",
),
TocSection(dir_name="classic_client", index_file_name="usage.rst"),
]
add_sections(toc_path, custom_sections)
Expand All @@ -210,6 +270,7 @@ def validate_toc(toc_file_path, expected_section_list, added_sections):
"Changelog",
"Multiprocessing",
"Data Client",
"Admin Client",
"Classic Client",
],
added_sections=custom_sections,
Expand Down
Loading
Loading