Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
704d1fec
Unverified
Commit
704d1fec
authored
Jan 11, 2022
by
Sylvain Gugger
Committed by
GitHub
Jan 11, 2022
Browse files
Doc styler tip (#15105)
* Add new lines before/after tips * Check end of lines
parent
68d92519
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
1 deletion
+12
-1
utils/style_doc.py
utils/style_doc.py
+12
-1
No files found.
utils/style_doc.py
View file @
704d1fec
...
@@ -41,7 +41,8 @@ _re_args = re.compile("^\s*(Args?|Arguments?|Params?|Parameters?):\s*$")
...
@@ -41,7 +41,8 @@ _re_args = re.compile("^\s*(Args?|Arguments?|Params?|Parameters?):\s*$")
_re_returns
=
re
.
compile
(
"^\s*Returns?:\s*$"
)
_re_returns
=
re
.
compile
(
"^\s*Returns?:\s*$"
)
# Matches the special tag to ignore some paragraphs.
# Matches the special tag to ignore some paragraphs.
_re_doc_ignore
=
re
.
compile
(
r
"(\.\.|#)\s*docstyle-ignore"
)
_re_doc_ignore
=
re
.
compile
(
r
"(\.\.|#)\s*docstyle-ignore"
)
# Re pattern that matches <Tip>, </Tip> and <Tip warning={true}> blocks.
_re_tip
=
re
.
compile
(
"^\s*</?Tip(>|\s+warning={true}>)\s*$"
)
DOCTEST_PROMPTS
=
[
">>>"
,
"..."
]
DOCTEST_PROMPTS
=
[
">>>"
,
"..."
]
...
@@ -275,6 +276,8 @@ def style_docstring(docstring, max_len):
...
@@ -275,6 +276,8 @@ def style_docstring(docstring, max_len):
new_paragraph
=
new_paragraph
or
list_search
is
not
None
new_paragraph
=
new_paragraph
or
list_search
is
not
None
# Code block beginning
# Code block beginning
new_paragraph
=
new_paragraph
or
code_search
is
not
None
new_paragraph
=
new_paragraph
or
code_search
is
not
None
# Beginning/end of tip
new_paragraph
=
new_paragraph
or
_re_tip
.
search
(
line
)
# In this case, we treat the current paragraph
# In this case, we treat the current paragraph
if
not
in_code
and
new_paragraph
and
current_paragraph
is
not
None
and
len
(
current_paragraph
)
>
0
:
if
not
in_code
and
new_paragraph
and
current_paragraph
is
not
None
and
len
(
current_paragraph
)
>
0
:
...
@@ -318,6 +321,14 @@ def style_docstring(docstring, max_len):
...
@@ -318,6 +321,14 @@ def style_docstring(docstring, max_len):
elif
_re_args
.
search
(
line
):
elif
_re_args
.
search
(
line
):
new_lines
.
append
(
line
)
new_lines
.
append
(
line
)
param_indent
=
find_indent
(
lines
[
idx
+
1
])
param_indent
=
find_indent
(
lines
[
idx
+
1
])
elif
_re_tip
.
search
(
line
):
# Add a new line before if not present
if
not
is_empty_line
(
new_lines
[
-
1
]):
new_lines
.
append
(
""
)
new_lines
.
append
(
line
)
# Add a new line after if not present
if
idx
<
len
(
lines
)
-
1
and
not
is_empty_line
(
lines
[
idx
+
1
]):
new_lines
.
append
(
""
)
elif
current_paragraph
is
None
or
find_indent
(
line
)
!=
current_indent
:
elif
current_paragraph
is
None
or
find_indent
(
line
)
!=
current_indent
:
indent
=
find_indent
(
line
)
indent
=
find_indent
(
line
)
# Special behavior for parameters intros.
# Special behavior for parameters intros.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment