diff --git a/README.md b/README.md index d650c17..eaf8d3e 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ Add this to your `.pre-commit-config.yaml` - `--indent ...` - Control the indentation (either a number for a number of spaces or a string of whitespace). Defaults to 4 spaces. - `--no-sort-keys` - when autofixing, retain the original key ordering (instead of sorting the keys) - `--top-keys comma,separated,keys` - Keys to keep at the top of mappings. -- `requirements-txt-fixer` - Sorts entries in requirements.txt +- `requirements-txt-fixer` - Sorts entries in requirements.txt and removes incorrect entry for `pkg-resources==0.0.0` - `sort-simple-yaml` - Sorts simple YAML files which consist only of top-level keys, preserving comments and blocks. - `trailing-whitespace` - Trims trailing whitespace. - Markdown linebreak trailing spaces preserved for `.md` and`.markdown`; diff --git a/pre_commit_hooks/requirements_txt_fixer.py b/pre_commit_hooks/requirements_txt_fixer.py index 1ee6fac..6dcf8d0 100644 --- a/pre_commit_hooks/requirements_txt_fixer.py +++ b/pre_commit_hooks/requirements_txt_fixer.py @@ -69,6 +69,13 @@ def fix_requirements(f): else: rest = [] + # find and remove pkg-resources==0.0.0 + # 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' + ] + for requirement in sorted(requirements): after.extend(requirement.comments) after.append(requirement.value) diff --git a/tests/requirements_txt_fixer_test.py b/tests/requirements_txt_fixer_test.py index 87e7b0c..437cebd 100644 --- a/tests/requirements_txt_fixer_test.py +++ b/tests/requirements_txt_fixer_test.py @@ -28,6 +28,8 @@ from pre_commit_hooks.requirements_txt_fixer import Requirement FAIL, b'Django\n-e git+ssh://git_url@tag#egg=ocflib\nPyMySQL\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'), ), ) def test_integration(input_s, expected_retval, output, tmpdir):