1
0
Fork 0

Adding upstream version 5.0.0+dfsg.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-09 20:23:50 +01:00
parent 810185ab4a
commit f3f36bd616
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
12 changed files with 153 additions and 26 deletions

View file

@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
@ -14,7 +14,7 @@ repos:
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/asottile/reorder-python-imports
rev: v3.12.0
rev: v3.13.0
hooks:
- id: reorder-python-imports
args: [--py38-plus, --add-import, 'from __future__ import annotations']
@ -23,20 +23,19 @@ repos:
hooks:
- id: add-trailing-comma
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
rev: v3.17.0
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/hhatto/autopep8
rev: v2.1.0
rev: v2.3.1
hooks:
- id: autopep8
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
rev: 7.1.1
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
rev: v1.11.2
hooks:
- id: mypy
additional_dependencies: [types-all]

View file

@ -3,7 +3,8 @@
description: prevents giant files from being committed.
entry: check-added-large-files
language: python
stages: [commit, push, manual]
stages: [pre-commit, pre-push, manual]
minimum_pre_commit_version: 3.2.0
- id: check-ast
name: check python ast
description: simply checks whether the files parse as valid python.
@ -39,7 +40,13 @@
entry: check-executables-have-shebangs
language: python
types: [text, executable]
stages: [commit, push, manual]
stages: [pre-commit, pre-push, manual]
minimum_pre_commit_version: 3.2.0
- id: check-illegal-windows-names
name: check illegal windows names
entry: Illegal Windows filenames detected
language: fail
files: '(?i)((^|/)(CON|PRN|AUX|NUL|COM[\d¹²³]|LPT[\d¹²³])(\.|/|$)|[<>:\"\\|?*\x00-\x1F]|/[^/]*[\.\s]/|[^/]*[\.\s]$)'
- id: check-json
name: check json
description: checks json files for parseable syntax.
@ -52,7 +59,8 @@
entry: check-shebang-scripts-are-executable
language: python
types: [text]
stages: [commit, push, manual]
stages: [pre-commit, pre-push, manual]
minimum_pre_commit_version: 3.2.0
- id: pretty-format-json
name: pretty format json
description: sets a standard for formatting json files.
@ -107,6 +115,7 @@
entry: destroyed-symlinks
language: python
types: [file]
stages: [pre-commit, pre-push, manual]
- id: detect-aws-credentials
name: detect aws credentials
description: detects *your* aws credentials from the aws cli credentials file.
@ -131,7 +140,8 @@
entry: end-of-file-fixer
language: python
types: [text]
stages: [commit, push, manual]
stages: [pre-commit, pre-push, manual]
minimum_pre_commit_version: 3.2.0
- id: file-contents-sorter
name: file contents sorter
description: sorts the lines in specified files (defaults to alphabetical). you must provide list of target files as input in your .pre-commit-config.yaml file.
@ -198,4 +208,5 @@
entry: trailing-whitespace-fixer
language: python
types: [text]
stages: [commit, push, manual]
stages: [pre-commit, pre-push, manual]
minimum_pre_commit_version: 3.2.0

View file

@ -1,3 +1,27 @@
5.0.0 - 2024-10-05
==================
### Features
- `requirements-txt-fixer`: also remove `pkg_resources==...`.
- #850 PR by @ericfrederich.
- #1030 issue by @ericfrederich.
- `check-illegal-windows-names`: new hook!
- #1044 PR by @ericfrederich.
- #589 issue by @ericfrederich.
- #1049 PR by @Jeffrey-Lim.
- `pretty-format-json`: continue processing even if a file has a json error.
- #1039 PR by @amarvin.
- #1038 issue by @amarvin.
### Fixes
- `destroyed-symlinks`: set `stages` to `[pre-commit, pre-push, manual]`
- PR #1085 by @AdrianDC.
### Migrating
- pre-commit-hooks now requires `pre-commit>=3.2.0`.
- use non-deprecated names for `stages`.
- #1093 PR by @asottile.
4.6.0 - 2024-04-06
==================

View file

