### Install Pydocstyle Source: https://context7.com/pycqa/pydocstyle/llms.txt Commands to install the pydocstyle package using pip, including optional support for TOML configuration files. ```bash pip install pydocstyle pip install pydocstyle[toml] ``` -------------------------------- ### Configuration File Formats Source: https://context7.com/pycqa/pydocstyle/llms.txt Examples of configuring pydocstyle settings using INI-style or TOML-style configuration files. ```ini [pydocstyle] convention = google ignore = D100,D104 add_ignore = D415 ``` ```toml [tool.pydocstyle] convention = "numpy" ignore = ["D100", "D104", "D203"] add_ignore = ["D415"] ``` -------------------------------- ### pydocstyle pre-commit CLI Arguments Example Source: https://github.com/pycqa/pydocstyle/blob/master/docs/usage.md Example of configuring pydocstyle within a pre-commit configuration file using command-line arguments. This demonstrates how to specify ignored and selected error codes. ```yaml - id: pydocstyle args: - --ignore=D100,D203,D405 # or multiline - |- --select= D101, D2 ``` -------------------------------- ### pydocstyle Configuration Example (INI) Source: https://github.com/pycqa/pydocstyle/blob/master/docs/snippets/config.md An example of a pydocstyle configuration in an INI-style file. This configuration disables inheritance, specifies files to ignore, and sets a matching pattern for files. ```ini [pydocstyle] inherit = false ignore = D100,D203,D405 match = .* .py ``` -------------------------------- ### Install pydocstyle via pip Source: https://github.com/pycqa/pydocstyle/blob/master/docs/quickstart.md This command installs the pydocstyle package globally or in the current virtual environment using the Python package manager. ```bash pip install pydocstyle ``` -------------------------------- ### Skipping pydocstyle Checks with Inline Comments Source: https://github.com/pycqa/pydocstyle/blob/master/docs/snippets/in_file.md Demonstrates how to use '# noqa' comments to skip all pydocstyle checks or specific error codes (e.g., D102, D203). This is useful for exceptions where a docstring might not fully comply with standard conventions but is acceptable in context. The example shows skipping the D400 check for a missing period in a function's docstring. ```python >>> def bad_function(): # noqa: D400 ... """Omit a period in the docstring as an exception""" ... pass ``` -------------------------------- ### Filter Pydocstyle Error Codes by Prefix Source: https://context7.com/pycqa/pydocstyle/llms.txt This code snippet shows how to filter pydocstyle error codes based on a given prefix. It uses set comprehensions to efficiently create sets of codes starting with 'D1' (missing docstrings) and 'D4' (content issues), then prints the sorted lists. ```python d1xx_codes = {code for code in all_codes if code.startswith('D1')} d4xx_codes = {code for code in all_codes if code.startswith('D4')} print(f"Missing docstring codes (D1xx): {sorted(d1xx_codes)}") print(f"Content issue codes (D4xx): {sorted(d4xx_codes)}") ``` -------------------------------- ### Configure Docstring Conventions Source: https://context7.com/pycqa/pydocstyle/llms.txt Select specific docstring conventions like PEP 257, NumPy, or Google using the --convention flag. ```bash pydocstyle --convention=pep257 mymodule.py pydocstyle --convention=numpy mymodule.py pydocstyle --convention=google mymodule.py ``` -------------------------------- ### CLI Execution and Configuration Source: https://context7.com/pycqa/pydocstyle/llms.txt Standard usage of the pydocstyle command-line tool to analyze Python files and directories. ```APIDOC ## CLI Execution ### Description Run pydocstyle against specific files or directories to identify docstring violations. ### Method CLI Command ### Endpoint pydocstyle [files/directories] ### Parameters #### Query Parameters - **--convention** (string) - Optional - Select style: pep257, numpy, or google. - **--select** (string) - Optional - Comma-separated list of error codes to include. - **--ignore** (string) - Optional - Comma-separated list of error codes to exclude. - **--match** (regex) - Optional - Regex pattern to match files to check. - **--explain** (flag) - Optional - Show explanation for each error. - **--source** (flag) - Optional - Show source code context for each error. ### Request Example `pydocstyle --convention=google --select=D100,D101 src/` ### Response #### Success Response (0) - **Output** (text) - List of violations found in the format: [file]:[line] in [context]: [code]: [message] ``` -------------------------------- ### Verbose and Debug Output Source: https://context7.com/pycqa/pydocstyle/llms.txt Enable detailed reporting, including explanations, source context, and error counts. ```bash pydocstyle --explain --source mymodule.py pydocstyle --count mymodule.py ``` -------------------------------- ### File and Directory Matching Source: https://context7.com/pycqa/pydocstyle/llms.txt Use regex patterns with --match and --match-dir to filter which files and directories are analyzed. ```bash pydocstyle --match='.*\.py' src/ pydocstyle --match-dir='[^_].*' src/ ``` -------------------------------- ### Run pydocstyle CLI Source: https://github.com/pycqa/pydocstyle/blob/master/docs/usage.md Basic command line syntax for executing pydocstyle against files or directories. It supports various flags for filtering, output formatting, and error selection. ```bash pydocstyle [options] [...] ``` -------------------------------- ### Managing conventions and error registries Source: https://context7.com/pycqa/pydocstyle/llms.txt Retrieve predefined conventions like PEP 257, NumPy, or Google, and inspect the total registry of available error codes. ```python from pydocstyle.violations import conventions, ErrorRegistry # Access predefined conventions pep257_codes = conventions.pep257 # Get all available error codes all_codes = set(ErrorRegistry.get_error_codes()) # Create custom convention custom_convention = conventions.google - {'D400', 'D401'} | {'D212'} ``` -------------------------------- ### Configure pydocstyle in pre-commit Source: https://github.com/pycqa/pydocstyle/blob/master/docs/snippets/pre_commit.md This snippet demonstrates the basic configuration required to add pydocstyle as a hook in your .pre-commit-config.yaml file. It specifies the repository source, the version tag, and the hook identifier. ```yaml - repo: https://github.com/pycqa/pydocstyle rev: 0.0.0.dev0 hooks: - id: pydocstyle ``` -------------------------------- ### Integrating pydocstyle with pre-commit Source: https://context7.com/pycqa/pydocstyle/llms.txt Configure pydocstyle within a .pre-commit-config.yaml file to automate docstring validation. Supports custom arguments for conventions and error filtering. ```yaml # .pre-commit-config.yaml repos: - repo: https://github.com/pycqa/pydocstyle rev: 6.3.0 hooks: - id: pydocstyle args: - --convention=google - --add-ignore=D100,D104 # Alternative with inline configuration - repo: https://github.com/pycqa/pydocstyle rev: 6.3.0 hooks: - id: pydocstyle args: - |- --select= D101, D102, D103, D2 ``` -------------------------------- ### Run pydocstyle on a Python file Source: https://github.com/pycqa/pydocstyle/blob/master/docs/quickstart.md Executes the pydocstyle command-line tool against a specific Python file to report docstring convention violations. The output displays the file path, line number, and the specific error code found. ```bash pydocstyle test.py ``` -------------------------------- ### Customize pydocstyle arguments in pre-commit Source: https://github.com/pycqa/pydocstyle/blob/master/docs/snippets/pre_commit.md This snippet shows how to pass command-line arguments to pydocstyle within the pre-commit configuration. It demonstrates both simple ignore lists and multiline select configurations. ```yaml - id: pydocstyle args: - --ignore=D100,D203,D405 - |- --select= D101, D2 ``` -------------------------------- ### pydocstyle pre-commit Configuration Source: https://github.com/pycqa/pydocstyle/blob/master/docs/usage.md Configuration snippet for integrating pydocstyle as a hook within the pre-commit framework. This allows automatic checking of Python code style during Git commits. ```yaml - repo: [https://github.com/pycqa/pydocstyle](https://github.com/pycqa/pydocstyle) rev: 0.0.0.dev0 # pick a git hash / tag to point to hooks: - id: pydocstyle ``` -------------------------------- ### Fine-grained control with ConventionChecker Source: https://context7.com/pycqa/pydocstyle/llms.txt The ConventionChecker class provides advanced control for checking raw source code strings directly. It allows fine-tuning of decorators and property handling. ```python from pydocstyle.checker import ConventionChecker import re checker = ConventionChecker() source_code = ''' def greet(name): """Says hello to the user""" return f"Hello, {name}!" class MyClass: def method(self): pass ''' # Check source code directly errors = list(checker.check_source( source=source_code, filename='example.py', ignore_decorators=None, property_decorators={'property', 'cached_property'}, ignore_inline_noqa=False, ignore_self_only_init=False )) for error in errors: print(f"Line {error.line}: {error.code} - {error.message}") ``` -------------------------------- ### Programmatically checking files with the check() function Source: https://context7.com/pycqa/pydocstyle/llms.txt The check() function allows you to scan files for docstring violations programmatically. It supports filtering by specific error codes, ignoring codes, and customizing conventions. ```python from pydocstyle import check from pydocstyle.violations import conventions # Basic usage - check files with default PEP 257 convention errors = list(check(['mymodule.py'])) for error in errors: print(f"{error.filename}:{error.line} - {error.code}: {error.message}") # Check with specific error codes only errors = list(check( ['mymodule.py', 'another.py'], select={'D100', 'D101', 'D102', 'D103'} )) # Check with ignored error codes errors = list(check( ['src/'], ignore={'D100', 'D104', 'D203'} )) # Use a convention as base and customize errors = list(check( ['mymodule.py'], select=conventions.google - {'D415'} )) # Ignore decorated functions import re errors = list(check( ['mymodule.py'], ignore_decorators=re.compile(r'override|deprecated') )) # Ignore noqa comments errors = list(check( ['mymodule.py'], ignore_inline_noqa=True )) # Ignore __init__ methods with only self parameter errors = list(check( ['mymodule.py'], ignore_self_only_init=True )) ``` -------------------------------- ### Check Docstring Conventions with Pydocstyle Source: https://context7.com/pycqa/pydocstyle/llms.txt This snippet demonstrates how to check if specific docstring error codes exist within predefined conventions like PEP 257 and NumPy. It utilizes the 'conventions' object to perform these checks and prints the results. ```python print("D100 in PEP 257:", 'D100' in conventions.pep257) print("D107 in NumPy:", 'D107' in conventions.numpy) ``` -------------------------------- ### Filter Errors with Select and Ignore Source: https://context7.com/pycqa/pydocstyle/llms.txt Control which errors are reported by explicitly selecting or ignoring specific error codes. ```bash pydocstyle --select=D1 mymodule.py pydocstyle --ignore=D100,D203,D212 mymodule.py ``` -------------------------------- ### Accessing error object properties and metadata Source: https://context7.com/pycqa/pydocstyle/llms.txt Iterate through error objects to access detailed metadata such as error codes, messages, file locations, and explanations. ```python from pydocstyle import check from pydocstyle.violations import Error for error in check(['mymodule.py']): print(f"Code: {error.code}") print(f"Message: {error.message}") # Enable explanation/source in output Error.explain = True Error.source = True print(str(error)) ``` -------------------------------- ### Ignore Decorated Functions Source: https://context7.com/pycqa/pydocstyle/llms.txt Skip analysis for functions marked with specific decorators using the --ignore-decorators flag. ```bash pydocstyle --ignore-decorators='override' mymodule.py pydocstyle --ignore-decorators='property|cached_property' mymodule.py ``` -------------------------------- ### Pydocstyle Error Code Reference Source: https://context7.com/pycqa/pydocstyle/llms.txt This is a reference block listing various pydocstyle error codes organized by category. It includes codes related to missing docstrings, whitespace issues, quotes, and docstring content. ```python """ MISSING DOCSTRINGS (D1xx) ------------------------- D100 - Missing docstring in public module D101 - Missing docstring in public class D102 - Missing docstring in public method D103 - Missing docstring in public function D104 - Missing docstring in public package D105 - Missing docstring in magic method D106 - Missing docstring in public nested class D107 - Missing docstring in __init__ WHITESPACE ISSUES (D2xx) ------------------------ D200 - One-line docstring should fit on one line with quotes D201 - No blank lines allowed before function docstring D202 - No blank lines allowed after function docstring D203 - 1 blank line required before class docstring D204 - 1 blank line required after class docstring D205 - 1 blank line required between summary line and description D206 - Docstring should be indented with spaces, not tabs D207 - Docstring is under-indented D208 - Docstring is over-indented D209 - Multi-line docstring closing quotes should be on a separate line D210 - No whitespaces allowed surrounding docstring text D211 - No blank lines allowed before class docstring D212 - Multi-line docstring summary should start at the first line D213 - Multi-line docstring summary should start at the second line D214 - Section is over-indented D215 - Section underline is over-indented QUOTES ISSUES (D3xx) -------------------- D300 - Use triple double quotes D301 - Use r\"\"\" if any backslashes in a docstring D302 - Deprecated: Use u\"\"\" for Unicode docstrings DOCSTRING CONTENT ISSUES (D4xx) ----------------------------- D400 - First line should end with a period D401 - First line should be in imperative mood D402 - First line should not be the function's signature D403 - First word of the first line should be properly capitalized D404 - First word of the docstring should not be 'This' D405 - Section name should be properly capitalized D406 - Section name should end with a newline D407 - Missing dashed underline after section D408 - Section underline should be in the line following the section's name D409 - Section underline should match the length of its name D410 - Missing blank line after section D411 - Missing blank line before section D412 - No blank lines allowed between a section header and its content D413 - Missing blank line after last section D414 - Section has no content D415 - First line should end with a period, question mark, or exclamation point D416 - Section name should end with a colon D417 - Missing argument descriptions in the docstring D418 - Function decorated with @overload shouldn't contain a docstring D419 - Docstring is empty """ ``` -------------------------------- ### Suppressing pydocstyle checks with inline comments Source: https://context7.com/pycqa/pydocstyle/llms.txt Use # noqa comments to skip specific or all pydocstyle checks for individual functions or methods. This format is compatible with flake8-docstrings. ```python def function_without_docstring(): # noqa """This skips ALL pydocstyle checks for this function.""" pass def another_function(): # noqa: D400,D401 """Skip only specific error codes D400 and D401 This comment format is compatible with flake8-docstrings. """ pass def compatible_with_flake8(): # noqa: D102,E501,D203 """Mix pydocstyle and flake8 error codes in the same comment""" pass ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.