Skip to content

Commit 4aa9b08

Browse files
committed
fix tests and apply suggestions from code review
1 parent 9224885 commit 4aa9b08

File tree

7 files changed

+110
-23
lines changed

7 files changed

+110
-23
lines changed

packages/help/docfx_helper.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import os
15+
import argparse
1616
import pathlib
1717
import shutil
18-
import sys
18+
from typing import Dict, Union
1919
import yaml
2020
import pypandoc
2121

22-
def build_docfx(current_dir, repo_root, docs_map):
22+
def build_docfx(
23+
current_dir: Union[str, pathlib.Path],
24+
docs_map: Dict[str, str],
25+
) -> None:
2326
current_dir = pathlib.Path(current_dir)
24-
repo_root = pathlib.Path(repo_root)
2527
output_dir = current_dir / "docs" / "_build"
2628

2729
if output_dir.exists():
@@ -35,7 +37,7 @@ def build_docfx(current_dir, repo_root, docs_map):
3537
print("Pandoc not found. Downloading...")
3638
pypandoc.download_pandoc()
3739

38-
toc = []
40+
doc_items = []
3941

4042
for title, source in docs_map.items():
4143
source_path = pathlib.Path(source)
@@ -54,7 +56,7 @@ def build_docfx(current_dir, repo_root, docs_map):
5456
'gfm',
5557
format='rst'
5658
)
57-
(output_dir / target_filename).write_text(output)
59+
(output_dir / target_filename).write_text(output, encoding="utf-8")
5860
else:
5961
print(f"Warning: Source {source_path} not found.")
6062
(output_dir / target_filename).write_text(f"# {title}\n\nContent missing.")
@@ -68,22 +70,32 @@ def build_docfx(current_dir, repo_root, docs_map):
6870
(output_dir / filename).write_text(f"# {title}\n\nContent missing.")
6971
href = filename
7072

71-
toc.append({"name": title, "href": href})
73+
doc_items.append({"name": title, "href": href})
74+
75+
# Create the structured TOC
76+
toc = [
77+
{
78+
"uid": "product-neutral-guides",
79+
"name": "Client library help",
80+
"items": doc_items
81+
}
82+
]
7283

7384
# Write toc.yaml
7485
toc_path = output_dir / "toc.yaml"
75-
with open(toc_path, "w") as f:
86+
with open(toc_path, "w", encoding="utf-8") as f:
87+
# Using block style for YAML as requested
7688
yaml.dump(toc, f, default_flow_style=False)
7789

7890
print(f"DocFX build complete in {output_dir}")
7991
print(f"Generated TOC: {toc}")
8092

8193
if __name__ == "__main__":
82-
# Simple argument parsing: current_dir, repo_root, then pairs of Title,Source
83-
curr = sys.argv[1]
84-
root = sys.argv[2]
85-
d_map = {}
86-
for i in range(3, len(sys.argv), 2):
87-
d_map[sys.argv[i]] = sys.argv[i+1]
94+
parser = argparse.ArgumentParser(description="Build DocFX documentation.")
95+
parser.add_argument("--current-dir", required=True, help="Current package directory")
96+
parser.add_argument("--doc", action="append", nargs=2, metavar=("TITLE", "PATH"), help="Add a document title and its source path")
97+
98+
args = parser.parse_args()
8899

89-
build_docfx(curr, root, d_map)
100+
docs_map = {title: path for title, path in args.doc} if args.doc else {}
101+
build_docfx(args.current_dir, docs_map)

packages/help/help/__init__.py

Whitespace-only changes.

packages/help/help/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2022 Google LLC
1+
# Copyright 2026 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

packages/help/mypy.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[mypy]
2+
python_version = 3.9
3+
ignore_missing_imports = True
4+
strict = True
5+
disallow_untyped_decorators = False
6+
show_error_codes = True
7+
explicit_package_bases = True
8+
namespace_packages = True

packages/help/noxfile.py

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
from __future__ import absolute_import
18-
1917
import pathlib
2018
import nox
2119

2220
DEFAULT_PYTHON_VERSION = "3.14"
21+
ALL_PYTHON = ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
2322
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
2423
REPO_ROOT = CURRENT_DIRECTORY.parent.parent
2524

@@ -31,26 +30,76 @@
3130

3231
nox.options.sessions = [
3332
"lint",
33+
"lint_setup_py",
34+
"unit",
35+
"mypy",
36+
"prerelease_deps",
37+
"core_deps_from_source",
3438
"docfx",
39+
"docs",
3540
]
3641

3742
# Error if a python version is missing
3843
nox.options.error_on_missing_interpreters = True
3944

4045
@nox.session(python=DEFAULT_PYTHON_VERSION)
41-
def lint(session):
46+
def lint_setup_py(session: nox.Session) -> None:
47+
"""Verify that setup.py is valid."""
48+
session.install("setuptools")
49+
session.run("python", "setup.py", "check", "--strict")
50+
51+
@nox.session(python=ALL_PYTHON)
52+
def unit(session: nox.Session) -> None:
53+
"""Run unit tests."""
54+
session.install("pytest", "pytest-cov")
55+
session.install("-e", ".")
56+
session.run("pytest", "tests")
57+
58+
@nox.session(python=DEFAULT_PYTHON_VERSION)
59+
def mypy(session: nox.Session) -> None:
60+
"""Run mypy."""
61+
session.install("mypy", "types-PyYAML")
62+
session.install("-e", ".")
63+
session.run("mypy", "help", "tests", "noxfile.py", "docfx_helper.py")
64+
65+
@nox.session(python=DEFAULT_PYTHON_VERSION)
66+
def prerelease_deps(session: nox.Session) -> None:
67+
"""Run unit tests with prerelease dependencies."""
68+
# Since we have no dependencies, this is just a normal unit test run
69+
# but with --pre enabled for any test tools.
70+
session.install("pytest", "pytest-cov")
71+
session.install("-e", ".")
72+
session.run("pytest", "tests")
73+
74+
@nox.session(python=DEFAULT_PYTHON_VERSION)
75+
def core_deps_from_source(session: nox.Session) -> None:
76+
"""Run unit tests with core dependencies installed from source."""
77+
# We don't depend on core, so we just run unit tests.
78+
session.install("pytest", "pytest-cov")
79+
session.install("-e", ".")
80+
session.run("pytest", "tests")
81+
82+
@nox.session(python=DEFAULT_PYTHON_VERSION)
83+
def lint(session: nox.Session) -> None:
4284
"""Run linters."""
4385
session.install("ruff")
4486
session.run("ruff", "check", ".")
4587

4688
@nox.session(python="3.10")
47-
def docfx(session):
89+
def docfx(session: nox.Session) -> None:
4890
"""Build the docfx yaml files for this library."""
4991
session.install("PyYAML", "pypandoc")
5092

5193
# Construct arguments for the helper script
52-
args = [str(CURRENT_DIRECTORY), str(REPO_ROOT)]
94+
args = [
95+
"--current-dir", str(CURRENT_DIRECTORY),
96+
]
5397
for title, source in DOCS_MAP.items():
54-
args.extend([title, str(source)])
98+
args.extend(["--doc", title, str(source)])
5599

56100
session.run("python", "docfx_helper.py", *args)
101+
102+
@nox.session(python=DEFAULT_PYTHON_VERSION)
103+
def docs(session: nox.Session) -> None:
104+
"""No-op session for docs."""
105+
session.log("This package does not have Sphinx documentation.")

packages/help/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"Topic :: Internet",
6868
],
6969
install_requires=dependencies,
70-
python_requires=">=3.10",
70+
python_requires=">=3.9",
7171
include_package_data=True,
7272
zip_safe=False,
7373
packages=["help"],
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from help import version
16+
17+
def test_version() -> None:
18+
assert version.__version__ is not None

0 commit comments

Comments
 (0)