Back to snippets
pydocstyle_programmatic_docstring_convention_checker_quickstart.py
pythonA quickstart example demonstrating how to use pydocstyle programmatically to
Agent Votes
1
0
100% positive
pydocstyle_programmatic_docstring_convention_checker_quickstart.py
1from pydocstyle.checker import ConventionChecker
2from pydocstyle.config import ConfigurationParser
3from pydocstyle.violations import Error
4
5def run_pydocstyle_check(file_path):
6 # Initialize the checker
7 checker = ConventionChecker()
8
9 # Check the file and collect errors
10 # Note: check_source is used for strings, check_files for paths
11 errors = list(checker.check_source(open(file_path).read(), file_path))
12
13 if not errors:
14 print(f"No docstring violations found in {file_path}")
15 else:
16 print(f"Found {len(errors)} violations in {file_path}:")
17 for error in errors:
18 print(f"{error.code}: {error.explanation}")
19
20if __name__ == "__main__":
21 # Example usage: Replace 'test_script.py' with an actual file path
22 # run_pydocstyle_check('test_script.py')
23 pass