Package: pre-commit-update
pre-commit-updatepre-commit-updateis a simple CLI tool to check and update pre-commit hooks.Table of contentsReasoningFeaturesInstallationUsagePipeline usage examplepre-commit hook usage examplepyproject.toml usage exampleReasoningpre-commitis a nice little tool that helps you polish your code before releasing it into the wild.
It is fairly easy to use. A singlepre-commit-config.yamlfile can hold multiple hooks (checks) that will go through
your code or repository and do certain checks. The problem is that the file is static and once you pin your hook versions
after a while they get outdated.pre-commit-updatewas created because there is no easy way to update your hooks by usingpre-commit autoupdateas it is not versatile enough.FeaturesFeaturepre-commit-updatepre-commit autoupdateDry run (checks for updates, does not update)YesNoStable versions onlyYesNoExclude repo(s) from update checkYesWorkaround (updates only specified repo(s))Keep repo(s) (checks for updates, does not update)YesNoUpdate by hash instead of tagYesYesCan be used as a pre-commit hookYesNoCan be configured inpyproject.tomlYesNoInstallationpre-commit-updateis available on PyPI:$python-mpipinstallpre-commit-updatePython >= 3.7 is supported.NOTE:Please make sure thatgitis installed.Usagepre-commit-updateCLI can be used as below:Usage: pre-commit-update [OPTIONS]Options:-d, --dry-run       Dry run only checks for the new versions withoutupdating-a, --all-versions  Include the alpha/beta versions when updating-v, --verbose       Display the complete output-e, --exclude TEXT  Exclude specific repo(s) by the `repo` url trim-k, --keep TEXT     Keep the version of specific repo(s) by the `repo` url trim (still checks for the new versions)-h, --help          Show this message and exit.If you want to just check for updates (without updatingpre-commit-config.yaml), for example, you would use:$pre-commit-update-dor$pre-commit-update--dry-runNOTE:If you are to use theexcludeorkeepoptions, please pass the repo url trim as a parameter.
Keep in mind that if you have multiple hooks (id's) configured for a single repo and youexcludethat repo,NONEof the hooks will be updated, whole repo will be excluded.Example of repo url trim:https://github.com/ambv/black->black(you will only passblackas a parameter toexcludeorkeep)Pipeline usage exampleGitLab job:pre-commit-hooks-update:stage:updatescript:# install git if not present in the image-pip install pre-commit-update-pre-commit-update --dry-runexcept:-mainwhen:manualallow_failure:trueNOTE:This is just an example, feel free to do your own configurationpre-commit hook usage exampleYou can also usepre-commit-updateas a hook in yourpre-commithooks:-repo:https://gitlab.com/vojko.pribudic/pre-commit-updaterev:v0.1.6# Insert the latest tag herehooks:-id:pre-commit-updateargs:[--dry-run,--exclude,black,--keep,isort]pyproject.toml usage exampleYou can configurepre-commit-updatein yourpyproject.tomlas below (feel free to do your own configuration):[tool.pre-commit-update]dry_run=trueall_versions=falseverbose=trueexclude=["isort"]keep=["black"]NOTE:If some of the options are missing (for exampleexcludeoption),pre-commit-updatewill use default value for that option (default forexcludeoption would be an empty list).IMPORTANTIf you invokepre-commit-updatewith any flags (e.g.pre-commit-update -d),pyproject.tomlconfiguration will beignored. If you configurepre-commit-updateviapyproject.tomlyou should only runpre-commit-update(without any flags / arguments).