Skip to content
GitLab
探索
项目
群组
代码片段
项目
群组
代码片段
/
帮助
帮助
支持
社区论坛
快捷键
?
提交反馈
登录
切换导航
菜单
打开侧边栏
ExternalRepo
pre-commit-hooks
提交
da2ea3f7
提交
da2ea3f7
编辑于
5年前
作者:
Barak Y. Reif
浏览文件
操作
下载
电子邮件补丁
差异文件
add new line post reading requirements file, change before from tuple to list, add test cases
上级
277f875b
main
remove-fix-encoding-pragma
v4.6.0
v4.5.0
v4.4.0
v4.3.0
v4.2.0
v4.1.0
v4.0.1
v4.0.0
v3.4.0
v3.3.0
v3.2.0
v3.1.0
v3.0.1
v3.0.0
v2.5.0
v2.4.0
无相关合并请求
变更
2
Hide whitespace changes
Inline
Side-by-side
显示
2 个更改的文件
pre_commit_hooks/requirements_txt_fixer.py
+7
-2
pre_commit_hooks/requirements_txt_fixer.py
tests/requirements_txt_fixer_test.py
+3
-0
tests/requirements_txt_fixer_test.py
有
10 个添加
和
2 个删除
+10
-2
pre_commit_hooks/requirements_txt_fixer.py
+
7
-
2
浏览文件 @
da2ea3f7
...
...
@@ -40,9 +40,14 @@ class Requirement(object):
def
fix_requirements
(
f
):
# type: (IO[bytes]) -> int
requirements
=
[]
# type: List[Requirement]
before
=
tuple
(
f
)
before
=
list
(
f
)
# type: List[bytes]
after
=
[]
# type: List[bytes]
# adds new line in case one is missing
# AND a change to the requirements file is needed regardless:
if
before
and
not
before
[
-
1
].
endswith
(
b
'
\n
'
):
before
[
-
1
]
+=
b
'
\n
'
before_string
=
b
''
.
join
(
before
)
# If the file is empty (i.e. only whitespace/newlines) exit early
...
...
@@ -94,7 +99,7 @@ def fix_requirements(f): # type: (IO[bytes]) -> int
after_string
=
b
''
.
join
(
after
)
if
before_string
==
after_string
:
if
before_string
.
rstrip
()
==
after_string
.
rstrip
()
:
return
PASS
else
:
f
.
seek
(
0
)
...
...
This diff is collapsed.
Click to expand it.
tests/requirements_txt_fixer_test.py
+
3
-
0
浏览文件 @
da2ea3f7
...
...
@@ -15,6 +15,9 @@ from pre_commit_hooks.requirements_txt_fixer import Requirement
(
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
'a
\n
c
\n
b
\n
'
,
FAIL
,
b
'a
\n
b
\n
c
\n
'
),
(
b
'a
\n
c
\n
b'
,
FAIL
,
b
'a
\n
b
\n
c
\n
'
),
(
b
'a
\n
b
\n
c'
,
PASS
,
b
'a
\n
b
\n
c'
),
(
b
'#comment1
\n
foo
\n
#comment2
\n
bar
\n
'
,
FAIL
,
...
...
This diff is collapsed.
Click to expand it.
编辑
预览
支持
Markdown
0%
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录
菜单
探索
项目
群组
代码片段