Skip to content

Commit e6127b6

Browse files
authored
Strict sphinx (Azure#32507)
* Add strict_sphinx mode * Doc * cspell
1 parent b25a030 commit e6127b6

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

doc/eng_sys_checks.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ Starting with [this pr](https://github.com/Azure/azure-sdk-for-python/pull/28345
118118

119119
We default to **enabling** most of our checks like `pylint`, `mypy`, etc. Due to that, most `pyproject.toml` settings will likely be **disabling** checks.
120120

121+
There is also an additional setting to turn on strict sphinx validation, for docstring validation.
122+
121123
Here's an example:
122124

123125
```toml
@@ -130,6 +132,7 @@ verifytypes = false
130132
pyright = false
131133
pylint = false
132134
black = false
135+
strict_sphinx = false
133136
```
134137

135138
If a package does not yet have a `pyproject.toml`, creating one with just the section `[tool.azure-sdk-build]` will do no harm to the release of the package in question.
@@ -195,9 +198,20 @@ Analyze job in both nightly CI and pull request validation pipeline runs a set o
195198

196199
1. Go to root of the package.
197200
2. Execute following command: `tox run -e pylint -c ../../../eng/tox/tox.ini --root .`
198-
201+
199202
Note that the `pylint` environment is configured to run against the **earliest supported python version**. This means that users **must** have `python 3.7` installed on their machine to run this check locally.
200203

204+
### Sphinx and docstring checker
205+
206+
[`Sphinx`](https://www.sphinx-doc.org/en/master/) is the preferred documentation builder for Python libraries. The documentation is always built and attached to each PR builds. Sphinx can be configured to
207+
fail if docstring are invalid, helping to ensure the resulting documentation will be of high quality. Following are the steps to run `sphinx` locally for a specific package with strict docstring checking:
208+
209+
1. Go to root of the package.
210+
2. Make sure the `pyproject.toml` file contains `strict_sphinx = true`
211+
3. Execute following command: `tox run -e sphinx -c ../../../eng/tox/tox.ini --root .`
212+
213+
Note: While as of now the default value is `False`, it will become `True` by mid 2024.
214+
201215
### Bandit
202216

203217
`Bandit` is static security analysis tool. This check is triggered for all Azure SDK package as part of analyze job. Following are the steps to `Bandit` tool locally for a specific package.

eng/tox/run_sphinx_build.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import shutil
2323

2424
from ci_tools.parsing import ParsedSetup
25+
from ci_tools.functions import get_config_setting
2526

2627
logging.getLogger().setLevel(logging.INFO)
2728

@@ -39,7 +40,7 @@ def move_output_and_compress(target_dir, package_dir, package_name):
3940
individual_zip_location = os.path.join(ci_doc_dir, package_name, package_name)
4041
shutil.make_archive(individual_zip_location, 'gztar', target_dir)
4142

42-
def sphinx_build(target_dir, output_dir):
43+
def sphinx_build(target_dir, output_dir, fail_on_warning=False):
4344
command_array = [
4445
"sphinx-build",
4546
"-b",
@@ -51,6 +52,9 @@ def sphinx_build(target_dir, output_dir):
5152
target_dir,
5253
output_dir
5354
]
55+
if fail_on_warning:
56+
command_array.append("-W")
57+
command_array.append("--keep-going")
5458

5559
try:
5660
logging.info("Sphinx build command: {}".format(command_array))
@@ -59,7 +63,7 @@ def sphinx_build(target_dir, output_dir):
5963
)
6064
except CalledProcessError as e:
6165
logging.error(
62-
"sphinx-apidoc failed for path {} exited with error {}".format(
66+
"sphinx-build failed for path {} exited with error {}".format(
6367
args.working_directory, e.returncode
6468
)
6569
)
@@ -103,15 +107,16 @@ def sphinx_build(target_dir, output_dir):
103107

104108
args = parser.parse_args()
105109

106-
107110
output_dir = os.path.abspath(args.output_directory)
108111
target_dir = os.path.abspath(args.working_directory)
109112
package_dir = os.path.abspath(args.package_root)
110113

111114
pkg_details = ParsedSetup.from_path(package_dir)
112115

113116
if should_build_docs(pkg_details.name):
114-
sphinx_build(target_dir, output_dir)
117+
fail_on_warning = get_config_setting(args.package_root, "strict_sphinx", default=False)
118+
119+
sphinx_build(target_dir, output_dir, fail_on_warning=fail_on_warning)
115120

116121
if in_ci() or args.in_ci:
117122
move_output_and_compress(output_dir, package_dir, pkg_details.name)

0 commit comments

Comments
 (0)