summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-10-16 11:18:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-10-16 11:18:13 +0000
commit535187ceaf88786aaf22560790564f1f6965ba30 (patch)
tree82456c5d0bc77961759812ddd85414435ba89127
parentAdding upstream version 4.4.0+dfsg. (diff)
downloadpre-commit-hooks-535187ceaf88786aaf22560790564f1f6965ba30.tar.xz
pre-commit-hooks-535187ceaf88786aaf22560790564f1f6965ba30.zip
Adding upstream version 4.5.0+dfsg.upstream/4.5.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
-rw-r--r--.github/workflows/main.yml19
-rw-r--r--.pre-commit-config.yaml25
-rw-r--r--.pre-commit-hooks.yaml2
-rw-r--r--CHANGELOG.md24
-rw-r--r--README.md16
-rw-r--r--azure-pipelines.yml23
-rw-r--r--pre_commit_hooks/check_added_large_files.py2
-rw-r--r--pre_commit_hooks/check_yaml.py2
-rw-r--r--pre_commit_hooks/debug_statement_hook.py1
-rw-r--r--pre_commit_hooks/destroyed_symlinks.py6
-rw-r--r--pre_commit_hooks/file_contents_sorter.py5
-rw-r--r--pre_commit_hooks/string_fixer.py15
-rw-r--r--setup.cfg6
-rw-r--r--tests/file_contents_sorter_test.py4
-rw-r--r--tests/string_fixer_test.py6
-rw-r--r--tox.ini2
16 files changed, 99 insertions, 59 deletions
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
new file mode 100644
index 0000000..088a066
--- /dev/null
+++ b/.github/workflows/main.yml
@@ -0,0 +1,19 @@
+name: main
+
+on:
+ push:
+ branches: [main, test-me-*]
+ tags: '*'
+ pull_request:
+
+jobs:
+ main-windows:
+ uses: asottile/workflows/.github/workflows/tox.yml@v1.5.0
+ with:
+ env: '["py38"]'
+ os: windows-latest
+ main-linux:
+ uses: asottile/workflows/.github/workflows/tox.yml@v1.5.0
+ with:
+ env: '["py38", "py39", "py310", "py311"]'
+ os: ubuntu-latest
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index cfe2378..d9ffea2 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- rev: v4.4.0
+ rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
@@ -10,34 +10,33 @@ repos:
- id: name-tests-test
- id: requirements-txt-fixer
- repo: https://github.com/asottile/setup-cfg-fmt
- rev: v2.2.0
+ rev: v2.5.0
hooks:
- id: setup-cfg-fmt
-- repo: https://github.com/asottile/reorder_python_imports
- rev: v3.9.0
+- repo: https://github.com/asottile/reorder-python-imports
+ rev: v3.12.0
hooks:
- id: reorder-python-imports
- args: [--py37-plus, --add-import, 'from __future__ import annotations']
+ args: [--py38-plus, --add-import, 'from __future__ import annotations']
- repo: https://github.com/asottile/add-trailing-comma
- rev: v2.3.0
+ rev: v3.1.0
hooks:
- id: add-trailing-comma
- args: [--py36-plus]
- repo: https://github.com/asottile/pyupgrade
- rev: v3.2.2
+ rev: v3.14.0
hooks:
- id: pyupgrade
- args: [--py37-plus]
-- repo: https://github.com/pre-commit/mirrors-autopep8
- rev: v2.0.0
+ args: [--py38-plus]
+- repo: https://github.com/hhatto/autopep8
+ rev: v2.0.4
hooks:
- id: autopep8
- repo: https://github.com/PyCQA/flake8
- rev: 5.0.4
+ rev: 6.1.0
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
- rev: v0.991
+ rev: v1.5.1
hooks:
- id: mypy
additional_dependencies: [types-all]
diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml
index f8523d4..c0d811c 100644
--- a/.pre-commit-hooks.yaml
+++ b/.pre-commit-hooks.yaml
@@ -185,7 +185,7 @@
description: sorts entries in requirements.txt.
entry: requirements-txt-fixer
language: python
- files: requirements.*\.txt$
+ files: (requirements|constraints).*\.txt$
- id: sort-simple-yaml
name: sort simple yaml files
description: sorts simple yaml files which consist only of top-level keys, preserving comments and blocks.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 36d5aeb..c1daaba 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,27 @@
+4.5.0 - 2023-10-07
+==================
+
+### Features
+- `requirements-txt-fixer`: also sort `constraints.txt` by default.
+ - #857 PR by @lev-blit.
+ - #830 issue by @PLPeeters.
+- `debug-statements`: add `bpdb` debugger.
+ - #942 PR by @mwip.
+ - #941 issue by @mwip.
+
+### Fixes
+- `file-contents-sorter`: fix sorting an empty file.
+ - #944 PR by @RoelAdriaans.
+ - #935 issue by @paduszyk.
+- `double-quote-string-fixer`: don't rewrite inside f-strings in 3.12+.
+ - #973 PR by @asottile.
+ - #971 issue by @XuehaiPan.
+
+## Migrating
+- now requires python >= 3.8.
+ - #926 PR by @asottile.
+ - #927 PR by @asottile.
+
4.4.0 - 2022-11-23
==================
diff --git a/README.md b/README.md
index 9aa966d..9ae7ec5 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,4 @@
-[![Build Status](https://asottile.visualstudio.com/asottile/_apis/build/status/pre-commit.pre-commit-hooks?branchName=main)](https://asottile.visualstudio.com/asottile/_build/latest?definitionId=17&branchName=main)
-[![Azure DevOps coverage](https://img.shields.io/azure-devops/coverage/asottile/asottile/17/main.svg)](https://dev.azure.com/asottile/asottile/_build/latest?definitionId=17&branchName=main)
+[![build status](https://github.com/pre-commit/pre-commit-hooks/actions/workflows/main.yml/badge.svg)](https://github.com/pre-commit/pre-commit-hooks/actions/workflows/main.yml)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/pre-commit/pre-commit-hooks/main.svg)](https://results.pre-commit.ci/latest/github/pre-commit/pre-commit-hooks/main)
pre-commit-hooks
@@ -16,7 +15,7 @@ Add this to your `.pre-commit-config.yaml`
```yaml
- repo: https://github.com/pre-commit/pre-commit-hooks
- rev: v4.4.0 # Use the ref you want to point at
+ rev: v4.5.0 # Use the ref you want to point at
hooks:
- id: trailing-whitespace
# - id: ...
@@ -118,6 +117,11 @@ Makes sure files end in a newline and only a newline.
Sort the lines in specified files (defaults to alphabetical).
You must provide the target [`files`](https://pre-commit.com/#config-files) as input.
Note that this hook WILL remove blank lines and does NOT respect any comments.
+All newlines will be converted to line feeds (`\n`).
+
+The following arguments are available:
+- `--ignore-case` - fold lower case to upper case characters.
+- `--unique` - ensure each line is unique.
#### `fix-byte-order-marker`
removes UTF-8 byte order marker
@@ -126,10 +130,6 @@ removes UTF-8 byte order marker
Add `# -*- coding: utf-8 -*-` to the top of python files.
- To remove the coding pragma pass `--remove` (useful in a python3-only codebase)
-The following arguments are available:
-- `--ignore-case` - fold lower case to upper case characters.
-- `--unique` - ensure each line is unique.
-
#### `forbid-new-submodules`
Prevent addition of new git submodules.
@@ -180,7 +180,7 @@ the following commandline options:
- `--top-keys comma,separated,keys` - Keys to keep at the top of mappings.
#### `requirements-txt-fixer`
-Sorts entries in requirements.txt and removes incorrect entry for `pkg-resources==0.0.0`
+Sorts entries in requirements.txt and constraints.txt and removes incorrect entry for `pkg-resources==0.0.0`
#### `sort-simple-yaml`
Sorts simple YAML files which consist only of top-level
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
deleted file mode 100644
index 117b014..0000000
--- a/azure-pipelines.yml
+++ /dev/null
@@ -1,23 +0,0 @@
-trigger:
- branches:
- include: [main, test-me-*]
- tags:
- include: ['*']
-
-resources:
- repositories:
- - repository: asottile
- type: github
- endpoint: github
- name: asottile/azure-pipeline-templates
- ref: refs/tags/v2.4.0
-
-jobs:
-- template: job--python-tox.yml@asottile
- parameters:
- toxenvs: [py38]
- os: windows
-- template: job--python-tox.yml@asottile
- parameters:
- toxenvs: [py37, py38, py39, py310]
- os: linux
diff --git a/pre_commit_hooks/check_added_large_files.py b/pre_commit_hooks/check_added_large_files.py
index 79c8d4e..9e0619b 100644
--- a/pre_commit_hooks/check_added_large_files.py
+++ b/pre_commit_hooks/check_added_large_files.py
@@ -46,7 +46,7 @@ def find_large_added_files(
filenames_filtered &= added_files()
for filename in filenames_filtered:
- kb = int(math.ceil(os.stat(filename).st_size / 1024))
+ kb = math.ceil(os.stat(filename).st_size / 1024)
if kb > maxkb:
print(f'{filename} ({kb} KB) exceeds {maxkb} KB.')
retv = 1
diff --git a/pre_commit_hooks/check_yaml.py b/pre_commit_hooks/check_yaml.py
index 250794e..9563347 100644
--- a/pre_commit_hooks/check_yaml.py
+++ b/pre_commit_hooks/check_yaml.py
@@ -46,7 +46,7 @@ def main(argv: Sequence[str] | None = None) -> int:
'--unsafe', action='store_true',
help=(
'Instead of loading the files, simply parse them for syntax. '
- 'A syntax-only check enables extensions and unsafe contstructs '
+ 'A syntax-only check enables extensions and unsafe constructs '
'which would otherwise be forbidden. Using this option removes '
'all guarantees of portability to other yaml implementations. '
'Implies --allow-multiple-documents'
diff --git a/pre_commit_hooks/debug_statement_hook.py b/pre_commit_hooks/debug_statement_hook.py
index 9ada657..cf544c7 100644
--- a/pre_commit_hooks/debug_statement_hook.py
+++ b/pre_commit_hooks/debug_statement_hook.py
@@ -8,6 +8,7 @@ from typing import Sequence
DEBUG_STATEMENTS = {
+ 'bpdb',
'ipdb',
'pdb',
'pdbr',
diff --git a/pre_commit_hooks/destroyed_symlinks.py b/pre_commit_hooks/destroyed_symlinks.py
index 88253c0..f256908 100644
--- a/pre_commit_hooks/destroyed_symlinks.py
+++ b/pre_commit_hooks/destroyed_symlinks.py
@@ -76,11 +76,7 @@ def main(argv: Sequence[str] | None = None) -> int:
for destroyed_link in destroyed_links:
print(f'- {destroyed_link}')
print('You should unstage affected files:')
- print(
- '\tgit reset HEAD -- {}'.format(
- ' '.join(shlex.quote(link) for link in destroyed_links),
- ),
- )
+ print(f'\tgit reset HEAD -- {shlex.join(destroyed_links)}')
print(
'And retry commit. As a long term solution '
'you may try to explicitly tell git that your '
diff --git a/pre_commit_hooks/file_contents_sorter.py b/pre_commit_hooks/file_contents_sorter.py
index c5691f0..02bdbcc 100644
--- a/pre_commit_hooks/file_contents_sorter.py
+++ b/pre_commit_hooks/file_contents_sorter.py
@@ -37,7 +37,10 @@ def sort_file_contents(
after = sorted(lines, key=key)
before_string = b''.join(before)
- after_string = b'\n'.join(after) + b'\n'
+ after_string = b'\n'.join(after)
+
+ if after_string:
+ after_string += b'\n'
if before_string == after_string:
return PASS
diff --git a/pre_commit_hooks/string_fixer.py b/pre_commit_hooks/string_fixer.py
index 0ef9bc7..d1b1c4a 100644
--- a/pre_commit_hooks/string_fixer.py
+++ b/pre_commit_hooks/string_fixer.py
@@ -3,9 +3,16 @@ from __future__ import annotations
import argparse
import io
import re
+import sys
import tokenize
from typing import Sequence
+if sys.version_info >= (3, 12): # pragma: >=3.12 cover
+ FSTRING_START = tokenize.FSTRING_START
+ FSTRING_END = tokenize.FSTRING_END
+else: # pragma: <3.12 cover
+ FSTRING_START = FSTRING_END = -1
+
START_QUOTE_RE = re.compile('^[a-zA-Z]*"')
@@ -40,11 +47,17 @@ def fix_strings(filename: str) -> int:
# Basically a mutable string
splitcontents = list(contents)
+ fstring_depth = 0
+
# Iterate in reverse so the offsets are always correct
tokens_l = list(tokenize.generate_tokens(io.StringIO(contents).readline))
tokens = reversed(tokens_l)
for token_type, token_text, (srow, scol), (erow, ecol), _ in tokens:
- if token_type == tokenize.STRING:
+ if token_type == FSTRING_START: # pragma: >=3.12 cover
+ fstring_depth += 1
+ elif token_type == FSTRING_END: # pragma: >=3.12 cover
+ fstring_depth -= 1
+ elif fstring_depth == 0 and token_type == tokenize.STRING:
new_text = handle_match(token_text)
splitcontents[
line_offsets[srow] + scol:
diff --git a/setup.cfg b/setup.cfg
index 834b3e8..6a4c459 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = pre_commit_hooks
-version = 4.4.0
+version = 4.5.0
description = Some out-of-the-box hooks for pre-commit.
long_description = file: README.md
long_description_content_type = text/markdown
@@ -8,7 +8,7 @@ url = https://github.com/pre-commit/pre-commit-hooks
author = Anthony Sottile
author_email = asottile@umich.edu
license = MIT
-license_file = LICENSE
+license_files = LICENSE
classifiers =
License :: OSI Approved :: MIT License
Programming Language :: Python :: 3
@@ -21,7 +21,7 @@ packages = find:
install_requires =
ruamel.yaml>=0.15
tomli>=1.1.0;python_version<"3.11"
-python_requires = >=3.7
+python_requires = >=3.8
[options.packages.find]
exclude =
diff --git a/tests/file_contents_sorter_test.py b/tests/file_contents_sorter_test.py
index 5e79e40..49b3b79 100644
--- a/tests/file_contents_sorter_test.py
+++ b/tests/file_contents_sorter_test.py
@@ -10,7 +10,9 @@ from pre_commit_hooks.file_contents_sorter import PASS
@pytest.mark.parametrize(
('input_s', 'argv', 'expected_retval', 'output'),
(
- (b'', [], FAIL, b'\n'),
+ (b'', [], PASS, b''),
+ (b'\n', [], FAIL, b''),
+ (b'\n\n', [], FAIL, b''),
(b'lonesome\n', [], PASS, b'lonesome\n'),
(b'missing_newline', [], FAIL, b'missing_newline\n'),
(b'newline\nmissing', [], FAIL, b'missing\nnewline\n'),
diff --git a/tests/string_fixer_test.py b/tests/string_fixer_test.py
index 9dd7315..8eb164c 100644
--- a/tests/string_fixer_test.py
+++ b/tests/string_fixer_test.py
@@ -37,6 +37,12 @@ TESTS = (
1,
),
('"foo""bar"', "'foo''bar'", 1),
+ pytest.param(
+ "f'hello{\"world\"}'",
+ "f'hello{\"world\"}'",
+ 0,
+ id='ignore nested fstrings',
+ ),
)
diff --git a/tox.ini b/tox.ini
index cb2b92a..11340f4 100644
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
[tox]
-envlist = py37,py38,pypy3,pre-commit
+envlist = py,pre-commit
[testenv]
deps = -rrequirements-dev.txt