### Install wemake-python-styleguide Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/README.md Install the package using pip. ```bash pip install wemake-python-styleguide ``` -------------------------------- ### Install wemake-python-styleguide Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/setup.rst Use pip to install the linter. It is recommended to use poetry for package management. ```bash pip install wemake-python-styleguide ``` -------------------------------- ### Install wemake-python-styleguide with uv Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/pycharm.rst Install the wemake-python-styleguide and its executable dependencies using uv. This ensures the flake8 binary is available on your PATH. ```bash uv tool install --with-executables-from flake8 wemake-python-styleguide ``` -------------------------------- ### Install ondivi Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/ondivi.rst Install the ondivi script using pip. It is recommended to use poetry for package management. ```bash pip install ondivi ``` -------------------------------- ### Configure Travis CI for wemake-python-styleguide Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/ci.rst Minimal configuration for .travis.yml to install and run the styleguide. ```yaml dist: xenial language: python python: 3.7 install: pip install wemake-python-styleguide script: flake8 . ``` -------------------------------- ### Install MCP dependencies Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/cli.rst Install the necessary optional dependencies to enable MCP server functionality. ```console $ pip install 'wemake-python-styleguide[mcp]' ``` -------------------------------- ### Install python-lsp-server with uv Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/pycharm.rst Install python-lsp-server along with necessary plugins for flake8 integration using uv. This makes the pylsp binary available on your PATH. ```bash uv tool install \ --with flake8 \ --with wemake-python-styleguide \ --with pyls-flake8 \ python-lsp-server ``` -------------------------------- ### Configure GitLab CI for wemake-python-styleguide Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/ci.rst Minimal configuration for .gitlab-ci.yml to install and run the styleguide. ```yaml image: python3.12 test: before_script: pip install wemake-python-styleguide script: flake8 . ``` -------------------------------- ### Install Dependencies with Poetry Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/CONTRIBUTING.md Use this command to install project dependencies managed by Poetry. ```bash poetry install ``` -------------------------------- ### Run MCP server Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/cli.rst Start the MCP server or open it in the MCP Inspector using standard input/output transport. ```console $ mcp run wemake_python_styleguide/mcp.py:mcp ``` ```console $ mcp dev wemake_python_styleguide/mcp.py:mcp ``` -------------------------------- ### Install Spellchecking Tools Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/CONTRIBUTING.md Install codespell and flake8-spellcheck for spell and grammar checking. ```bash pip install codespell flake8-spellcheck ``` -------------------------------- ### Example Report with Source Code Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/formatter.rst This is an example of how flake8 reports violations when the '--show-source' option is enabled. ```text » flake8 . --format=wemake --show-source ./wemake_python_styleguide/formatter.py 107:32 E231 missing whitespace after ':' def show_source(self, error:Violation) -> str: ^ ``` -------------------------------- ### Example Report with Statistics Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/formatter.rst This is an example of a flake8 report that includes violation statistics, showing counts per type and file. ```text » flake8 . --format=wemake --show-source --statistics ./wemake_python_styleguide/formatter.py 107:32 E231 missing whitespace after ':' def show_source(self, error:Violation) -> str: ^ ./wemake_python_styleguide/types.py 53:47 E231 missing whitespace after ',' AnyFunctionDefAndLambda = Union[AnyFunctionDef,ast.Lambda] ^ E231: missing whitespace after ':' 1 ./wemake_python_styleguide/formatter.py 1 ./wemake_python_styleguide/types.py Total: 2 All errors: 2 ``` -------------------------------- ### Create a release branch for patches Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/CONTRIBUTING.md Steps to create a new branch for releasing patches to older versions, starting from a specific tag. ```bash git checkout $TAG_NAME; git checkout -b $RELEASE_NAME ``` -------------------------------- ### Pre-commit Configuration for wemake-python-styleguide Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/plugins.rst This YAML configuration is used with pre-commit to enforce wemake-python-styleguide checks locally before committing. Ensure flake8 is installed with the wemake plugin and specify the configuration file. ```yaml repos: - repo: local hooks: - id: flake8 name: flake8 description: wemake-python-styleguide enforcement entry: flake8 args: ["--config=setup.cfg"] language: python types: [python] ``` -------------------------------- ### Run nbqa with flake8 on a Jupyter Notebook Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/jupyter_notebooks.rst Use this command to run flake8 on a Jupyter Notebook file, ignoring specific error codes that may not apply naturally to notebooks. Ensure nbqa is installed and configured. ```bash $ nbqa flake8 notebook.ipynb --extend-ignore=NIP102,D100,E302,E305,E703,WPS102,WPS114 ``` -------------------------------- ### Python Visitor with Protected Method Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/api/tutorial.rst Example of a Python visitor class that uses a protected method to check for multiple 'if' conditions in comprehensions. This pattern helps enforce code style rules. ```python class WrongComprehensionVisitor(BaseNodeVisitor): _max_ifs = 1 def _check_ifs(self, node: ast.comprehension) -> None: if len(node.ifs) > self._max_ifs: # This will restrict to have more than 1 `if` # in your comprehensions: self.add_violation(MultipleIfsInComprehensionViolation(node)) def visit_comprehension(self, node: ast.comprehension) -> None: self._check_ifs(node) self.generic_visit(node) ``` -------------------------------- ### Enable Showing Source Code in setup.cfg Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/formatter.rst Configure flake8 to display the source code context for violations by setting 'show-source' to True in setup.cfg. ```ini [flake8] show-source = True ``` -------------------------------- ### Enable Statistics in setup.cfg Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/formatter.rst Configure flake8 to show violation statistics by setting 'statistics' to True in setup.cfg. ```ini [flake8] statistics = True ``` -------------------------------- ### Run Docker Image with Mounted Config and Code Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/docker.rst Run the Docker image, mounting a local configuration file and the current directory as code. ```bash docker run --rm wemakeservices/wemake-python-styleguide -v `pwd`:/code /code ``` -------------------------------- ### Basic GitHub Action Usage Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/github-actions.rst This snippet shows the most basic way to use the wemake-python-styleguide GitHub Action. It assumes the default reporter settings. ```yaml - name: wemake-python-styleguide uses: wemake-services/wemake-python-styleguide ``` -------------------------------- ### Run linter with ruff Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/README.md Combine ruff for formatting and checking with the wemake-python-styleguide linter. ```bash ruff check && ruff format flake8 . --select=WPS ``` -------------------------------- ### Ignoring Violations Per File in setup.cfg Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/configuration.rst Use the `per-file-ignores` option in your `setup.cfg` to specify violations to ignore for particular files or directories. This is useful for cases where certain rules are not applicable to specific parts of your codebase, such as test files. ```ini [flake8] per-file-ignores = # We allow to shadow functions with parameter names, because of the pytest API: tests/*.py: WPS442 ``` -------------------------------- ### Activate Custom Formatter in setup.cfg Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/formatter.rst Configure flake8 to use the 'wemake' formatter by setting the 'format' option in your setup.cfg file. ```ini [flake8] format = wemake ``` -------------------------------- ### Using GitHub Action Outputs Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/github-actions.rst This snippet demonstrates how to capture and use the outputs from the wemake-python-styleguide GitHub Action in subsequent steps of your workflow. ```yaml - name: wemake-python-styleguide uses: wemake-services/wemake-python-styleguide - name: Custom Action runs: echo "{{ steps.wemake-python-styleguide.outputs.output }}" ``` -------------------------------- ### Run linter on a module Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/README.md Execute the linter using flake8 with the WPS plugin selected. ```bash flake8 your_module.py --select=WPS ``` -------------------------------- ### Configure pre-commit hook for wemake-python-styleguide Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/ci.rst Add this hook to your .pre-commit-config.yaml to enable the styleguide in your pre-commit workflow. ```yaml repos: - repo: https://github.com/wemake-services/wemake-python-styleguide rev: ... # select the last active version hooks: - id: wemake-python-styleguide ``` -------------------------------- ### Explain violations via CLI Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/cli.rst Retrieve detailed descriptions for specific violation codes using the wps explain command. ```console $ wps explain WPS115 WPS115 — Require ``snake_case`` for naming class attributes. Attributes in Enum and enum-like classes (Django Choices) are ignored, as they should be written in UPPER_SNAKE_CASE ... ``` ```console $ wps explain 116 WPS116 — Forbid using more than one consecutive underscore in variable names. Reasoning: This is done to gain extra readability. ... ``` -------------------------------- ### Enable Violation Links in Command Line Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/formatter.rst Activate the display of direct links to documentation for each violation using the '--show-violation-links' command-line option. ```text » flake8 . --format=wemake --show-source --show-violation-links ./wemake_python_styleguide/formatter.py 107:32 E231 missing whitespace after ':' -> https://pyflak.es/E231 def show_source(self, error:Violation) -> str: ^ ``` -------------------------------- ### Add wemake-python-styleguide badge to documentation Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/README.md Use these snippets to display the project badge in your README files using either Markdown or reStructuredText syntax. ```md [![wemake-python-styleguide](https://img.shields.io/badge/style-wemake-000000.svg)](https://github.com/wemake-services/wemake-python-styleguide) ``` ```rst .. image:: https://img.shields.io/badge/style-wemake-000000.svg :target: https://github.com/wemake-services/wemake-python-styleguide ``` -------------------------------- ### Release a new version Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/CONTRIBUTING.md Steps to release a new version of the project, including updating changelog, bumping versions, committing, tagging, pushing, and publishing. ```bash git commit -a -m 'Version x.y.z release' && git tag -a x.y.x -m 'Version x.y.z' && git push && git push --tags ``` ```bash poetry publish --build ``` -------------------------------- ### Set up Interactive Debugging with ipdb Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/api/debugging.rst Configure your environment to use ipdb for interactive debugging. This involves setting an environment variable and using the breakpoint() function. ```bash export PYTHONBREAKPOINT=ipdb.set_trace ``` ```python breakpoint() ``` -------------------------------- ### Pull and Run Docker Image Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/docker.rst Pull the official Docker image and run it to check a directory. ```bash docker pull wemakeservices/wemake-python-styleguide docker run --rm wemakeservices/wemake-python-styleguide . ``` -------------------------------- ### Run all tests with make Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/CONTRIBUTING.md Execute all tests, including pytest, mypy, and flake8, using the make command. Refer to the Makefile for more details. ```bash make test ``` -------------------------------- ### Activate Custom Formatter via Command Line Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/formatter.rst Use this command to activate the 'wemake' formatter when running flake8 from the command line. ```bash flake8 --format=wemake your_module.py ``` -------------------------------- ### Run Linting with Flake8 Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/CONTRIBUTING.md Perform code linting using flake8 on the current directory. ```bash flake8 . ``` -------------------------------- ### Git Pre-commit Hook for wemake-python-styleguide Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/plugins.rst This bash script can be added to your local git pre-commit hook to run wemake-python-styleguide checks before each commit. If errors are found, the commit will be aborted with a message. ```bash # Your added code to run wemake-python-styleguide. Add this before # the whitespace error lines flake8 . if [ $? -ne 0 ] then echo "Please fix the ERRORS and commit again." exit 1 fi # If there are whitespace errors, print the offending file names and fail. exec git diff-index --check --cached $against -- ``` -------------------------------- ### Run All Tests Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/CONTRIBUTING.md Execute all project tests using pytest. ```bash pytest ``` -------------------------------- ### GitHub Action with Custom Path Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/github-actions.rst Specify a custom path for the wemake-python-styleguide GitHub Action to analyze. This is useful if your code or configuration is not in the root directory. ```yaml - name: wemake-python-styleguide uses: wemake-services/wemake-python-styleguide with: path: './your/custom/path' ``` -------------------------------- ### View Module Contents with Tokenize Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/api/debugging.rst Examine the tokenized representation of a Python module. This helps in understanding how the code is parsed into tokens. ```bash python3.12 -m tokenize ex.py ``` -------------------------------- ### Configure ondivi with baseline and custom format Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/ondivi.rst Use ondivi with a baseline commit and a custom format for parsing linter messages. This allows filtering violations based on a specified baseline and custom output parsing. ```bash flake8 script.py | ondivi --baseline master --format "{filename}:{line_num:d}{other}" ``` -------------------------------- ### GitHub Action to Prevent Workflow Failure Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/github-actions.rst Configure the wemake-python-styleguide GitHub Action to not fail the workflow even if violations are found by setting 'fail_workflow: false'. ```yaml - name: wemake-python-styleguide uses: wemake-services/wemake-python-styleguide with: fail_workflow: false ``` -------------------------------- ### PyCharm LSP Server Configuration Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/pycharm.rst Configure the pylsp-wps LSP server definition in PyCharm. This JSON snippet specifies the plugins to enable, including flake8 with WPS support. ```json { "pylsp": { "plugins": { "flake8": { "enabled": true, "select": ["WPS", "E"] }, "pycodestyle": { "enabled": false }, "pyflakes": { "enabled": false }, "mccabe": { "enabled": false } } } } ``` -------------------------------- ### Import Linter Configuration Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/api/index.rst This INI file defines the layered architecture contract for the project, specifying allowed import dependencies between different layers. ```ini [importlinter] root_package = wemake_python_styleguide [importlinter:contracts] # Layer: Core # Description: Core components should not depend on anything else. # Contract: core # Dependencies: # - wemake_python_styleguide.checker # - wemake_python_styleguide.errors # - wemake_python_styleguide.options # - wemake_python_styleguide.types # Layer: Checker # Description: Checker components can depend on core components. # Contract: checker # Dependencies: # - wemake_python_styleguide.checker # - wemake_python_styleguide.errors # - wemake_python_styleguide.options # - wemake_python_styleguide.types # - wemake_python_styleguide.visitors # - wemake_python_styleguide.transformations # Layer: Visitors # Description: Visitors can depend on core and checker components. # Contract: visitors # Dependencies: # - wemake_python_styleguide.checker # - wemake_python_styleguide.errors # - wemake_python_styleguide.options # - wemake_python_styleguide.types # - wemake_python_styleguide.visitors # - wemake_python_styleguide.transformations # Layer: Transformations # Description: Transformations can depend on core and checker components. # Contract: transformations # Dependencies: # - wemake_python_styleguide.checker # - wemake_python_styleguide.errors # - wemake_python_styleguide.options # - wemake_python_styleguide.types # - wemake_python_styleguide.visitors # - wemake_python_styleguide.transformations # Layer: Violations # Description: Violations can depend on core and checker components. # Contract: violations # Dependencies: # - wemake_python_styleguide.checker # - wemake_python_styleguide.errors # - wemake_python_styleguide.options # - wemake_python_styleguide.types # - wemake_python_styleguide.visitors # - wemake_python_styleguide.transformations # - wemake_python_styleguide.violations # Layer: Formatter # Description: Formatter can depend on core and checker components. # Contract: formatter # Dependencies: # - wemake_python_styleguide.checker # - wemake_python_styleguide.errors # - wemake_python_styleguide.options # - wemake_python_styleguide.types # - wemake_python_styleguide.visitors # - wemake_python_styleguide.transformations # - wemake_python_styleguide.violations # - wemake_python_styleguide.formatter ``` -------------------------------- ### Run Type Checks with Mypy Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/CONTRIBUTING.md Perform static type checking on the project code using mypy. ```bash mypy wemake_python_styleguide ``` -------------------------------- ### View Module Contents with AST Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/api/debugging.rst Inspect the Abstract Syntax Tree (AST) of a Python module to understand its structure. This is useful for analyzing code without executing it. ```bash python3.12 -m ast ex.py ``` -------------------------------- ### Integrate ondivi with flake8 Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/ondivi.rst Pipe the output of flake8 to ondivi to filter violations on changed lines. ```bash flake8 script.py | ondivi ``` -------------------------------- ### Run Codespell Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/CONTRIBUTING.md Execute codespell to find and correct spelling errors in specified directories and files. ```bash codespell -w wemake_python_styleguide tests docs scripts styles *.md --ignore-words ./tests/whitelist.txt ``` -------------------------------- ### Run flake8 with wemake-python-styleguide Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/setup.rst Execute flake8 to check Python files for style violations. You can run it on the current directory, a single file, or a package. ```bash flake8 . ``` ```bash flake8 your_module.py ``` ```bash flake8 your_package ``` -------------------------------- ### GitHub Action with Custom Current Working Directory (cwd) Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/github-actions.rst Set a custom current working directory for the wemake-python-styleguide GitHub Action. This allows the action to 'cd' into a specific subfolder before execution. ```yaml - name: wemake-python-styleguide uses: wemake-services/wemake-python-styleguide with: cwd: './your/custom/path' ``` -------------------------------- ### Enforce Architecture with Import Linter Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/CONTRIBUTING.md Check if the project's import structure adheres to defined architectural contracts. ```bash lint-imports ``` -------------------------------- ### Disable Colors with NO_COLOR Environment Variable Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/formatter.rst To disable all text highlighting and colors in the 'wemake' formatter, set the NO_COLOR environment variable to 1. ```bash export NO_COLOR=1 ``` -------------------------------- ### Python Function with Type Hinting Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/tests/fixtures/notebook.ipynb A Python function demonstrating type hinting for parameters and return values. It performs a simple addition. ```python def clear_name(good_name: int) -> int: """All functions should be like this one.""" return good_name + good_name ``` -------------------------------- ### Run a Specific Test with Pytest Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/api/debugging.rst Execute a single test file using pytest. This is a common step in test-driven development to isolate and fix bugs. ```bash pytest tests/full/path/to/your/test_module.py ``` -------------------------------- ### GitHub Action with PR Review Reporter Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/github-actions.rst Configure the GitHub Action to use the 'github-pr-review' reporter for inline comments in code reviews. This requires the GITHUB_TOKEN environment variable. ```yaml - name: wemake-python-styleguide uses: wemake-services/wemake-python-styleguide with: reporter: 'github-pr-review' env: GITHUB_TOKEN: ${{ secrets.github_token }} ``` -------------------------------- ### Run Flake8 Spellcheck Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/CONTRIBUTING.md Utilize flake8-spellcheck to identify spelling errors, ignoring words in the specified whitelist file. ```bash flake8 --whitelist ./tests/whitelist.txt . ``` -------------------------------- ### Ignore Violations for Stub Files Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/stubs.rst Configure flake8 to ignore specific violations for all stub files (*.pyi) by adding an entry to the [flake8] section in your setup.cfg file. This is useful when using tools like flake8-pyi. ```ini # Inside `setup.cfg`: [flake8] per-file-ignores = *.pyi: WPS604 ``` -------------------------------- ### Use ondivi with baseline for legacy code Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/docs/pages/usage/integrations/ondivi.rst Filter out violations present in a specified baseline commit or branch, allowing focus on new violations. This is useful for managing existing violations in older codebases. ```bash flake8 script.py | ondivi --baseline master ``` -------------------------------- ### Python Function with Underscore Separator Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/tests/fixtures/notebook.ipynb A Python function using an underscore as a visual separator in a numeric literal for readability. It returns an integer. ```python def s(handle: int) -> int: return handle + 2_00 ``` -------------------------------- ### Python Function with Underscore Separator and Variable Source: https://github.com/wemake-services/wemake-python-styleguide/blob/master/tests/fixtures/notebook.ipynb A Python function that uses an underscore separator in a numeric literal and references an undefined variable 's'. This code may raise a NameError. ```python def data(param) -> int: return s + 10_00 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.