repomatic.long_lines module¶
Wrap the comment and docstring lines that run past the line length.
Ruff’s formatter wraps code, and keeps the line breaks of prose: a comment, or a
paragraph of a docstring, stays as long as it was written
(astral-sh/ruff#7414), and E501
then fails lint-python on it.
autopep8 2.3.2 shortens a comment line only under --aggressive. Even then, it
wraps only the last line of a comment block, to at most 72 characters of text.
fix_long_lines() pushes words down. An overlong line keeps the words that
fit, and the rest open the next line of its paragraph. That line can overflow in
turn, so the push goes on down the paragraph, and its last line gets a new one
below it. The lines above stay as they are and no other line break moves, so the
diff holds only the lines that had to change.
Note
A line that this cannot shorten is left for a human to reword: a code line, a
string literal, a trailing comment, a pragma comment, the summary line of a
docstring, which D205 holds to one line, and a line of a code block, a doctest
or a table in a docstring. So are the two kinds of line E501 itself ignores: a
single word, and a line that ends with a URL starting inside the limit.
- repomatic.long_lines.DEFAULT_LINE_LENGTH = 88¶
The line length
E501checks when no Ruff configuration sets one.
- repomatic.long_lines.PYTHON_SUFFIXES = frozenset({'.py', '.pyi', '.pyw'})¶
The sources this rewrites: notebooks and Cython files do not parse as Python.
- repomatic.long_lines.RUFF_CONFIG_FILES = ('.ruff.toml', 'ruff.toml')¶
The Ruff configuration files that win over
[tool.ruff], in Ruff’s order.
- repomatic.long_lines.FIELD_HANG = 4¶
How far the next lines of a reST field indent past the field name.
- repomatic.long_lines.is_overlong(line, limit)[source]¶
Tell whether
E501reports line at limit.E501skips a line that no wrap can shorten: one that holds a single word, a#before it included, and one that ends with a URL starting inside the limit.
- repomatic.long_lines.wrap_source(source, limit)[source]¶
Wrap the overlong comment and docstring lines of one Python source.
- repomatic.long_lines.ruff_line_length(project_root=None)[source]¶
Read the line length that Ruff checks in project_root.
Ruff reads
.ruff.toml, thenruff.toml, then the[tool.ruff]table ofpyproject.toml, and stops at the first one it finds.- Parameters:
project_root (
Path|None) – The directory to read. Defaults to the current one.- Return type:
- Returns:
The
line-lengththat configuration sets, orDEFAULT_LINE_LENGTH.
- repomatic.long_lines.fix_long_lines(paths=None, line_length=None)[source]¶
Wrap the overlong comment and docstring lines of paths.
A file that does not parse as Python, or that has Windows line endings, is left as it is, with a warning.
- Parameters:
- Return type:
- Returns:
Each file that changed, with how many of its lines got shorter.