Skip to content

Commit

Permalink
fix: excessive whitespace in middle of line
Browse files Browse the repository at this point in the history
  • Loading branch information
weibullguy committed May 28, 2023
1 parent 924f13a commit 9f2a854
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 183 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/do-prioritize-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,19 @@ jobs:
uses: weibullguy/get-labels-action@main

- name: Add High Urgency Labels
if: |
${{ (contains(steps.getlabels.outputs.labels, "C: convention") && contains (steps.getlabels.outputs.labels, "P: bug")) }}
if: '${{ (contains(steps.getlabels.outputs.labels, "C: convention") && contains (steps.getlabels.outputs.labels, "P: bug")) }}'
uses: andymckay/labeler@master
with:
add-labels: "U: high"

- name: Add Medium Urgency Labels
if: |
${{ (contains(steps.getlabels.outputs.labels, "C: style") && contains(steps.getlabels.outputs.labels, "P: bug")) || (contains(steps.getlabels.outputs.labels, "C: stakeholder") && contains(steps.getlabels.outputs.labels, "P: bug")) || (contains(steps.getlabels.outputs.labels, "C: convention") && contains(steps.getlabels.outputs.labels, "P: enhancement")) }}
if: '${{ (contains(steps.getlabels.outputs.labels, "C: style") && contains(steps.getlabels.outputs.labels, "P: bug")) || (contains(steps.getlabels.outputs.labels, "C: stakeholder") && contains(steps.getlabels.outputs.labels, "P: bug")) || (contains(steps.getlabels.outputs.labels, "C: convention") && contains(steps.getlabels.outputs.labels, "P: enhancement")) }}'
uses: andymckay/labeler@master
with:
add-labels: "U: medium"

- name: Add Low Urgency Labels
if: |
${{ (contains(steps.getlabels.outputs.labels, "C: style") && contains(steps.getlabels.outputs.labels, "P: enhancement")) || (contains(steps.getlabels.outputs.labels, "C: stakeholder") && contains(steps.getlabels.outputs.labels, "P: enhancement")) || contains(steps.getlabels.outputs.labels, "doc") || contains(steps.getlabels.outputs.labels, "chore") }}
if: '${{ (contains(steps.getlabels.outputs.labels, "C: style") && contains(steps.getlabels.outputs.labels, "P: enhancement")) || (contains(steps.getlabels.outputs.labels, "C: stakeholder") && contains(steps.getlabels.outputs.labels, "P: enhancement")) || contains(steps.getlabels.outputs.labels, "doc") || contains(steps.getlabels.outputs.labels, "chore") }}'
uses: andymckay/labeler@master
with:
add-labels: "U: low"
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
project = "docformatter"
copyright = "2022-2023, Steven Myint"
author = "Steven Myint"
release = "1.7.2-rc1"
release = "1.7.2-rc2"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "docformatter"
version = "1.7.2-rc1"
version = "1.7.2-rc2"
description = "Formats docstrings to follow PEP 257"
authors = ["Steven Myint"]
maintainers = [
Expand Down
2 changes: 1 addition & 1 deletion src/docformatter/__pkginfo__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
# SOFTWARE.
"""Package information for docformatter."""

__version__ = "1.7.2-rc1"
__version__ = "1.7.2-rc2"
1 change: 1 addition & 0 deletions src/docformatter/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ def _do_format_docstring( # noqa PLR0911
self.args.style,
)
or _syntax.do_find_directives(summary)
or _syntax.do_find_links(summary)
):
# Something is probably not right with the splitting.
return docstring
Expand Down
75 changes: 42 additions & 33 deletions src/docformatter/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,20 @@ def do_split_description(
_url_idx = do_find_links(text)

# Check if the description contains any field lists.
_parameter_idx, _wrap_parameters = do_find_field_lists(text, style)

if not _url_idx and not (_parameter_idx and _wrap_parameters):
_field_idx, _wrap_fields = do_find_field_lists(text, style)

# Field list wrapping takes precedence over URL wrapping.
for _fieldl, _fieldu in _field_idx:
for _key, _value in enumerate(_url_idx):
if (
_value[0] == _fieldl
or _value[0] == _fieldu
or _value[1] == _fieldl
or _value[1] == _fieldu
):
_url_idx.pop(_key)

if not _url_idx and not (_field_idx and _wrap_fields):
return description_to_list(
text,
indentation,
Expand All @@ -397,10 +408,10 @@ def do_split_description(
wrap_length,
)

if _parameter_idx:
_lines, _text_idx = do_wrap_parameter_lists(
if _field_idx:
_lines, _text_idx = do_wrap_field_lists(
text,
_parameter_idx,
_field_idx,
_lines,
_text_idx,
indentation,
Expand All @@ -421,22 +432,22 @@ def do_split_description(
return _lines


def do_wrap_parameter_lists( # noqa: PLR0913
def do_wrap_field_lists( # noqa: PLR0913
text: str,
parameter_idx: List[Tuple[int, int]],
field_idx: List[Tuple[int, int]],
lines: List[str],
text_idx: int,
indentation: str,
wrap_length: int,
) -> Tuple[List[str], int]:
"""Wrap parameter lists in the long description.
"""Wrap field lists in the long description.
Parameters
----------
text : str
The long description text.
parameter_idx : list
The list of parameter list indices found in the description text.
field_idx : list
The list of field list indices found in the description text.
lines : list
The list of formatted lines in the description that come before the
first parameter list item.
Expand All @@ -456,46 +467,44 @@ def do_wrap_parameter_lists( # noqa: PLR0913
"""
lines.extend(
description_to_list(
text[text_idx : parameter_idx[0][0]],
text[text_idx : field_idx[0][0]],
indentation,
wrap_length,
)
)

for _idx, _parameter in enumerate(parameter_idx):
for _idx, _field in enumerate(field_idx):
try:
_parameter_description = text[
_parameter[1] : parameter_idx[_idx + 1][0]
].strip()
_field_description = text[_field[1] : field_idx[_idx + 1][0]].strip()
except IndexError:
_parameter_description = (
text[_parameter[1] :].strip().replace(" ", "").replace("\t", "")
)
_field_description = text[
_field[1] :
].strip() # .replace(" ", "").replace("\t", "")

if len(_parameter_description) <= (wrap_length - len(indentation)):
if len(_field_description) <= (wrap_length - len(indentation)):
lines.append(
f"{indentation}{text[_parameter[0]: _parameter[1]]} "
f"{_parameter_description}"
f"{indentation}{text[_field[0]: _field[1]]} " f"{_field_description}"
)
else:
if len(indentation) > DEFAULT_INDENT:
_subsequent = indentation + int(0.5 * len(indentation)) * " "
else:
_subsequent = 2 * indentation

lines.extend(
textwrap.wrap(
textwrap.dedent(
f"{text[_parameter[0]:_parameter[1]]} "
f"{_parameter_description.strip()}"
),
width=wrap_length,
initial_indent=indentation,
subsequent_indent=_subsequent,
)
_wrapped_fields = textwrap.wrap(
textwrap.dedent(
f"{text[_field[0]:_field[1]]} " f"{_field_description.strip()}"
),
width=wrap_length,
initial_indent=indentation,
subsequent_indent=_subsequent,
)
for _idx, _f in enumerate(_wrapped_fields):
_indent = indentation if _idx == 0 else _subsequent
_wrapped_fields[_idx] = f"{_indent}{re.sub(' +', ' ', _f.strip())}"
lines.extend(_wrapped_fields)

text_idx = _parameter[1]
text_idx = _field[1]

return lines, text_idx

Expand Down
Loading

0 comments on commit 9f2a854

Please sign in to comment.