pre-commit-hooks | git pre-commit hooks
kandi X-RAY | pre-commit-hooks Summary
kandi X-RAY | pre-commit-hooks Summary
A few useful git hooks to integrate with pre-commit.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Process files
- Find the first matching license header
- Check if there is a license insert in src_file_content
- Check if a license is found
- Read content from src_file
- Check if a license todo_comment is found in src_file_content
- Check if a license is found
- Check for fuzzy license found
- Return a valid license string
- Try to find a matching license header index
- Check if filename is a text file
- Return True if something is text
- Get the license info
- Removes CRRL from a file
- Removes tabs from a file
- Returns true if the file contains a crlf
- Check if a file contains tabs
pre-commit-hooks Key Features
pre-commit-hooks Examples and Code Snippets
pre_commit_all_cache_repos () { # Requires sqlite3
sqlite3 -header -column ~/.cache/pre-commit/db.db < <(echo -e ".width 50\nSELECT repo, ref, path FROM repos ORDER BY repo;")
}
pre_commit_local_cache_repos () { # Requires PyYaml & s
- repo: local
hooks:
- id: forbid-unicode-non-breaking-spaces
name: Detect unicode non-breaking space character U+00A0 aka M-BM-
language: system
entry: perl -ne 'print if $m = /\xc2\xa0/; $t ||= $m; END{{exit $t}}
- repo: local
hooks:
- id: forbid-abstract-classes-and-traits
name: Ensure neither abstract classes nor traits are used
language: pygrep
entry: "^(abstract|trait) "
files: ^src/.*\.groovy$
- repo: local
Community Discussions
Trending Discussions on pre-commit-hooks
QUESTION
I would like to enforce lower-case – and possibly snake_case – file names throughout a git repo, ideally via a pre-commit hook. Alas, Google comes up empty for this particular use case; check-case-conflict
isn't quite what I'm looking for. Does any such thing exist?
ANSWER
Answered 2022-Apr-04 at 16:47the easiest way to do this is via a language: fail
hook
something like this:
QUESTION
I am getting the below error when running "pre-commit run --all-files" and when trying to make a commit, it is some python error, python version in use is "Python 2.7.16".
...ANSWER
Answered 2022-Feb-28 at 16:52you're installing a very old version of mypy (0.782) which depends on an old version of typed-ast
(<1.5.0
) which does not support M1
you can ~usually get to the latest version by running pre-commit autoupdate
-- or pick a version newer than 0.900
(where mypy started support for M1)
disclaimer: I created pre-commit
QUESTION
I am wondering if there is a way to enforce type hints inside the Python projects?
Currently, I am using mypy pre-commit hook inside .pre-commit-config.yaml
:
ANSWER
Answered 2022-Jan-31 at 07:28Mypy exposes a bunch of option that you can set to enforce stricter or looser type checking, see for example enter link description here. For your case it would probably be disallow_untyped_defs, disallow_incomplete_defs, disallow_untyped_calls
You have several options to set them, for example using a mypy.ini file, or if you want to keep everything in your pre-commit.yaml, you can add several command line arguments. For your exact case, that would look like
QUESTION
As I understand the documentation, whenever I add these lines to the config:
...ANSWER
Answered 2021-Aug-12 at 14:04you're looking for the pre-commit install-hooks command
at the least you need something like this to cache the pre-commit environments:
QUESTION
I've been working on a project which so far has just involved building some cloud infrastructure, and now I'm trying to add a CLI to simplify running some AWS Lambdas. Unfortunately both the sdist and wheel packages built using poetry build
don't seem to include the dependencies, so I have to manually pip install
all of them to run the command. Basically I
- run
poetry build
in the project, cd "$(mktemp --directory)"
,python -m venv .venv
,. .venv/bin/activate
,pip install /path/to/result/of/poetry/build/above
, and then- run the new .venv/bin/ executable.
At this point the executable fails, because pip
did not install any of the package dependencies. If I pip show PACKAGE
the Requires
line is empty.
The Poetry manual doesn't seem to specify how to link dependencies to the built package, so what do I have to do instead?
I am using some optional dependencies, could that be interfering with the build process? To be clear, even non-optional dependencies do not show up in the package dependencies.
pyproject.toml:
...ANSWER
Answered 2021-Nov-04 at 02:15This appears to be a bug in Poetry. Or at least it's not clear from the documentation what the expected behavior would be in a case such as yours.
In your pyproject.toml
, you specify two dependencies as required in this section:
QUESTION
I would like to make a Git repo that’s REUSE compliant. I want to use the reuse pre-commit hook to help ensure that I’m compliant. The REUSE Specification requires that I make a folder called “LICENSES” that contains each of the licenses that my project uses. I’m using several other hooks, and I don’t want those hooks to check or modify anything in the LICENSES/
folder. I want every hook other than reuse to exclude LICENSES/
. (Side note: at the moment, it looks like the reuse hook isn’t affected by excluding LICENSES/
, but that should probably be fixed). Here’s what I’ve tried so far:
ANSWER
Answered 2021-Sep-08 at 16:29there is not without specifying an exclude
on each hook as you've found
the top level exclude
is a shortcut which is applied to all hooks
I would recommend just adding exclude
to the hooks which would modify the LICENSES
disclaimer: I created pre-commit
QUESTION
I have a precommit file which checks for commented line format in .cfg files. The current comment style is a semicolon, so this will fail if a pound sign is used for file comments. Can RegEx somehow be used to match multiple comment patterns? For example:
...ANSWER
Answered 2021-Aug-11 at 14:36QUESTION
cfn-lint version: 0.53.0
Description of issue.
I have following setup on my Ubuntu machine
- cfn-lint
- cfn-python-lint via pre-commit
Case 1: If I run cfn-lint ./**/*.yml
from terminal at the project root folder then there are no errors
Case 2: If I now try to git commit the code with pre-commit installed, it gives the following error "E0000 Template needs to be an object." for the parameters JSON file.
The parameter JSON looks something like this:
...ANSWER
Answered 2021-Aug-06 at 09:41In Case 1, you are only matching files with a *.yml
extension and not a JSON extension. However, in Case 2, being your pre-commit hook, you do include json files as well. Meaning it will probably try to interpret your parameters JSON file as a CloudFormation file.
Your parameters file isn't CloudFormation however, it is a simple JSON array containing some values. A CloudFormation file is always an object, never an array at the top level. This would explain the error message. The solution: only include files in your cfn-python-lint scan that are actually CloudFormation files.
QUESTION
I am using Django to develop an ERP and I want to use pre-commit with my project.
I have installed pre-commit, black, flake8, flake8-black. and this is my
...ANSWER
Answered 2021-Jun-27 at 07:04This is a known issue with cpython on windows. The error occurs when black tries to run multiple workers on >60 core machines because the default number of process workers given by os.cpu_count()
breaks some other windows limit (number of waiting processes? I'm not quite sure). Black >=19.10b0
has a fix for this, so try updating the version of black in your pre-commit config if you can?
- Python bug report: https://bugs.python.org/issue26903
- Fix applied by this PR in black: https://github.com/psf/black/pull/838
QUESTION
This code was created by black:
...ANSWER
Answered 2021-Jan-26 at 20:35from your configuration, you've set ignore = W504
ignore
isn't the option you want as it resets the default ignore (bringing in a bunch of things, including W503).
If you remove ignore=
, both W504
and W503
are in the default ignore so they won't be caught
as for your E501 (line too long), you can either extend-ignore = E501
or you can set max-line-length
appropriately
for black, this is the suggested configuration:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install pre-commit-hooks
You can use pre-commit-hooks like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page