1
0
Fork 0

Merging upstream version 4.6.0+dfsg.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-09 20:22:51 +01:00
parent db08a7e438
commit 9d65518d11
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
8 changed files with 49 additions and 9 deletions

View file

@ -1,6 +1,6 @@
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0 rev: v4.6.0
hooks: hooks:
- id: trailing-whitespace - id: trailing-whitespace
- id: end-of-file-fixer - id: end-of-file-fixer
@ -23,20 +23,20 @@ repos:
hooks: hooks:
- id: add-trailing-comma - id: add-trailing-comma
- repo: https://github.com/asottile/pyupgrade - repo: https://github.com/asottile/pyupgrade
rev: v3.14.0 rev: v3.15.2
hooks: hooks:
- id: pyupgrade - id: pyupgrade
args: [--py38-plus] args: [--py38-plus]
- repo: https://github.com/hhatto/autopep8 - repo: https://github.com/hhatto/autopep8
rev: v2.0.4 rev: v2.1.0
hooks: hooks:
- id: autopep8 - id: autopep8
- repo: https://github.com/PyCQA/flake8 - repo: https://github.com/PyCQA/flake8
rev: 6.1.0 rev: 7.0.0
hooks: hooks:
- id: flake8 - id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy - repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1 rev: v1.9.0
hooks: hooks:
- id: mypy - id: mypy
additional_dependencies: [types-all] additional_dependencies: [types-all]

View file

@ -145,7 +145,7 @@
language: python language: python
types: [text] types: [text]
- id: fix-encoding-pragma - id: fix-encoding-pragma
name: fix python encoding pragma name: fix python encoding pragma (deprecated)
description: 'adds # -*- coding: utf-8 -*- to the top of python files.' description: 'adds # -*- coding: utf-8 -*- to the top of python files.'
language: python language: python
entry: fix-encoding-pragma entry: fix-encoding-pragma

View file

@ -1,3 +1,17 @@
4.6.0 - 2024-04-06
==================
### Features
- `requirements-txt-fixer`: remove duplicate packages.
- #1014 PR by @vhoulbreque-withings.
- #960 issue @csibe17.
### Migrating
- `fix-encoding-pragma`: deprecated -- will be removed in 5.0.0. use
[pyupgrade](https://github.com/asottile/pyupgrade) or some other tool.
- #1033 PR by @mxr.
- #1032 issue by @mxr.
4.5.0 - 2023-10-07 4.5.0 - 2023-10-07
================== ==================

View file

@ -15,7 +15,7 @@ Add this to your `.pre-commit-config.yaml`
```yaml ```yaml
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0 # Use the ref you want to point at rev: v4.6.0 # Use the ref you want to point at
hooks: hooks:
- id: trailing-whitespace - id: trailing-whitespace
# - id: ... # - id: ...
@ -127,6 +127,9 @@ The following arguments are available:
removes UTF-8 byte order marker removes UTF-8 byte order marker
#### `fix-encoding-pragma` #### `fix-encoding-pragma`
_Deprecated since py2 is EOL - use [pyupgrade](https://github.com/asottile/pyupgrade) instead._
Add `# -*- coding: utf-8 -*-` to the top of python files. Add `# -*- coding: utf-8 -*-` to the top of python files.
- To remove the coding pragma pass `--remove` (useful in a python3-only codebase) - To remove the coding pragma pass `--remove` (useful in a python3-only codebase)

View file

@ -1,6 +1,7 @@
from __future__ import annotations from __future__ import annotations
import argparse import argparse
import sys
from typing import IO from typing import IO
from typing import NamedTuple from typing import NamedTuple
from typing import Sequence from typing import Sequence
@ -107,6 +108,13 @@ def _normalize_pragma(pragma: str) -> bytes:
def main(argv: Sequence[str] | None = None) -> int: def main(argv: Sequence[str] | None = None) -> int:
print(
'warning: this hook is deprecated and will be removed in a future '
'release because py2 is EOL. instead, use '
'https://github.com/asottile/pyupgrade',
file=sys.stderr,
)
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
'Fixes the encoding pragma of python files', 'Fixes the encoding pragma of python files',
) )

View file

@ -45,6 +45,11 @@ class Requirement:
elif requirement.value == b'\n': elif requirement.value == b'\n':
return False return False
else: else:
# if 2 requirements have the same name, the one with comments
# needs to go first (so that when removing duplicates, the one
# with comments is kept)
if self.name == requirement.name:
return bool(self.comments) > bool(requirement.comments)
return self.name < requirement.name return self.name < requirement.name
def is_complete(self) -> bool: def is_complete(self) -> bool:
@ -113,10 +118,14 @@ def fix_requirements(f: IO[bytes]) -> int:
if req.value != b'pkg-resources==0.0.0\n' if req.value != b'pkg-resources==0.0.0\n'
] ]
# sort the requirements and remove duplicates
prev = None
for requirement in sorted(requirements): for requirement in sorted(requirements):
after.extend(requirement.comments) after.extend(requirement.comments)
assert requirement.value, requirement.value assert requirement.value, requirement.value
if prev is None or requirement.value != prev.value:
after.append(requirement.value) after.append(requirement.value)
prev = requirement
after.extend(rest) after.extend(rest)
after_string = b''.join(after) after_string = b''.join(after)

View file

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

View file

@ -68,6 +68,12 @@ from pre_commit_hooks.requirements_txt_fixer import Requirement
b'f<=2\n' b'f<=2\n'
b'g<2\n', b'g<2\n',
), ),
(b'a==1\nb==1\na==1\n', FAIL, b'a==1\nb==1\n'),
(
b'a==1\nb==1\n#comment about a\na==1\n',
FAIL,
b'#comment about a\na==1\nb==1\n',
),
(b'ocflib\nDjango\nPyMySQL\n', FAIL, b'Django\nocflib\nPyMySQL\n'), (b'ocflib\nDjango\nPyMySQL\n', FAIL, b'Django\nocflib\nPyMySQL\n'),
( (
b'-e git+ssh://git_url@tag#egg=ocflib\nDjango\nPyMySQL\n', b'-e git+ssh://git_url@tag#egg=ocflib\nDjango\nPyMySQL\n',