@ -15,7 +15,7 @@ Add this to your `.pre-commit-config.yaml`
```yaml
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0 # Use the ref you want to point at
rev: v5.0.0 # Use the ref you want to point at
hooks:
- id: trailing-whitespace
# - id: ...
@ -51,6 +51,9 @@ Checks for a common error of placing code before the docstring.
#### `check-executables-have-shebangs`
Checks that non-binary executables have a proper shebang.
#### `check-illegal-windows-names`
Check for files that cannot be created on Windows.
#### `check-json`
Attempts to load all json files to verify syntax.

View file

@ -35,7 +35,7 @@ class GitLsFile(NamedTuple):
filename: str
def git_ls_files(paths: Sequence[str]) -> Generator[GitLsFile, None, None]:
def git_ls_files(paths: Sequence[str]) -> Generator[GitLsFile]:
outs = cmd_output('git', 'ls-files', '-z', '--stage', '--', *paths)
for out in zsplit(outs):
metadata, filename = out.split('\t')

View file

@ -11,7 +11,7 @@ import ruamel.yaml
yaml = ruamel.yaml.YAML(typ='safe')
def _exhaust(gen: Generator[str, None, None]) -> None:
def _exhaust(gen: Generator[str]) -> None:
for _ in gen:
pass

View file

@ -115,16 +115,20 @@ def main(argv: Sequence[str] | None = None) -> int:
f'Input File {json_file} is not a valid JSON, consider using '
f'check-json',
)
return 1
if contents != pretty_contents:
if args.autofix:
_autofix(json_file, pretty_contents)
else:
diff_output = get_diff(contents, pretty_contents, json_file)
sys.stdout.buffer.write(diff_output.encode())
status = 1
else:
if contents != pretty_contents:
if args.autofix:
_autofix(json_file, pretty_contents)
else:
diff_output = get_diff(
contents,
pretty_contents,
json_file,
)
sys.stdout.buffer.write(diff_output.encode())
status = 1
return status

View file

@ -115,7 +115,10 @@ def fix_requirements(f: IO[bytes]) -> int:
# which is automatically added by broken pip package under Debian
requirements = [
req for req in requirements
if req.value != b'pkg-resources==0.0.0\n'
if req.value not in [
b'pkg-resources==0.0.0\n',
b'pkg_resources==0.0.0\n',
]
]
# sort the requirements and remove duplicates

View file

@ -1,6 +1,6 @@
[metadata]
name = pre_commit_hooks
version = 4.6.0
version = 5.0.0
description = Some out-of-the-box hooks for pre-commit.
long_description = file: README.md
long_description_content_type = text/markdown

View file

@ -0,0 +1,63 @@
from __future__ import annotations
import os.path
import re
import pytest
from pre_commit_hooks.check_yaml import yaml
@pytest.fixture(scope='module')
def hook_re():
here = os.path.dirname(__file__)
with open(os.path.join(here, '..', '.pre-commit-hooks.yaml')) as f:
hook_defs = yaml.load(f)
hook, = (
hook
for hook in hook_defs
if hook['id'] == 'check-illegal-windows-names'
)
yield re.compile(hook['files'])
@pytest.mark.parametrize(
's',
(
pytest.param('aux.txt', id='with ext'),
pytest.param('aux', id='without ext'),
pytest.param('AuX.tXt', id='capitals'),
pytest.param('com7.dat', id='com with digit'),
pytest.param(':', id='bare colon'),
pytest.param('file:Zone.Identifier', id='mid colon'),
pytest.param('path/COM¹.json', id='com with superscript'),
pytest.param('dir/LPT³.toml', id='lpt with superscript'),
pytest.param('with < less than', id='with less than'),
pytest.param('Fast or Slow?.md', id='with question mark'),
pytest.param('with "double" quotes', id='with double quotes'),
pytest.param('with_null\x00byte', id='with null byte'),
pytest.param('ends_with.', id='ends with period'),
pytest.param('ends_with ', id='ends with space'),
pytest.param('ends_with\t', id='ends with tab'),
pytest.param('dir/ends./with.txt', id='directory ends with period'),
pytest.param('dir/ends /with.txt', id='directory ends with space'),
),
)
def test_check_illegal_windows_names_matches(hook_re, s):
assert hook_re.search(s)
@pytest.mark.parametrize(
's',
(
pytest.param('README.md', id='standard file'),
pytest.param('foo.aux', id='as ext'),
pytest.param('com.dat', id='com without digit'),
pytest.param('.python-version', id='starts with period'),
pytest.param(' pseudo nan', id='with spaces'),
pytest.param('!@#$%^&;=≤\'~`¡¿€🤗', id='with allowed characters'),
pytest.param('path.to/file.py', id='standard path'),
),
)
def test_check_illegal_windows_names_does_not_match(hook_re, s):
assert hook_re.search(s) is None

View file

@ -82,6 +82,24 @@ def test_autofix_main(tmpdir):
assert ret == 0
def test_invalid_main(tmpdir):
srcfile1 = tmpdir.join('not_valid_json.json')
srcfile1.write(
'{\n'
' // not json\n'
' "a": "b"\n'
'}',
)
srcfile2 = tmpdir.join('to_be_json_formatted.json')
srcfile2.write('{ "a": "b" }')
# it should have skipped the first file and formatted the second one
assert main(['--autofix', str(srcfile1), str(srcfile2)]) == 1
# confirm second file was formatted (shouldn't trigger linter again)
assert main([str(srcfile2)]) == 0
def test_orderfile_get_pretty_format():
ret = main((
'--top-keys=alist', get_resource_path('pretty_formatted_json.json'),

View file

@ -82,6 +82,8 @@ from pre_commit_hooks.requirements_txt_fixer import Requirement
),
(b'bar\npkg-resources==0.0.0\nfoo\n', FAIL, b'bar\nfoo\n'),
(b'foo\npkg-resources==0.0.0\nbar\n', FAIL, b'bar\nfoo\n'),
(b'bar\npkg_resources==0.0.0\nfoo\n', FAIL, b'bar\nfoo\n'),
(b'foo\npkg_resources==0.0.0\nbar\n', FAIL, b'bar\nfoo\n'),
(
b'git+ssh://git_url@tag#egg=ocflib\nDjango\nijk\n',
FAIL,