Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pre Commit Hooks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
opensource
Pre Commit Hooks
Commits
361a6ac1
Commit
361a6ac1
authored
7 years ago
by
Anthony Sottile
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #243 from pre-commit/comment_only_requirements_txt
Fix requirements-txt-fixer for comments at end of file
parents
7f0d6274
86691eda
Branches
Branches containing commit
Tags
Tags containing commit
Loading
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pre_commit_hooks/requirements_txt_fixer.py
+7
-0
7 additions, 0 deletions
pre_commit_hooks/requirements_txt_fixer.py
tests/requirements_txt_fixer_test.py
+2
-0
2 additions, 0 deletions
tests/requirements_txt_fixer_test.py
with
9 additions
and
0 deletions
pre_commit_hooks/requirements_txt_fixer.py
+
7
−
0
View file @
361a6ac1
...
...
@@ -63,9 +63,16 @@ def fix_requirements(f):
else
:
requirement
.
value
=
line
# if a file ends in a comment, preserve it at the end
if
requirements
[
-
1
].
value
is
None
:
rest
=
requirements
.
pop
().
comments
else
:
rest
=
[]
for
requirement
in
sorted
(
requirements
):
after
.
extend
(
requirement
.
comments
)
after
.
append
(
requirement
.
value
)
after
.
extend
(
rest
)
after_string
=
b
''
.
join
(
after
)
...
...
This diff is collapsed.
Click to expand it.
tests/requirements_txt_fixer_test.py
+
2
−
0
View file @
361a6ac1
...
...
@@ -11,6 +11,8 @@ from pre_commit_hooks.requirements_txt_fixer import Requirement
(
(
b
''
,
PASS
,
b
''
),
(
b
'
\n
'
,
PASS
,
b
'
\n
'
),
(
b
'
# intentionally empty
\n
'
,
PASS
,
b
'
# intentionally empty
\n
'
),
(
b
'
foo
\n
# comment at end
\n
'
,
PASS
,
b
'
foo
\n
# comment at end
\n
'
),
(
b
'
foo
\n
bar
\n
'
,
FAIL
,
b
'
bar
\n
foo
\n
'
),
(
b
'
bar
\n
foo
\n
'
,
PASS
,
b
'
bar
\n
foo
\n
'
),
(
b
'
#comment1
\n
foo
\n
#comment2
\n
bar
\n
'
,
FAIL
,
b
'
#comment2
\n
bar
\n
#comment1
\n
foo
\n
'
),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment