### Install pre-commit hooks and update Source: https://github.com/akaihola/graylint/blob/main/README.rst Commands to install the Git hook scripts and update to the newest version. This is part of the pre-commit setup workflow. ```bash pre-commit install pre-commit autoupdate ``` -------------------------------- ### Set up Graylint development environment Source: https://github.com/akaihola/graylint/blob/main/CONTRIBUTING.rst Commands to clone the repository, create a virtual environment, install dependencies, create a feature branch, and run tests and linting. Darker fixes formatting and lists linting errors. ```bash git clone git@github.com:akaihola/graylint.git python -m venv .venv-graylint source .venv-graylint/bin/activate cd graylint pip install -e '.[test]' git checkout -b my-feature-branch # modify code git commit -m "My feature" pytest darker --config check-graylint.toml ``` -------------------------------- ### Configure linters on the command line Source: https://github.com/akaihola/graylint/blob/main/README.rst Shows how to pass custom arguments to linters via Graylint's -L and --lint options, using mypy and pylint as examples. ```shell graylint -L "mypy --strict" . graylint --lint "pylint --errors-only" . ``` -------------------------------- ### Install or upgrade Graylint with pip Source: https://github.com/akaihola/graylint/blob/main/README.rst Use this command to install or upgrade Graylint to the latest 2.0.x version. The `~=` compatible release specifier is recommended to avoid linter compatibility breakage. ```bash pip install --upgrade graylint~=2.0.0 ``` -------------------------------- ### Graylint configuration in pyproject.toml Source: https://github.com/akaihola/graylint/blob/main/README.rst Example TOML configuration for Graylint in pyproject.toml. Sets source directories, revision, linters, and log level. This configuration is read by Graylint but not by the linters it runs. ```toml [tool.graylint] src = [ "src/mypackage", ] revision = "master" lint = [ "pylint", ] log_level = "INFO" ``` -------------------------------- ### Install and update Graylint with Conda Source: https://github.com/akaihola/graylint/blob/main/README.rst Use these commands to install or update Graylint from the conda-forge channel. The `~=` specifier is recommended for version compatibility. ```bash conda install -c conda-forge graylint~=0.0.1 conda update -c conda-forge graylint ``` -------------------------------- ### Copy linter settings for pylint Source: https://github.com/akaihola/graylint/blob/main/README.rst Command to run graylint with the --copy-settings option to ensure the same linter configuration is used for both old and new code versions. This example uses pylint and a .pylintrc file. ```shell graylint --lint pylint --copy-settings .pylintrc . ``` -------------------------------- ### Pin linter versions in pre-commit configuration Source: https://github.com/akaihola/graylint/blob/main/README.rst YAML configuration to pin linter versions for a stable pre-commit setup. Specifies arguments for isort, mypy, flake8, and pylint, with additional dependencies pinned to specific versions. ```yaml - repo: https://github.com/akaihola/graylint rev: v2.0.0 hooks: - id: graylint args: - --isort - --lint - mypy - --lint - flake8 - --lint - pylint additional_dependencies: - mypy==0.990 - flake8==5.0.4 - pylint==2.15.5 ``` -------------------------------- ### Initialize a Git repository Source: https://github.com/akaihola/graylint/blob/main/README.rst Creates a temporary directory, navigates into it, and initializes a Git repository. The output confirms the repository was created. ```shell $ mkdir /tmp/test $ cd /tmp/test $ git init Initialized empty Git repository in /tmp/test/.git/ ``` -------------------------------- ### GitHub Actions workflow for Graylint Source: https://github.com/akaihola/graylint/blob/main/README.rst Complete GitHub Actions workflow YAML that sets up a Python environment, checks out code with full history, and runs Graylint with specified options, source directory, version, linters, and extra packages. ```yaml name: Lint on: [push, pull_request] jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - uses: akaihola/graylint@2.0.0 with: options: "-v" src: "./src" version: "~=2.0.0" lint: >- flake8 pylint==2.13.1 with: >- flake8-bugbear>=22.1.11,!=24.8.19 flake8-2020>=1.6.1 ``` -------------------------------- ### Generate base pre-commit configuration Source: https://github.com/akaihola/graylint/blob/main/README.rst Command to generate a base pre-commit configuration file. This is the first step in setting up Graylint as a pre-commit hook. ```bash pre-commit sample-config >.pre-commit-config.yaml ``` -------------------------------- ### Run Graylint with revision and lint options Source: https://github.com/akaihola/graylint/blob/main/README.rst Command-line invocation of graylint with a revision range and lint target. The output shows coverage warnings for specific lines in src/graylint/__main__.py. ```shell $ graylint --revision 0.1.0.. --lint cov_to_lint.py src src/graylint/__main__.py:94: no coverage: logger.debug("No changes in %s after isort", src) src/graylint/__main__.py:95: no coverage: break src/graylint/__main__.py:125: no coverage: except NotEquivalentError: src/graylint/__main__.py:130: no coverage: if context_lines == max_context_lines: src/graylint/__main__.py:131: no coverage: raise src/graylint/__main__.py:132: no coverage: logger.debug( ``` -------------------------------- ### Run Pylint on our_file.py Source: https://github.com/akaihola/graylint/blob/main/README.rst Shows the Pylint output for the initial file, reporting a missing module docstring and a rating of 7.50/10. ```shell $ pylint our_file.py ************* Module our_file our_file.py:1:0: C0114: Missing module docstring (missing-module-docstring) ------------------------------------------------------------------ Your code has been rated at 7.50/10 (previous run: 7.50/10, +0.00) ``` -------------------------------- ### Run linters on all Python files Source: https://github.com/akaihola/graylint/blob/main/README.rst Runs Graylint with Pylint on the entire repository, checking all Python files. ```shell $ graylint --lint pylint . ``` -------------------------------- ### Commit the initial file Source: https://github.com/akaihola/graylint/blob/main/README.rst Stages and commits the Python file, with the commit output showing the new commit hash and file change summary. ```shell $ git add our_file.py $ git commit -m "Initial commit" [master (root-commit) a0c7c32] Initial commit 1 file changed, 3 insertions(+) create mode 100644 our_file.py ``` -------------------------------- ### Linter output formats Source: https://github.com/akaihola/graylint/blob/main/README.rst Graylint supports linter output in these two formats: file:line: description and file:line:column: description. ```text :: ::: ``` -------------------------------- ### Pre-commit hook configuration for Graylint Source: https://github.com/akaihola/graylint/blob/main/README.rst YAML configuration for adding Graylint as a pre-commit hook. Includes the ruff package under additional_dependencies and passes the lint argument 'ruff check'. ```yaml - repo: https://github.com/akaihola/graylint rev: v2.0.0 hooks: - id: graylint args: [--lint "ruff check"] additional_dependencies: - ruff~=0.3.2 ``` -------------------------------- ### Add Graylint hook to pre-commit configuration Source: https://github.com/akaihola/graylint/blob/main/README.rst YAML snippet to append to .pre-commit-config.yaml to add the Graylint hook. Uses version v2.0.0. ```yaml - repo: https://github.com/akaihola/graylint rev: v2.0.0 hooks: - id: graylint ``` -------------------------------- ### Compare against a different revision Source: https://github.com/akaihola/graylint/blob/main/README.rst Runs Graylint with Pylint, comparing against the 'main' branch (or any commit) instead of the last commit. ```shell $ graylint --lint pylint --revision main . ``` -------------------------------- ### Show only new linting violations with graylint Source: https://github.com/akaihola/graylint/blob/main/README.rst Runs Graylint with Pylint on the file, displaying only the newly introduced violation (W0125) since the last commit. ```shell $ graylint --lint pylint our_file.py our_file.py:4:5: W0125: Using a conditional statement with a constant value (using-constant-test) [pylint] ``` -------------------------------- ### Invoke Graylint as a Python module Source: https://github.com/akaihola/graylint/blob/main/README.rst Use `python -m graylint` instead of the `graylint` command when you prefer to invoke the module directly through the Python executable. ```bash python -m graylint ``` -------------------------------- ### Run Pylint on a file or directory Source: https://github.com/akaihola/graylint/blob/main/README.rst Runs Pylint on the specified file or directory, comparing results between the current commit and the working tree to show only new lint errors. ```bash graylint --lint pylint ``` ```bash graylint --lint pylint ``` -------------------------------- ### YAML folded style for lint option Source: https://github.com/akaihola/graylint/blob/main/README.rst Shows how to use YAML folded style (>) to put a space-separated list of linters on multiple lines for readability. The >- syntax removes the trailing newline. ```yaml lint: >- flake8 pylint==2.13.1 ``` -------------------------------- ### Run Pylint on modified file Source: https://github.com/akaihola/graylint/blob/main/README.rst Pylint output after the modification, now reporting both the missing docstring and the constant-condition warning, with a rating drop to 6.00/10. ```shell $ pylint our_file.py ************* Module our_file our_file.py:1:0: C0114: Missing module docstring (missing-module-docstring) our_file.py:4:5: W0125: Using a conditional statement with a constant value (using-constant-test) ------------------------------------------------------------------ Your code has been rated at 6.00/10 (previous run: 7.50/10, -1.50) ``` -------------------------------- ### Update contributors with GitHub token Source: https://github.com/akaihola/graylint/blob/main/CONTRIBUTING.rst Command to generate contributor information using a GitHub personal access token. Requires the token and modifies README and contributors files. ```bash python release_tools/update_contributors.py \ generate \ --token= \ --modify-readme \ --modify-contributors ``` -------------------------------- ### Python file with Pylint violation Source: https://github.com/akaihola/graylint/blob/main/README.rst A simple Python script that reads a name and prints a message. It triggers a missing module docstring warning (C0114) when checked with Pylint. ```python first_name = input("Enter your first name: ") if first_name == "Guido": print("I know you") else: print("Nice to meet you") ``` -------------------------------- ### Modified Python file with new violation Source: https://github.com/akaihola/graylint/blob/main/README.rst The file is modified to use a constant condition (elif True), which introduces a new Pylint warning (W0125) in addition to the existing missing docstring. ```python first_name = input("Enter your first name: ") if first_name == "Guido": print("I know you") elif True: print("Nice to meet you") ```