|
From: <aa-...@us...> - 2024-08-01 22:27:22
|
Revision: 9841
http://sourceforge.net/p/docutils/code/9841
Author: aa-turner
Date: 2024-08-01 22:27:19 +0000 (Thu, 01 Aug 2024)
Log Message:
-----------
Enable the refurb linter in Ruff
Modified Paths:
--------------
trunk/docutils/.ruff.toml
trunk/docutils/docutils/transforms/peps.py
trunk/docutils/docutils/utils/__init__.py
trunk/docutils/docutils/utils/math/math2html.py
trunk/docutils/docutils/utils/math/tex2mathml_extern.py
trunk/docutils/docutils/writers/_html_base.py
trunk/docutils/docutils/writers/manpage.py
trunk/docutils/docutils/writers/odf_odt/__init__.py
trunk/docutils/docutils/writers/s5_html/__init__.py
trunk/docutils/test/test_CLI.py
trunk/docutils/test/test_dependencies.py
trunk/docutils/test/test_parsers/test_rst/test_TableParser.py
trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py
trunk/docutils/test/test_utils/test_math/test_tex2mathml_extern.py
trunk/docutils/tools/buildhtml.py
trunk/docutils/tools/dev/create_unimap.py
Modified: trunk/docutils/.ruff.toml
===================================================================
--- trunk/docutils/.ruff.toml 2024-08-01 21:56:03 UTC (rev 9840)
+++ trunk/docutils/.ruff.toml 2024-08-01 22:27:19 UTC (rev 9841)
@@ -12,6 +12,7 @@
"DTZ", # flake8-datetimez
"F", # pyflakes
"FA", # flake8-future-annotations
+ "FURB", # refurb
"G", # flake8-logging-format
"ICN", # flake8-import-conventions
"INP", # flake8-no-pep420
Modified: trunk/docutils/docutils/transforms/peps.py
===================================================================
--- trunk/docutils/docutils/transforms/peps.py 2024-08-01 21:56:03 UTC (rev 9840)
+++ trunk/docutils/docutils/transforms/peps.py 2024-08-01 22:27:19 UTC (rev 9841)
@@ -117,11 +117,14 @@
space = nodes.Text(' ')
for refpep in re.split(r',?\s+', body.astext()):
pepno = int(refpep)
- newbody.append(nodes.reference(
- refpep, refpep,
- refuri=(self.document.settings.pep_base_url
- + self.pep_url % pepno)))
- newbody.append(space)
+ newbody.extend((
+ nodes.reference(
+ refpep, refpep,
+ refuri=(self.document.settings.pep_base_url
+ + self.pep_url % pepno)
+ ),
+ space,
+ ))
para[:] = newbody[:-1] # drop trailing space
elif name == 'last-modified':
utils.clean_rcs_keywords(para, self.rcs_keyword_substitutions)
Modified: trunk/docutils/docutils/utils/__init__.py
===================================================================
--- trunk/docutils/docutils/utils/__init__.py 2024-08-01 21:56:03 UTC (rev 9840)
+++ trunk/docutils/docutils/utils/__init__.py 2024-08-01 22:27:19 UTC (rev 9841)
@@ -626,8 +626,10 @@
if found == -1:
parts.append(text[start:])
return ''.join(parts)
- parts.append(text[start:found])
- parts.append('\x00' + text[found+1:found+2])
+ parts.extend((
+ text[start:found],
+ '\x00' + text[found + 1:found + 2],
+ ))
start = found + 2 # skip character after escape
Modified: trunk/docutils/docutils/utils/math/math2html.py
===================================================================
--- trunk/docutils/docutils/utils/math/math2html.py 2024-08-01 21:56:03 UTC (rev 9840)
+++ trunk/docutils/docutils/utils/math/math2html.py 2024-08-01 22:27:19 UTC (rev 9841)
@@ -1848,10 +1848,11 @@
def innertext(self, pos) -> None:
"Parse some text inside the bracket, following textual rules."
- specialchars = list(FormulaConfig.symbolfunctions.keys())
- specialchars.append(FormulaConfig.starts['command'])
- specialchars.append(FormulaConfig.starts['bracket'])
- specialchars.append(Comment.start)
+ specialchars = list(FormulaConfig.symbolfunctions.keys()) + [
+ FormulaConfig.starts['command'],
+ FormulaConfig.starts['bracket'],
+ Comment.start,
+ ]
while not pos.finished():
if pos.current() in specialchars:
self.add(self.factory.parseany(pos))
Modified: trunk/docutils/docutils/utils/math/tex2mathml_extern.py
===================================================================
--- trunk/docutils/docutils/utils/math/tex2mathml_extern.py 2024-08-01 21:56:03 UTC (rev 9840)
+++ trunk/docutils/docutils/utils/math/tex2mathml_extern.py 2024-08-01 22:27:19 UTC (rev 9841)
@@ -174,10 +174,12 @@
details = []
if result.stderr:
lines = result.stderr.splitlines()
- details.append(nodes.paragraph('', lines[0]))
- details.append(nodes.literal_block('', '\n'.join(lines[1:3])))
- details.append(nodes.paragraph('', '\n'.join(lines[3:]),
- classes=['pre-wrap']))
+ details.extend((
+ nodes.paragraph('', lines[0]),
+ nodes.literal_block('', '\n'.join(lines[1:3])),
+ nodes.paragraph('', '\n'.join(lines[3:]),
+ classes=['pre-wrap']),
+ ))
_check_result(result, details=details)
return result.stdout
Modified: trunk/docutils/docutils/writers/_html_base.py
===================================================================
--- trunk/docutils/docutils/writers/_html_base.py 2024-08-01 21:56:03 UTC (rev 9840)
+++ trunk/docutils/docutils/writers/_html_base.py 2024-08-01 22:27:19 UTC (rev 9841)
@@ -159,8 +159,8 @@
self.output = self.apply_template()
def apply_template(self):
- with open(self.document.settings.template, encoding='utf-8') as fp:
- template = fp.read()
+ template_path = Path(self.document.settings.template)
+ template = template_path.read_text(encoding='utf-8')
subs = self.interpolation_dict()
return template % subs
@@ -506,8 +506,7 @@
adjust_path = bool(self.settings.stylesheet_path)
if self.settings.embed_stylesheet:
try:
- with open(path, encoding='utf-8') as f:
- content = f.read()
+ content = Path(path).read_text(encoding='utf-8')
except OSError as err:
msg = f'Cannot embed stylesheet: {err}'
self.document.reporter.error(msg)
@@ -1170,8 +1169,7 @@
elif loading == 'embed':
try:
imagepath = self.uri2imagepath(uri)
- with open(imagepath, 'rb') as imagefile:
- imagedata = imagefile.read()
+ imagedata = Path(imagepath).read_bytes()
except (ValueError, OSError) as err:
self.messages.append(self.document.reporter.error(
f'Cannot embed image "{uri}":\n {err}', base_node=node))
Modified: trunk/docutils/docutils/writers/manpage.py
===================================================================
--- trunk/docutils/docutils/writers/manpage.py 2024-08-01 21:56:03 UTC (rev 9840)
+++ trunk/docutils/docutils/writers/manpage.py 2024-08-01 22:27:19 UTC (rev 9841)
@@ -174,9 +174,11 @@
del cell_lines[-1]
def as_list(self):
- text = ['.TS\n']
- text.append(' '.join(self._options) + ';\n')
- text.append('%s.\n' % ('|'.join(self._coldefs)))
+ text = [
+ '.TS\n',
+ ' '.join(self._options) + ';\n',
+ '%s.\n' % '|'.join(self._coldefs),
+ ]
for row in self._rows:
# row = array of cells. cell = array of lines.
text.append('T{\n')
Modified: trunk/docutils/docutils/writers/odf_odt/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/odf_odt/__init__.py 2024-08-01 21:56:03 UTC (rev 9840)
+++ trunk/docutils/docutils/writers/odf_odt/__init__.py 2024-08-01 22:27:19 UTC (rev 9841)
@@ -930,8 +930,7 @@
stylespath = self.settings.stylesheet
ext = os.path.splitext(stylespath)[1]
if ext == '.xml':
- with open(stylespath, 'r', encoding='utf-8') as stylesfile:
- s1 = stylesfile.read()
+ s1 = Path(stylespath).read_text(encoding='utf-8')
elif ext == extension:
zfile = zipfile.ZipFile(stylespath, 'r')
s1 = zfile.read('styles.xml')
@@ -2629,8 +2628,7 @@
my_lines.append(my_line)
my_lines_str = '<text:line-break/>'.join(my_lines)
my_lines_str2 = wrapper1 % (my_lines_str, )
- lines1.append(my_lines_str2)
- lines1.append('</wrappertag1>')
+ lines1.extend((my_lines_str2, '</wrappertag1>'))
s1 = ''.join(lines1)
s1 = s1.encode("utf-8")
el1 = etree.fromstring(s1)
Modified: trunk/docutils/docutils/writers/s5_html/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/s5_html/__init__.py 2024-08-01 21:56:03 UTC (rev 9840)
+++ trunk/docutils/docutils/writers/s5_html/__init__.py 2024-08-01 22:27:19 UTC (rev 9841)
@@ -9,9 +9,11 @@
__docformat__ = 'reStructuredText'
-import sys
import os
import re
+import sys
+from pathlib import Path
+
import docutils
from docutils import frontend, nodes, utils
from docutils.writers import html4css1
@@ -266,14 +268,12 @@
if os.path.exists(dest) and not settings.overwrite_theme_files:
settings.record_dependencies.add(dest)
else:
- with open(source, 'rb') as src_file:
- src_data = src_file.read()
- with open(dest, 'wb') as dest_file:
- dest_dir = dest_dir.replace(os.sep, '/')
- dest_file.write(src_data.replace(
- b'ui/default',
- dest_dir[dest_dir.rfind('ui/'):].encode(
- sys.getfilesystemencoding())))
+ src_data = Path(source).read_bytes()
+ dest_dir = dest_dir.replace(os.sep, '/')
+ Path(dest).write_bytes(src_data.replace(
+ b'ui/default',
+ dest_dir[dest_dir.rfind('ui/'):].encode(
+ sys.getfilesystemencoding())))
settings.record_dependencies.add(source)
return True
if os.path.isfile(dest):
Modified: trunk/docutils/test/test_CLI.py
===================================================================
--- trunk/docutils/test/test_CLI.py 2024-08-01 21:56:03 UTC (rev 9840)
+++ trunk/docutils/test/test_CLI.py 2024-08-01 22:27:19 UTC (rev 9841)
@@ -85,8 +85,7 @@
# compare to stored version
docutils_txt = os.path.join(DATA_ROOT, 'help/docutils.txt')
- with open(docutils_txt, encoding='utf-8') as samplefile:
- expected = samplefile.read()
+ expected = Path(docutils_txt).read_text(encoding='utf-8')
if expected != output:
print_mismatch(expected, output)
@@ -95,8 +94,7 @@
output = self.get_help_text('rst2html', core.rst2html)
# compare to stored version
rst2html_txt = os.path.join(DATA_ROOT, 'help/rst2html.txt')
- with open(rst2html_txt, encoding='utf-8') as samplefile:
- expected = samplefile.read()
+ expected = Path(rst2html_txt).read_text(encoding='utf-8')
if expected != output:
print_mismatch(expected, output)
@@ -105,8 +103,7 @@
output = self.get_help_text('rst2latex', core.rst2latex)
# compare to stored version
rst2latex_txt = os.path.join(DATA_ROOT, 'help/rst2latex.txt')
- with open(rst2latex_txt, encoding='utf-8') as samplefile:
- expected = samplefile.read()
+ expected = Path(rst2latex_txt).read_text(encoding='utf-8')
if expected != output:
print_mismatch(expected, output)
Modified: trunk/docutils/test/test_dependencies.py
===================================================================
--- trunk/docutils/test/test_dependencies.py 2024-08-01 21:56:03 UTC (rev 9840)
+++ trunk/docutils/test/test_dependencies.py 2024-08-01 22:27:19 UTC (rev 9841)
@@ -65,8 +65,8 @@
**kwargs)
recorder.close()
# Read the record file:
- with open(recordfile, encoding='utf-8') as record:
- return record.read().splitlines(), output
+ records = Path(recordfile).read_text(encoding='utf-8').splitlines()
+ return records, output
def test_dependencies_xml(self):
# Note: currently, raw input files are read (and hence recorded) while
Modified: trunk/docutils/test/test_parsers/test_rst/test_TableParser.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_TableParser.py 2024-08-01 21:56:03 UTC (rev 9840)
+++ trunk/docutils/test/test_parsers/test_rst/test_TableParser.py 2024-08-01 22:27:19 UTC (rev 9841)
@@ -24,7 +24,7 @@
def test_parse_table(self):
parser = tableparser.GridTableParser()
for name, cases in totest.items():
- for casenum, case in enumerate(cases):
+ for case in cases:
case_input, case_table, _case_expected = case
lines_input = StringList(string2lines(case_input), 'test data')
parser.setup(lines_input)
Modified: trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py 2024-08-01 21:56:03 UTC (rev 9840)
+++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_tables.py 2024-08-01 22:27:19 UTC (rev 9841)
@@ -67,8 +67,7 @@
try:
- with open(utf_16_csv, 'rb') as f:
- csv_data = f.read()
+ csv_data = Path(utf_16_csv).read_bytes()
csv_data = str(csv_data, 'latin1').splitlines()
reader = csv.reader([line + '\n' for line in csv_data])
next(reader)
Modified: trunk/docutils/test/test_utils/test_math/test_tex2mathml_extern.py
===================================================================
--- trunk/docutils/test/test_utils/test_math/test_tex2mathml_extern.py 2024-08-01 21:56:03 UTC (rev 9840)
+++ trunk/docutils/test/test_utils/test_math/test_tex2mathml_extern.py 2024-08-01 22:27:19 UTC (rev 9841)
@@ -146,8 +146,7 @@
'buggy-maths',
writer='html5',
settings_overrides=settings)
- with open(out_path, "w") as fd:
- fd.write(parts['whole'])
+ Path(out_path).write_text(parts['whole'])
with self.subTest(converter=math_output[1] or 'latex2mathml()'):
compare_output(parts['whole'], out_path, expected_path)
Modified: trunk/docutils/tools/buildhtml.py
===================================================================
--- trunk/docutils/tools/buildhtml.py 2024-08-01 21:56:03 UTC (rev 9840)
+++ trunk/docutils/tools/buildhtml.py 2024-08-01 22:27:19 UTC (rev 9841)
@@ -295,7 +295,7 @@
errout.write('/// ...Skipping directory (pruned): %s\n'
% relative_path(None, dirpath))
sys.stderr.flush()
- del dirnames[:] # modify in-place to control `os.walk()` run
+ dirnames.clear() # modify in-place to control `os.walk()` run
return
if not self.initial_settings.silent:
errout.write('/// Processing directory: %s\n'
Modified: trunk/docutils/tools/dev/create_unimap.py
===================================================================
--- trunk/docutils/tools/dev/create_unimap.py 2024-08-01 21:56:03 UTC (rev 9840)
+++ trunk/docutils/tools/dev/create_unimap.py 2024-08-01 22:27:19 UTC (rev 9841)
@@ -68,7 +68,7 @@
print('# $%s$' % 'Id')
print('# Author: Lea Wiemann <LeW...@gm...>')
print('# Copyright: This file has been placed in the public domain.')
-print('')
+print()
print('# This is a mapping of Unicode characters to LaTeX equivalents.')
print('# The information has been extracted from')
print('# <https://www.w3.org/2003/entities/xml/unicode.xml>, written by')
@@ -76,5 +76,5 @@
print('#')
print('# The extraction has been done by the "create_unimap.py" script')
print('# located at <https://docutils.sourceforge.io/tools/dev/create_unimap.py>.') # noqa:501
-print('')
+print()
print('unicode_map = %s' % pprint.pformat(unicode_map, indent=0))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|