-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(docs): publish Client libraries help to python reference documen… #16575
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
Open
bshaffer
wants to merge
6
commits into
googleapis:main
Choose a base branch
from
bshaffer:client-libraries-help
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9224885
feat(docs): publish Client libraries help to python reference documen…
bshaffer c9c4b27
fix tests and apply suggestions from code review
bshaffer f6fecee
fix more tests
bshaffer 1379c27
fix remaining tests
bshaffer b3e63e9
fixes for mypy
bshaffer 140e068
hopefully one last fix
bshaffer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,10 @@ | ||
| { | ||
| "name": "help", | ||
| "name_pretty": "Client libraries help", | ||
| "client_documentation": "https://cloud.google.com/python/docs/reference/help/latest", | ||
| "language": "python", | ||
| "library_type": "OTHER", | ||
| "repo": "googleapis/google-cloud-python", | ||
| "distribution_name": "help", | ||
| "codeowner_team": "@googleapis/cloud-sdk-python-team" | ||
| } |
This file contains hidden or 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,3 @@ | ||
| # Google Cloud Python Help | ||
|
|
||
| Client libraries help documentation for common support issues and general information. |
This file contains hidden or 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,104 @@ | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import argparse | ||
| import pathlib | ||
| import shutil | ||
| from typing import Dict, Union | ||
| import yaml | ||
| import pypandoc | ||
|
|
||
| def build_docfx( | ||
| current_dir: Union[str, pathlib.Path], | ||
| repo_root: Union[str, pathlib.Path], | ||
| docs_map: Dict[str, str], | ||
| ) -> None: | ||
| current_dir = pathlib.Path(current_dir) | ||
| repo_root = pathlib.Path(repo_root) | ||
| output_dir = current_dir / "docs" / "_build" | ||
|
|
||
| if output_dir.exists(): | ||
| shutil.rmtree(output_dir) | ||
| output_dir.mkdir(parents=True) | ||
|
|
||
| # Ensure pandoc is available (pypandoc will download it if not found in PATH) | ||
| try: | ||
| pypandoc.get_pandoc_version() | ||
| except OSError: | ||
| print("Pandoc not found. Downloading...") | ||
| pypandoc.download_pandoc() | ||
|
|
||
| doc_items = [] | ||
|
|
||
| for title, source in docs_map.items(): | ||
| source_path = pathlib.Path(source) | ||
| if not source_path.is_absolute(): | ||
| source_path = current_dir / source_path | ||
|
|
||
| filename = source_path.name | ||
|
|
||
| if filename.endswith(".rst"): | ||
| target_filename = filename.replace(".rst", ".md") | ||
| print(f"Converting {filename} -> {target_filename} using pandoc") | ||
| if source_path.exists(): | ||
| # Use pandoc to convert RST to GFM (GitHub Flavored Markdown) | ||
| output = pypandoc.convert_file( | ||
| str(source_path), | ||
| 'gfm', | ||
| format='rst' | ||
| ) | ||
| (output_dir / target_filename).write_text(output) | ||
| else: | ||
| print(f"Warning: Source {source_path} not found.") | ||
| (output_dir / target_filename).write_text(f"# {title}\n\nContent missing.") | ||
| href = target_filename | ||
| else: | ||
| print(f"Copying {filename}") | ||
| if source_path.exists(): | ||
| shutil.copy(source_path, output_dir / filename) | ||
| else: | ||
| print(f"Warning: Source {source_path} not found.") | ||
| (output_dir / filename).write_text(f"# {title}\n\nContent missing.") | ||
| href = filename | ||
|
|
||
| doc_items.append({"name": title, "href": href}) | ||
|
|
||
| # Create the structured TOC | ||
| toc = [ | ||
| { | ||
| "uid": "product-neutral-guides", | ||
| "name": "Client library help", | ||
| "items": doc_items | ||
| } | ||
| ] | ||
|
|
||
| # Write toc.yaml | ||
| toc_path = output_dir / "toc.yaml" | ||
| with open(toc_path, "w", encoding="utf-8") as f: | ||
| # Using block style for YAML as requested | ||
| yaml.dump(toc, f, default_flow_style=False) | ||
|
|
||
| print(f"DocFX build complete in {output_dir}") | ||
| print(f"Generated TOC: {toc}") | ||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser(description="Build DocFX documentation.") | ||
| parser.add_argument("--current-dir", required=True, help="Current package directory") | ||
| parser.add_argument("--repo-root", required=True, help="Repository root directory") | ||
| parser.add_argument("--doc", action="append", nargs=2, metavar=("TITLE", "PATH"), help="Add a document title and its source path") | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| docs_map = {title: path for title, path in args.doc} if args.doc else {} | ||
| build_docfx(args.current_dir, args.repo_root, docs_map) | ||
This file contains hidden or 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,19 @@ | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| __version__ = "1.0.0" | ||
|
|
||
| # {x-release-please-start-date} | ||
| __release_date__ = "2026-04-07" | ||
| # {x-release-please-end} |
This file contains hidden or 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,8 @@ | ||
| [mypy] | ||
| python_version = 3.9 | ||
| ignore_missing_imports = True | ||
| strict = True | ||
| disallow_untyped_decorators = False | ||
| show_error_codes = True | ||
| explicit_package_bases = True | ||
| namespace_packages = True |
This file contains hidden or 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,106 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software/ | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import pathlib | ||
| import nox | ||
|
|
||
| DEFAULT_PYTHON_VERSION = "3.14" | ||
| ALL_PYTHON = ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] | ||
| CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() | ||
| REPO_ROOT = CURRENT_DIRECTORY.parent.parent | ||
|
|
||
| # Hardcoded dictionary of documentation files. | ||
| # Format: {"Display Title": "filename.md" or absolute path} | ||
| DOCS_MAP = { | ||
| "Getting started": str(REPO_ROOT / "README.rst"), | ||
| } | ||
|
|
||
| nox.options.sessions = [ | ||
| "lint", | ||
| "lint_setup_py", | ||
| "unit", | ||
| "mypy", | ||
| "prerelease_deps", | ||
| "core_deps_from_source", | ||
| "docfx", | ||
| "docs", | ||
| ] | ||
|
|
||
| # Error if a python version is missing | ||
| nox.options.error_on_missing_interpreters = True | ||
|
|
||
| @nox.session(python=DEFAULT_PYTHON_VERSION) | ||
| def lint_setup_py(session: nox.Session) -> None: | ||
| """Verify that setup.py is valid.""" | ||
| session.install("setuptools") | ||
| session.run("python", "setup.py", "check", "--strict") | ||
|
|
||
| @nox.session(python=ALL_PYTHON) | ||
| def unit(session: nox.Session) -> None: | ||
| """Run unit tests.""" | ||
| session.install("pytest", "pytest-cov") | ||
| session.install("-e", ".") | ||
| session.run("pytest", "tests") | ||
|
|
||
| @nox.session(python=DEFAULT_PYTHON_VERSION) | ||
| def mypy(session: nox.Session) -> None: | ||
| """Run mypy.""" | ||
| session.install("mypy", "types-PyYAML") | ||
| session.install("-e", ".") | ||
| session.run("mypy", "help", "tests", "noxfile.py", "docfx_helper.py") | ||
|
|
||
| @nox.session(python=DEFAULT_PYTHON_VERSION) | ||
| def prerelease_deps(session: nox.Session) -> None: | ||
| """Run unit tests with prerelease dependencies.""" | ||
| # Since we have no dependencies, this is just a normal unit test run | ||
| # but with --pre enabled for any test tools. | ||
| session.install("pytest", "pytest-cov") | ||
| session.install("-e", ".") | ||
| session.run("pytest", "tests") | ||
|
|
||
| @nox.session(python=DEFAULT_PYTHON_VERSION) | ||
| def core_deps_from_source(session: nox.Session) -> None: | ||
| """Run unit tests with core dependencies installed from source.""" | ||
| # We don't depend on core, so we just run unit tests. | ||
| session.install("pytest", "pytest-cov") | ||
| session.install("-e", ".") | ||
| session.run("pytest", "tests") | ||
|
|
||
| @nox.session(python=DEFAULT_PYTHON_VERSION) | ||
| def lint(session: nox.Session) -> None: | ||
| """Run linters.""" | ||
| session.install("ruff") | ||
| session.run("ruff", "check", ".") | ||
|
|
||
| @nox.session(python="3.10") | ||
| def docfx(session: nox.Session) -> None: | ||
| """Build the docfx yaml files for this library.""" | ||
| session.install("PyYAML", "pypandoc") | ||
|
|
||
| # Construct arguments for the helper script | ||
| args = [ | ||
| "--current-dir", str(CURRENT_DIRECTORY), | ||
| "--repo-root", str(REPO_ROOT), | ||
| ] | ||
| for title, source in DOCS_MAP.items(): | ||
| args.extend(["--doc", title, str(source)]) | ||
|
|
||
| session.run("python", "docfx_helper.py", *args) | ||
|
|
||
| @nox.session(python=DEFAULT_PYTHON_VERSION) | ||
| def docs(session: nox.Session) -> None: | ||
| """No-op session for docs.""" | ||
| session.log("This package does not have Sphinx documentation.") |
This file contains hidden or 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,74 @@ | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
|
|
||
| import io | ||
| import os | ||
|
|
||
| import setuptools | ||
|
|
||
| # Package metadata. | ||
|
|
||
| name = "help" | ||
| description = "Client libraries help documentation" | ||
| release_status = "Development Status :: 5 - Production/Stable" | ||
| dependencies = [] | ||
|
|
||
| # Setup boilerplate below this line. | ||
|
|
||
| package_root = os.path.abspath(os.path.dirname(__file__)) | ||
|
|
||
| readme_filename = os.path.join(package_root, "README.md") | ||
| with io.open(readme_filename, encoding="utf-8") as readme_file: | ||
| readme = readme_file.read() | ||
|
|
||
| version = {} | ||
| with open(os.path.join(package_root, "help/version.py")) as fp: | ||
| exec(fp.read(), version) | ||
| version_id = version["__version__"] | ||
|
|
||
| setuptools.setup( | ||
| name=name, | ||
| version=version_id, | ||
| description=description, | ||
| long_description=readme, | ||
| long_description_content_type="text/markdown", | ||
| author="Google LLC", | ||
| author_email="cloud-sdk@google.com", | ||
| license="Apache 2.0", | ||
| url="https://github.com/googleapis/google-cloud-python/tree/main/packages/help", | ||
| project_urls={ | ||
| "Source": "https://github.com/googleapis/google-cloud-python/tree/main/packages/help", | ||
| "Changelog": "https://github.com/googleapis/google-cloud-python/tree/main/packages/help/CHANGELOG.md", | ||
| "Issues": "https://github.com/googleapis/google-cloud-python/issues", | ||
| }, | ||
| classifiers=[ | ||
| release_status, | ||
| "Intended Audience :: Developers", | ||
| "Programming Language :: Python", | ||
| "Programming Language :: Python :: 3", | ||
| "Programming Language :: Python :: 3.10", | ||
| "Programming Language :: Python :: 3.11", | ||
| "Programming Language :: Python :: 3.12", | ||
| "Programming Language :: Python :: 3.13", | ||
| "Programming Language :: Python :: 3.14", | ||
| "Operating System :: OS Independent", | ||
| "Topic :: Internet", | ||
| ], | ||
| install_requires=dependencies, | ||
| python_requires=">=3.9", | ||
| include_package_data=True, | ||
| zip_safe=False, | ||
| packages=["help"], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ) | ||
This file contains hidden or 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,18 @@ | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from help import version | ||
|
|
||
| def test_version() -> None: | ||
| assert version.__version__ is not None |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When writing text to a file using write_text, it is recommended to specify the encoding explicitly (e.g., encoding="utf-8") to ensure consistent behavior across different platforms.