Skip to content

H4rryK4ne/update-mypy-hook

Repository files navigation

Update mypy pre-commit hook

This script uses uv to update the additional_dependencies of the mypy pre-commit hook.

With uv export it will generate a list of all dependencies required to run mypy. By default, it assumes that an uv dependency group, called mypy, exists and contains all additional dependencies (besides the project dependencies) to successfully run type checking. The group(s) may only contain the direct dependencies. Transitive dependencies are derived by uv automatically.

The dependency group(s) can be overwritten by -g/--group option.

Installation

If you have installed uv on your machine or is already part of your dependencies you can run

pip install update-mypy-hook

or with uv

uv add update-mypy-hook --group dev

If uv is not part of your setup, use the extra

pip install update-mypy-hook[uv]

Using update-mypy-hook

Run in your python project root folder

update-mypy-hook --help

Pre-commit hook

Add this to your .pre-commit-config.yaml

- repo: https://github.com/H4rryK4ne/update-mypy-hook
  rev: v0.2.0
  hooks:
  - id: update-mypy-hook
    additional_dependencies:
    - uv # if uv is not installed on every developer's system
    args:
    - --extra-excluded-package=some_package
    - --extra-excluded-package=some_other_package

Options:

  -h, --help            show this help message and exit
  -g GROUP, --group GROUP
                        Dependency group to include. Can be used multiple times (default: mypy)
  --no-groups           Do not include any dependency groups.
  -c PRE_COMMIT_CONFIG_PATH, --pre-commit-config-path PRE_COMMIT_CONFIG_PATH
                        Path to .pre-commit-config.yaml (default: .pre-commit-config.yaml)
  -p PROJECT_PATH, --project-path PROJECT_PATH
                        Path to python project. Only needed if not in project root.
  --excluded-package PACKAGE
                        Package excluded in the additional_dependencies. Can be used multiple times (default: mypy, mypy-extensions, tomli, typing-extensions)
  -x PACKAGE, --extra-excluded-package PACKAGE
                        Additional package excluded from additional_dependencies. Extends the --excluded-package option. Can be used multiple times.
  --yaml-width YAML_WIDTH
                        maximum width of yaml output (default: 120)
  --yaml-indent YAML_INDENT
                        number of spaces to indent (default: 2)
  --yaml-default-flow-style, --no-yaml-default-flow-style
                        use default flow style (default: False)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages