Skip to content

Commit

Permalink
Add an initial configuration file for Ruff
Browse files Browse the repository at this point in the history
This reflects the current flake8 settings, save diagnostics
that Ruff does not implement. Ruff's detection of unused variables
seems to be greater than flake8's, so also fix several instances
and add some more files to the per-file ignore list.


git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk/docutils@9795 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
  • Loading branch information
Adam Turner committed Jul 31, 2024
1 parent 2342e99 commit 5d341f3
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 22 deletions.
143 changes: 143 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
target-version = "py39" # Pin Ruff to Python 3.9
line-length = 88
output-format = "full"

[lint]
preview = true
select = [
"E", # pycodestyle
"F", # pyflakes
"W", # pycodestyle
]
ignore = [
"E226", # missing whitespace around arithmetic operator
"E228", # missing whitespace around modulo operator
# not generally frowned on by PEP 8:
# "If operators with different priorities are used, consider adding
# whitespace around the operators with the lowest priority(ies).
# Use your own judgment; …"
]

[lint.per-file-ignores]
# class definitions with "…: pass" on one line
"docutils/__init__.py" = [
"E302",
"E701",
]
"docutils/nodes.py" = [
"E302",
"E701",
]
"docutils/io.py" = [
"E302",
"E701",
]
"docutils/statemachine.py" = [
"E302",
"E701",
"F841",
]
"docutils/utils/__init__.py" = [
"E302",
"E701",
]

# complex regexp definitions
"docutils/parsers/rst/states.py" = [
"E302",
"E701",
"F841",
]
# deprecated module, will be removed
"docutils/utils/error_reporting.py" = [
"E261",
]

# module with 3rd-party origin
"docutils/utils/math/math2html.py" = [
"E241",
"E501",
"E731",
]

# generated auxiliary files
"docutils/utils/math/tex2unichar.py" = [
"E262",
"E501",
]
"docutils/utils/math/mathalphabet2unichar.py" = [
"E501",
]

# allow aligning values in data-collections
"docutils/utils/smartquotes.py" = [
"E241",
]
"docutils/utils/roman.py" = [
"E241",
"E701",
]
"docutils/utils/math/latex2mathml.py" = [
"E221",
"E241",
"E272",
"E501",
"E701",
]
"docutils/writers/xetex/__init__.py" = [
"E241",
]

# also allow '##' to mark deactivated code:
"docutils/writers/latex2e/__init__.py" = [
"E241",
"E266",
]

# ignore unused variables
"docutils/parsers/rst/directives/misc.py" = [
"F841",
]
"docutils/writers/odf_odt/__init__.py" = [
"F841",
]

# included configuration files referencing externally defined variables
"test/functional/tests/*" = [
"F821",
]

# deprecated module, will be removed
"test/test_error_reporting.py" = [
"E261",
]

# Lists with multi-line test output samples
# may contain long lines (E501)
# and are not indented (E122, E124, E128)
"test/test_parsers/*" = [
"E501",
]
"test/test_publisher.py" = [
"E501",
]
"test/test_readers/test_pep/*" = [
"E501",
]
"test/test_transforms/*" = [
"E501",
]
"test/test_writers/*" = [
"E501",
]

# test output contains trailing whitespace, long lines, operator at end
"test/test_writers/test_manpage.py" = [
"W291",
"E501",
]

# ignore long line in string templates
"tools/dev/generate_punctuation_chars.py" = [
"E501",
]
6 changes: 3 additions & 3 deletions docutils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def publish_file(source=None, source_path=None,
# The "*_name" arguments are deprecated.
_name_arg_warning(reader_name, parser_name, writer_name)
# The default is set in publish_programmatically().
output, publisher = publish_programmatically(
output, _publisher = publish_programmatically(
source_class=io.FileInput, source=source, source_path=source_path,
destination_class=io.FileOutput,
destination=destination, destination_path=destination_path,
Expand Down Expand Up @@ -480,7 +480,7 @@ def publish_string(source, source_path=None, destination_path=None,
# The "*_name" arguments are deprecated.
_name_arg_warning(reader_name, parser_name, writer_name)
# The default is set in publish_programmatically().
output, publisher = publish_programmatically(
output, _publisher = publish_programmatically(
source_class=io.StringInput, source=source, source_path=source_path,
destination_class=io.StringOutput,
destination=None, destination_path=destination_path,
Expand Down Expand Up @@ -521,7 +521,7 @@ def publish_parts(source, source_path=None, source_class=io.StringInput,
# The "*_name" arguments are deprecated.
_name_arg_warning(reader_name, parser_name, writer_name)
# The default is set in publish_programmatically().
output, publisher = publish_programmatically(
_output, publisher = publish_programmatically(
source=source, source_path=source_path, source_class=source_class,
destination_class=io.StringOutput,
destination=None, destination_path=destination_path,
Expand Down
2 changes: 1 addition & 1 deletion docutils/parsers/rst/directives/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def run(self):
node = nodes.Element() # anonymous container for parsing
self.state.nested_parse(self.content, self.content_offset, node)
try:
num_cols, col_widths = self.check_list_content(node)
_num_cols, col_widths = self.check_list_content(node)
table_data = [[item.children for item in row_list[0]]
for row_list in node[0]]
header_rows = self.options.get('header-rows', 0)
Expand Down
1 change: 0 additions & 1 deletion docutils/parsers/rst/languages/ka.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
'ნაგულისხმევი-როლი': 'default-role',
'სათაური': 'title',
'განყ-ნომერი': 'sectnum',
'განყ-ნომერი': 'sectnum',
'საფრთხე': 'danger',
'ფრთხილად': 'caution',
'შეცდომა': 'error',
Expand Down
4 changes: 2 additions & 2 deletions docutils/writers/latex2e/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,10 +1202,10 @@ def __init__(self, document, babel_class=Babel):
self.literal_block_env = ''
self.literal_block_options = ''
if settings.literal_block_env:
(none,
(_none,
self.literal_block_env,
self.literal_block_options,
none) = re.split(r'(\w+)(.*)', settings.literal_block_env)
_none) = re.split(r'(\w+)(.*)', settings.literal_block_env)
elif settings.use_verbatim_when_possible:
self.literal_block_env = 'verbatim'

Expand Down
2 changes: 1 addition & 1 deletion docutils/writers/manpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ def depart_footer(self, node):
pass

def visit_footnote(self, node):
num, text = node.astext().split(None, 1)
num, _text = node.astext().split(maxsplit=1)
num = num.strip()
self.body.append('.IP [%s] 5\n' % self.deunicode(num))

Expand Down
18 changes: 9 additions & 9 deletions test/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def test_dependencies_xml(self):
if PIL and os.path.exists('../docs/user/rst/images/'):
keys += ['figure-image']
expected = [paths[key] for key in keys]
record, output = self.get_record(writer='xml')
record, _output = self.get_record(writer='xml')
# the order of the files is arbitrary
self.assertEqual(sorted(expected), sorted(record))

Expand Down Expand Up @@ -123,23 +123,23 @@ def test_stylesheet_dependencies(self):
'stylesheet': None}
settings.update(latex_settings_overwrites)
settings['embed_stylesheet'] = False
record, output = self.get_record(writer='html',
settings_overrides=settings)
record, _output = self.get_record(writer='html',
settings_overrides=settings)
self.assertTrue(stylesheet not in record,
f'{stylesheet!r} should not be in {record!r}')
record, output = self.get_record(writer='latex',
settings_overrides=settings)
record, _output = self.get_record(writer='latex',
settings_overrides=settings)
self.assertTrue(stylesheet not in record,
f'{stylesheet!r} should not be in {record!r}')

settings['embed_stylesheet'] = True
record, output = self.get_record(writer='html',
settings_overrides=settings)
record, _output = self.get_record(writer='html',
settings_overrides=settings)
self.assertTrue(stylesheet in record,
f'{stylesheet!r} should be in {record!r}')
settings['embed_stylesheet'] = True
record, output = self.get_record(writer='latex',
settings_overrides=settings)
record, _output = self.get_record(writer='latex',
settings_overrides=settings)
self.assertTrue(stylesheet in record,
f'{stylesheet!r} should be in {record!r}')

Expand Down
4 changes: 2 additions & 2 deletions test/test_parsers/test_rst/test_TableParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_parse_table(self):
parser = tableparser.GridTableParser()
for name, cases in totest.items():
for casenum, case in enumerate(cases):
case_input, case_table, case_expected = case
case_input, case_table, _case_expected = case
lines_input = StringList(string2lines(case_input), 'test data')
parser.setup(lines_input)
try:
Expand All @@ -40,7 +40,7 @@ def test_parse(self):
parser = tableparser.GridTableParser()
for name, cases in totest.items():
for casenum, case in enumerate(cases):
case_input, case_table, case_expected = case
case_input, _case_table, case_expected = case
lines_input = StringList(string2lines(case_input), 'test data')
with self.subTest(id=f'totest[{name!r}][{casenum}]'):
try:
Expand Down
2 changes: 1 addition & 1 deletion test/test_statemachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def text(self, match, context, next_state):
return [match.string], next_state, ['text%s' % self.level]

def literalblock(self):
indented, indent, offset, good = self.state_machine.get_indented()
_indented, indent, _offset, _good = self.state_machine.get_indented()
if self.debug:
print('literalblock%s(%s)' % (self.level, indent), file=sys.stderr)
return ['literalblock%s(%s)' % (self.level, indent)]
Expand Down
6 changes: 4 additions & 2 deletions tools/test/test_buildhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
BUILDHTML_PATH = TOOLS_ROOT / 'buildhtml.py'


def process_and_return_filelist(options: list[str]) -> tuple[list[str], list[str]]:
def process_and_return_filelist(
options: list[str],
) -> tuple[list[str], list[str]]:
dirs = []
files = []
ret = subprocess.run(
Expand Down Expand Up @@ -80,7 +82,7 @@ def tearDown(self):

def test_1(self):
opts = ["--dry-run", str(self.root)]
dirs, files = process_and_return_filelist(opts)
_dirs, files = process_and_return_filelist(opts)
self.assertEqual(files.count("one.txt"), 4)

def test_local(self):
Expand Down

0 comments on commit 5d341f3

Please sign in to comment.