1
- #!/usr/bin/env python3
2
1
"""
3
2
Validate that the titles in the rst files follow the proper capitalization convention.
4
3
5
4
Print the titles that do not follow the convention.
6
5
7
6
Usage::
8
- ./scripts/validate_rst_title_capitalization.py doc/source/development/contributing.rst
9
- ./scripts/validate_rst_title_capitalization.py doc/source/
10
7
8
+ As pre-commit hook (recommended):
9
+ pre-commit run title-capitalization --all-files
10
+
11
+ From the command-line:
12
+ python scripts/validate_rst_title_capitalization.py <rst file>
11
13
"""
12
14
import argparse
13
- import glob
14
- import os
15
15
import re
16
16
import sys
17
17
from typing import Iterable , List , Tuple
@@ -233,45 +233,14 @@ def find_titles(rst_file: str) -> Iterable[Tuple[str, int]]:
233
233
previous_line = line
234
234
235
235
236
- def find_rst_files (source_paths : List [str ]) -> Iterable [str ]:
237
- """
238
- Given the command line arguments of directory paths, this method
239
- yields the strings of the .rst file directories that these paths contain.
240
-
241
- Parameters
242
- ----------
243
- source_paths : str
244
- List of directories to validate, provided through command line arguments.
245
-
246
- Yields
247
- -------
248
- str
249
- Directory address of a .rst files found in command line argument directories.
250
- """
251
-
252
- for directory_address in source_paths :
253
- if not os .path .exists (directory_address ):
254
- raise ValueError (
255
- "Please enter a valid path, pointing to a valid file/directory."
256
- )
257
- elif directory_address .endswith (".rst" ):
258
- yield directory_address
259
- else :
260
- yield from glob .glob (
261
- pathname = f"{ directory_address } /**/*.rst" , recursive = True
262
- )
263
-
264
-
265
- def main (source_paths : List [str ], output_format : str ) -> int :
236
+ def main (source_paths : List [str ]) -> int :
266
237
"""
267
238
The main method to print all headings with incorrect capitalization.
268
239
269
240
Parameters
270
241
----------
271
242
source_paths : str
272
243
List of directories to validate, provided through command line arguments.
273
- output_format : str
274
- Output format of the script.
275
244
276
245
Returns
277
246
-------
@@ -281,7 +250,7 @@ def main(source_paths: List[str], output_format: str) -> int:
281
250
282
251
number_of_errors : int = 0
283
252
284
- for filename in find_rst_files ( source_paths ) :
253
+ for filename in source_paths :
285
254
for title , line_number in find_titles (filename ):
286
255
if title != correct_title_capitalization (title ):
287
256
print (
@@ -297,16 +266,9 @@ def main(source_paths: List[str], output_format: str) -> int:
297
266
parser = argparse .ArgumentParser (description = "Validate heading capitalization" )
298
267
299
268
parser .add_argument (
300
- "paths" , nargs = "+" , default = "." , help = "Source paths of file/directory to check."
301
- )
302
-
303
- parser .add_argument (
304
- "--format" ,
305
- "-f" ,
306
- default = "{source_path}:{line_number}:{msg}:{heading}:{correct_heading}" ,
307
- help = "Output format of incorrectly capitalized titles" ,
269
+ "paths" , nargs = "*" , help = "Source paths of file/directory to check."
308
270
)
309
271
310
272
args = parser .parse_args ()
311
273
312
- sys .exit (main (args .paths , args . format ))
274
+ sys .exit (main (args .paths ))
0 commit comments