### Install Invoke and Pre-commit Hooks Source: https://github.com/andreoliwa/nitpick/blob/master/docs/contributing.md Installs the Invoke task runner and pre-commit hooks required for local development. Ensure uv is installed globally first. ```bash pipx install invoke invoke install --hooks ``` -------------------------------- ### Install Nitpick with yay Source: https://github.com/andreoliwa/nitpick/blob/master/docs/quickstart.md Install the latest release on Arch Linux using yay. ```bash yay -Syu nitpick ``` -------------------------------- ### Install Pre-commit Hooks with PreK Source: https://github.com/andreoliwa/nitpick/blob/master/docs/quickstart.md Install pre-commit and commit-msg Git hooks using prek, a Rust-based re-implementation. ```bash prek install --install-hooks prek install -t commit-msg ``` -------------------------------- ### Install Nitpick with Homebrew Source: https://github.com/andreoliwa/nitpick/blob/master/docs/quickstart.md Install the latest release or development branch on macOS/Linux using Homebrew. ```bash brew install andreoliwa/formulae/nitpick ``` ```bash brew install andreoliwa/formulae/nitpick --HEAD ``` -------------------------------- ### Install Nitpick with pip Source: https://github.com/andreoliwa/nitpick/blob/master/docs/quickstart.md Install or upgrade Nitpick using pip. ```bash pip install -U nitpick ``` -------------------------------- ### Install Nitpick Development Branch with Homebrew Source: https://github.com/andreoliwa/nitpick/blob/master/README.md Install the development branch of Nitpick from GitHub using Homebrew. ```shell brew install andreoliwa/formulae/nitpick --HEAD ``` -------------------------------- ### Install Nitpick with Homebrew Source: https://github.com/andreoliwa/nitpick/blob/master/README.md Install the latest release of Nitpick on macOS/Linux using Homebrew. ```shell brew install andreoliwa/formulae/nitpick ``` -------------------------------- ### Install Nitpick with Pipx Source: https://github.com/andreoliwa/nitpick/blob/master/README.md Install the latest PyPI release of Nitpick using pipx. ```shell pipx install nitpick ``` -------------------------------- ### Install Nitpick with Pipx Source: https://github.com/andreoliwa/nitpick/blob/master/docs/quickstart.md Install the latest PyPI release or development branch using pipx for isolated environments. ```bash pipx install nitpick ``` ```bash pipx install git+https://github.com/andreoliwa/nitpick ``` -------------------------------- ### Example Nitpick Style File Source: https://github.com/andreoliwa/nitpick/blob/master/docs/styles.md This TOML file defines configurations for Black, Poetry, and Flake8, enforcing specific settings like line length and dependencies. ```toml "pyproject.toml".tool.black line-length = 120 "pyproject.toml".tool.poetry.group.dev.dependencies pylint = "*" "setup.cfg".flake8 ignore = "D107,D202,D203,D401" max-line-length = 120 inline-quotes = "double" "setup.cfg".isort line_length = 120 multi_line_output = 3 include_trailing_comma = true force_grid_wrap = 0 combine_as_imports = true ``` -------------------------------- ### Install Nitpick Development Branch with Pipx Source: https://github.com/andreoliwa/nitpick/blob/master/README.md Install the development branch of Nitpick from GitHub using pipx. ```shell pipx install git+https://github.com/andreoliwa/nitpick ``` -------------------------------- ### Commit Message Examples Source: https://github.com/andreoliwa/nitpick/blob/master/docs/contributing.md Examples of commit messages following the Conventional Commits standard for features and bug fixes. These messages help automate changelog generation. ```bash # For a feature: git commit -m "feat: short description of your feature" # For a bug fix: git commit -m "fix: short description of what you fixed" ``` -------------------------------- ### Configure Style from Python Package Source: https://github.com/andreoliwa/nitpick/blob/master/docs/configuration.md Specify a style file located within an installed Python package using the `pypackage://` or `py://` scheme. ```toml [tool.nitpick] style = "pypackage://some_python_package/styles/nitpick-style.toml" # or style = "py://some_python_package/styles/nitpick-style.toml" ``` -------------------------------- ### Flake8 Plugin Violation Example Source: https://github.com/andreoliwa/nitpick/blob/master/docs/flake8_plugin.md Illustrates how a violation in a configuration file is reported as if it originated from a Python file when Nitpick is used as a Flake8 plugin. ```bash ./tasks.py:0:1: NIP323 File setup.cfg: [flake8]max-line-length is 80 but it should be like this: [flake8] max-line-length = 120 ``` -------------------------------- ### Set Minimum Nitpick Version Source: https://github.com/andreoliwa/nitpick/blob/master/docs/nitpick_section.md Specify the minimum version of Nitpick required for the project. This will display an upgrade message if the installed version is lower. ```toml [nitpick] minimum_version = "0.10.0" ``` -------------------------------- ### Initialize Nitpick Configuration Source: https://github.com/andreoliwa/nitpick/blob/master/docs/configuration.md Use the `nitpick init` command to create a configuration file for your project. ```sh nitpick init /path/to/your-style-file.toml ``` -------------------------------- ### Nitpick CLI: init command usage Source: https://github.com/andreoliwa/nitpick/blob/master/docs/cli.md Shows the available options for the `nitpick init` command, including autofixing, style suggestions, and library directory specification. ```bash Usage: nitpick init [OPTIONS] [STYLE_URLS]... Create or update the [tool.nitpick] table in the configuration file. Options: -f, --fix Autofix the files changed by the command; otherwise, just print what would be done -s, --suggest Suggest styles based on the extension of project files (skipping Git ignored files) -l, --library DIRECTORY Library dir to scan for style files (implies --suggest); if not provided, uses the built-in style library --help Show this message and exit. ``` -------------------------------- ### Initialize Nitpick Configuration Source: https://github.com/andreoliwa/nitpick/blob/master/docs/quickstart.md Download and use the default style file to initialize Nitpick. This command will create a configuration file if none exists. ```bash nitpick init ``` -------------------------------- ### Configure Multiple Style Files Source: https://github.com/andreoliwa/nitpick/blob/master/docs/configuration.md Use multiple style files, mixing local paths and URLs. The order is important as later styles override earlier ones. ```toml [tool.nitpick] style = [ "/path/to/first.toml", "/another/path/to/second.toml", "https://example.com/on/the/web/third.toml" ] ``` -------------------------------- ### Initialize and Run Nitpick as a Library Source: https://github.com/andreoliwa/nitpick/blob/master/docs/api/index.md Shows how to initialize the Nitpick singleton and run checks programmatically. Ensure the `nitpick.core` module is imported. ```python from nitpick.core import Nitpick # Initialize Nitpick nit = Nitpick.singleton().init() # Run checks violations = nit.run() ``` -------------------------------- ### Run Local Tests and Checks Source: https://github.com/andreoliwa/nitpick/blob/master/docs/contributing.md Commands to run tests and checks locally. 'make' provides quick tests, while 'invoke ci-build' simulates a full CI environment. ```bash # Quick tests and checks make # Or use this to simulate a full CI build with tox invoke ci-build ``` -------------------------------- ### Configure Comma Separated Values Source: https://github.com/andreoliwa/nitpick/blob/master/docs/nitpick_section.md Define keys within specific configuration files (like setup.cfg) whose values should be treated as comma-separated lists rather than exact strings. ```toml [nitpick.files."setup.cfg"] comma_separated_values = ["flake8.ignore", "isort.some_key", "another_section.another_key"] ``` -------------------------------- ### Include Styles with Different References Source: https://github.com/andreoliwa/nitpick/blob/master/docs/nitpick_section.md Demonstrates various ways to reference styles, including relative paths, absolute paths, and references with authentication tokens, all pointing to the same canonical location. ```toml [nitpick.styles] include = [ "foobar.toml", "../styles/foobar.toml", "/bar_project@branchname/styles/foobar.toml", "//$GITHUB_TOKEN@foo_dev/bar_project@branchname/styles/foobar.toml", ] ``` -------------------------------- ### Run PreK with All Files Source: https://github.com/andreoliwa/nitpick/blob/master/docs/quickstart.md Use prek to run checks against all files in the repository. ```bash prek run --all-files ``` -------------------------------- ### Nitpick CLI Main Options Source: https://github.com/andreoliwa/nitpick/blob/master/docs/cli.md Displays the main options and commands available for the Nitpick CLI, including project path, offline mode, and subcommands like check, fix, init, and ls. ```bash Usage: nitpick [OPTIONS] COMMAND [ARGS]... Enforce the same settings across multiple language-independent projects. Options: -p, --project DIRECTORY Path to project root --offline Offline mode: no style will be downloaded (no HTTP requests at all) --version Show the version and exit. --help Show this message and exit. Commands: check Don't modify files, just print the differences. fix Fix files, modifying them directly. init Create or update the [tool.nitpick] table in the configuration... ls List of files configured in the Nitpick style. ``` -------------------------------- ### Configure Local Style File (Home Directory) Source: https://github.com/andreoliwa/nitpick/blob/master/docs/configuration.md Specify a local style file using a path relative to the user's home directory. ```toml [tool.nitpick] style = "~/some/path/to/another-style.toml" ``` -------------------------------- ### Configure Local Style File (Relative Path) Source: https://github.com/andreoliwa/nitpick/blob/master/docs/configuration.md Specify a local style file using a relative path from another project on the same drive. ```toml [tool.nitpick] style = "../another-project/another-style.toml" ``` -------------------------------- ### Configure GitHub Style via Raw URL Source: https://github.com/andreoliwa/nitpick/blob/master/docs/configuration.md Use the raw URL of a GitHub file or a GitHub Gist to specify the style file. ```toml [tool.nitpick] style = "https://github.com/andreoliwa/nitpick/blob/v0.38.1/nitpick-style.toml" ``` ```toml [tool.nitpick] style = "https://raw.githubusercontent.com/andreoliwa/nitpick/v0.38.1/nitpick-style.toml" ``` ```toml [tool.nitpick] style = "https://gist.githubusercontent.com/andreoliwa/f4fccf4e3e83a3228e8422c01a48be61/raw/ff3447bddfc5a8665538ddf9c250734e7a38eabb/remote-style.toml" ``` -------------------------------- ### Configure Local Style File Source: https://github.com/andreoliwa/nitpick/blob/master/docs/configuration.md Set the `style` option in the `[tool.nitpick]` table of your configuration file to point to a local style file. ```toml [tool.nitpick] style = "/path/to/your-style-file.toml" ``` -------------------------------- ### Configure GitHub Style with Version Source: https://github.com/andreoliwa/nitpick/blob/master/docs/configuration.md Specify a GitHub style file using the `github://` or `gh://` scheme, pinned to a specific Git reference (tag, commit, or branch). ```toml [tool.nitpick] style = "github://andreoliwa/nitpick@v0.38.1/nitpick-style.toml" # or style = "gh://andreoliwa/nitpick@v0.38.1/nitpick-style.toml" ``` -------------------------------- ### Enforcing Black Line Length in Style File Source: https://github.com/andreoliwa/nitpick/blob/master/docs/styles.md Demonstrates how to specify the Black formatter's line length within a Nitpick style file to ensure consistency across projects. ```toml "pyproject.toml".tool.black line-length = 120 ``` -------------------------------- ### Override Remote Style with Local File Source: https://github.com/andreoliwa/nitpick/blob/master/docs/configuration.md Use a remote style as a base and override its settings with a local style file. The './' prefix indicates a local file. ```toml [tool.nitpick] style = [ "https://example.com/on/the/web/remote-style.toml", "./my-local-style.toml", ] ``` -------------------------------- ### Nitpick Class Usage Source: https://github.com/andreoliwa/nitpick/blob/master/docs/api/index.md Demonstrates how to initialize and use the `Nitpick` class as a library to run checks and retrieve violations. ```APIDOC ## Using the API Nitpick can be used as a library in your Python code. The main entry point is the `Nitpick` class. ```python from nitpick.core import Nitpick # Initialize Nitpick nit = Nitpick.singleton().init() # Run checks violations = nit.run() ``` For more details, see the module documentation below. ``` -------------------------------- ### Add Nitpick to Project with uv Source: https://github.com/andreoliwa/nitpick/blob/master/docs/quickstart.md Add Nitpick as a development dependency to your project using uv. ```bash uv add --dev nitpick ``` -------------------------------- ### Configure Private GitHub Style with Token Source: https://github.com/andreoliwa/nitpick/blob/master/docs/configuration.md Access private GitHub repositories by including a token directly in the URL or by using an environment variable for security. ```toml [tool.nitpick] # A literal token style = "github://p5iCG5AJuDgY@some-user/a-private-repo@some-branch/nitpick-style.toml" # Or reading the secret value from the MY_AUTH_KEY env var style = "github://$MY_AUTH_KEY@some-user/a-private-repo@some-branch/nitpick-style.toml" ``` -------------------------------- ### Run Nitpick as Flake8 Plugin Source: https://github.com/andreoliwa/nitpick/blob/master/docs/quickstart.md Execute Nitpick checks by running flake8 on a project with Python files. ```bash flake8 . ``` -------------------------------- ### Define Custom List Keys for YAML Files Source: https://github.com/andreoliwa/nitpick/blob/master/docs/styles.md Use this configuration to specify custom keys for searching elements within YAML lists, overriding default behavior. This is applied within your Nitpick style configuration. ```toml "path/from/root/to/your/config.yaml".__list_keys = "" ``` -------------------------------- ### Enforcing Mypy Configuration in Style File Source: https://github.com/andreoliwa/nitpick/blob/master/docs/styles.md Shows how to enforce Mypy's 'ignore_missing_imports' setting in all projects using a Nitpick style file. ```toml "setup.cfg".mypy ignore_missing_imports = true ``` -------------------------------- ### Nitpick 'ls' Command Usage Source: https://github.com/andreoliwa/nitpick/blob/master/docs/cli.md Lists files configured in the Nitpick style, indicating existing files in green and absent files in red. Supports partial and multiple file names. ```bash Usage: nitpick ls [OPTIONS] [FILES]... List of files configured in the Nitpick style. Display existing files in green and absent files in red. You can use partial and multiple file names in the FILES argument. Options: --help Show this message and exit. ``` -------------------------------- ### Configure GitHub Style with Default Branch Source: https://github.com/andreoliwa/nitpick/blob/master/docs/configuration.md If no Git reference is provided, Nitpick uses the default branch (e.g., `develop`) of the GitHub repository for the style file. ```toml [tool.nitpick] style = "github://andreoliwa/nitpick/nitpick-style.toml" # or style = "gh://andreoliwa/nitpick/nitpick-style.toml" # It has the same effect as providing the default branch explicitly: style = "github://andreoliwa/nitpick@develop/nitpick-style.toml" # or style = "gh://andreoliwa/nitpick@develop/nitpick-style.toml" ``` -------------------------------- ### Check Files with Nitpick Source: https://github.com/andreoliwa/nitpick/blob/master/docs/quickstart.md Run Nitpick to check files for style errors without modifying them. ```bash nitpick check ``` -------------------------------- ### Enforce File Presence Source: https://github.com/andreoliwa/nitpick/blob/master/docs/nitpick_section.md Configure files that must exist in the project. An optional custom message can be provided for each file. ```toml [nitpick.files.present] ".editorconfig" = "" "CHANGELOG.md" = "A project should have a changelog" ``` -------------------------------- ### Include Other Styles Source: https://github.com/andreoliwa/nitpick/blob/master/docs/nitpick_section.md Specify a list of other Nitpick styles to include and merge into the current style. The order in the list determines the merge precedence. ```toml [nitpick.styles] include = ["styles/python38", "styles/poetry"] ``` -------------------------------- ### Configure Cache to Never Expire Source: https://github.com/andreoliwa/nitpick/blob/master/docs/configuration.md Set the `cache` key to `forever` to ensure that cached remote styles never expire. ```toml [tool.nitpick] style = "https://example.com/remote-style.toml" cache = "forever" ``` -------------------------------- ### Add Nitpick to Project with Poetry Source: https://github.com/andreoliwa/nitpick/blob/master/docs/quickstart.md Add Nitpick as a development dependency to your project using Poetry. ```bash poetry add --dev nitpick ``` -------------------------------- ### Fix Executable Not Found Error with Tox Source: https://github.com/andreoliwa/nitpick/blob/master/docs/troubleshooting.md If you encounter an error like 'Executable .tox/lint/bin/pylint not found' when running 'make', first run 'invoke lint' to create the tox environment, then run 'make' again. ```shell invoke lint ``` -------------------------------- ### Migrate missing_message to nitpick.files.present Source: https://github.com/andreoliwa/nitpick/blob/master/docs/styles.md This snippet shows the migration of the `missing_message` key to the `[nitpick.files.present]` configuration. Use this when updating styles that previously used `missing_message`. ```toml [nitpick.files."pyproject.toml"] missing_message = "Install poetry and run 'poetry init' to create it" ``` ```toml [nitpick.files.present] "pyproject.toml" = "Install poetry and run 'poetry init' to create it" ``` -------------------------------- ### Running Flake8 with Nitpick Select Source: https://github.com/andreoliwa/nitpick/blob/master/docs/flake8_plugin.md This command selects Nitpick-specific error codes when running Flake8, typically used within a pre-commit hook. ```bash flake8 --select=NIP ``` -------------------------------- ### Fix Files with Nitpick Source: https://github.com/andreoliwa/nitpick/blob/master/docs/quickstart.md Run Nitpick to automatically fix and modify files according to the configured style. ```bash nitpick fix ``` -------------------------------- ### Configure Cache Expiration Time Source: https://github.com/andreoliwa/nitpick/blob/master/docs/configuration.md Set a custom expiration time for cached remote styles using the `cache` key with a specified integer and time unit. ```toml [tool.nitpick] style = "https://example.com/remote-style.toml" cache = "15 minutes" ``` ```toml [tool.nitpick] style = "https://example.com/remote-style.toml" cache = "1 day" ``` -------------------------------- ### Configure Nitpick as Pre-commit Hook Source: https://github.com/andreoliwa/nitpick/blob/master/docs/quickstart.md Add Nitpick hooks to your .pre-commit-config.yaml for automated style checking and fixing during commits. Choose between suggestion, fix, or check hooks. ```yaml repos: - repo: https://github.com/andreoliwa/nitpick rev: v0.38.1 hooks: # This hook runs the `nitpick init --fix --suggest` command - id: nitpick-suggest # Choose only one of the "fix" or "check" hooks. # These hooks run the `nitpick fix` command - id: nitpick # - id: nitpick-fix-all # same as nitpick # - id: nitpick-fix # These hooks run the `nitpick check` command # - id: nitpick-check-all # - id: nitpick-check ``` -------------------------------- ### Disable Nitpick Cache Source: https://github.com/andreoliwa/nitpick/blob/master/docs/configuration.md Configure Nitpick to never use the cache, ensuring remote style files are always fetched. ```toml [tool.nitpick] style = "https://example.com/remote-style.toml" cache = "never" ``` -------------------------------- ### Configure Nitpick as MegaLinter Plugin Source: https://github.com/andreoliwa/nitpick/blob/master/docs/quickstart.md Add Nitpick as a plugin to your MegaLinter configuration by specifying its descriptor URL and enabling the NITPICK linter. ```yaml PLUGINS: - https://raw.githubusercontent.com/andreoliwa/nitpick/v0.38.1/mega-linter-plugin-nitpick/nitpick.megalinter-descriptor.yml ENABLE_LINTERS: - NITPICK ``` -------------------------------- ### Enforce File Absence Source: https://github.com/andreoliwa/nitpick/blob/master/docs/nitpick_section.md Configure files that should not exist in the project. An optional custom message can be provided for each file. ```toml [nitpick.files.absent] "some_file.txt" = "This is an optional extra string to display after the warning" "another_file.env" = "" ``` -------------------------------- ### Configure Nitpick as Flake8 Plugin in Pre-commit Source: https://github.com/andreoliwa/nitpick/blob/master/docs/quickstart.md Integrate Nitpick as an additional dependency for the flake8 pre-commit hook. ```yaml repos: - repo: https://github.com/PyCQA/flake8 rev: 4.0.1 hooks: - id: flake8 additional_dependencies: [nitpick] ``` -------------------------------- ### Nitpick 'check' Command Usage Source: https://github.com/andreoliwa/nitpick/blob/master/docs/cli.md Checks files for style violations without modifying them. A return code of 0 indicates no changes, while 1 means files would be modified. ```bash Usage: nitpick check [OPTIONS] [FILES]... Don't modify files, just print the differences. Return code 0 means nothing would change. Return code 1 means some files would be modified. You can use partial and multiple file names in the FILES argument. Options: -v, --verbose Increase logging verbosity (-v = INFO, -vv = DEBUG) --help Show this message and exit. ``` -------------------------------- ### Nitpick 'fix' Command Usage Source: https://github.com/andreoliwa/nitpick/blob/master/docs/cli.md Allows direct modification of files to fix style violations. It reports the number of fixed violations and those requiring manual changes. ```bash Usage: nitpick fix [OPTIONS] [FILES]... Fix files, modifying them directly. You can use partial and multiple file names in the FILES argument. Options: -v, --verbose Increase logging verbosity (-v = INFO, -vv = DEBUG) --help Show this message and exit. ``` -------------------------------- ### Fix macOS Crash on Multi-threading with Fork Source: https://github.com/andreoliwa/nitpick/blob/master/docs/troubleshooting.md On macOS, flake8 might crash when calling requests.get(url) due to fork() safety issues. Add this environment variable to your shell's initialization file to resolve it. ```shell export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES ``` -------------------------------- ### Resolve Missing 'rev' Key in Pre-commit Config Source: https://github.com/andreoliwa/nitpick/blob/master/docs/troubleshooting.md When using default pre-commit styles, a missing 'rev' key can cause InvalidConfigError. Run 'pre-commit autoupdate' to update the styles to the latest version, which typically includes the 'rev' key. ```shell An error has occurred: InvalidConfigError: ==> File .pre-commit-config.yaml ==> At Config() ==> At key: repos ==> At Repository(repo='https://github.com/PyCQA/bandit') =====> Missing required key: rev Check the log at /Users/your-name/.cache/pre-commit/pre-commit.log ``` -------------------------------- ### Resolve ModuleNotFoundError for Plugins Source: https://github.com/andreoliwa/nitpick/blob/master/docs/troubleshooting.md When upgrading Nitpick, old plugins might be renamed. This can lead to ModuleNotFoundError if old metadata remains in your virtualenv. Remove and recreate the virtualenv to fix this. ```shell $ rg nitpick.plugins.setup ~/Library/Caches/pypoetry/ /Users/john.doe/Library/Caches/pypoetry/virtualenvs/nitpick-UU_pZ5zs-py3.7/lib/python3.7/site-packages/nitpick-0.24.1.dist-info/entry_points.txt 11:setup_cfg=nitpick.plugins.setup_cfg ``` -------------------------------- ### Enforce Lines in Text Files Source: https://github.com/andreoliwa/nitpick/blob/master/docs/plugins.md Use this snippet to check if a text file contains specific lines. Each 'contains' block specifies a line that must be present. ```toml "some.txt".contains: - line: "abc" "some.txt".contains: - line: "def" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.