Skip to content

Commit 20baf1a

Browse files
authored
Merge pull request #275 from nvtkaszpir/feature/fix-broken-pkg-resources
Provide automatic removal of pkg-resources==0.0.0
2 parents 1bdd699 + 980fc9b commit 20baf1a

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Add this to your `.pre-commit-config.yaml`
9090
- `--indent ...` - Control the indentation (either a number for a number of spaces or a string of whitespace). Defaults to 4 spaces.
9191
- `--no-sort-keys` - when autofixing, retain the original key ordering (instead of sorting the keys)
9292
- `--top-keys comma,separated,keys` - Keys to keep at the top of mappings.
93-
- `requirements-txt-fixer` - Sorts entries in requirements.txt
93+
- `requirements-txt-fixer` - Sorts entries in requirements.txt and removes incorrect entry for `pkg-resources==0.0.0`
9494
- `sort-simple-yaml` - Sorts simple YAML files which consist only of top-level keys, preserving comments and blocks.
9595
- `trailing-whitespace` - Trims trailing whitespace.
9696
- Markdown linebreak trailing spaces preserved for `.md` and`.markdown`;

pre_commit_hooks/requirements_txt_fixer.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ def fix_requirements(f):
6969
else:
7070
rest = []
7171

72+
# find and remove pkg-resources==0.0.0
73+
# which is automatically added by broken pip package under Debian
74+
requirements = [
75+
req for req in requirements
76+
if req.value != b'pkg-resources==0.0.0\n'
77+
]
78+
7279
for requirement in sorted(requirements):
7380
after.extend(requirement.comments)
7481
after.append(requirement.value)

tests/requirements_txt_fixer_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
FAIL,
2929
b'Django\n-e git+ssh://git_url@tag#egg=ocflib\nPyMySQL\n',
3030
),
31+
(b'bar\npkg-resources==0.0.0\nfoo\n', FAIL, b'bar\nfoo\n'),
32+
(b'foo\npkg-resources==0.0.0\nbar\n', FAIL, b'bar\nfoo\n'),
3133
),
3234
)
3335
def test_integration(input_s, expected_retval, output, tmpdir):

0 commit comments

Comments
 (0)