1
0
Fork 0
forked from github/pelican

Merge pull request #3318 from boxydog/more_ruff_fixes3

This commit is contained in:
Justin Mayer 2024-05-31 16:56:47 +02:00 committed by GitHub
commit 2687475fba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 56 additions and 54 deletions

View file

@ -108,15 +108,15 @@ class TestWordpressXmlImporter(TestCaseWithCLocale):
self.assertTrue(self.posts)
for (
title,
content,
fname,
date,
author,
categ,
tags,
status,
kind,
format,
_content,
_fname,
_date,
_author,
_categ,
_tags,
_status,
_kind,
_format,
) in self.posts:
self.assertTrue(title.strip())
@ -127,15 +127,15 @@ class TestWordpressXmlImporter(TestCaseWithCLocale):
pages_data = []
for (
title,
content,
_content,
fname,
date,
author,
categ,
tags,
status,
_date,
_author,
_categ,
_tags,
_status,
kind,
format,
_format,
) in self.posts:
if kind == "page":
pages_data.append((title, fname))
@ -147,7 +147,7 @@ class TestWordpressXmlImporter(TestCaseWithCLocale):
silent_f2p = mute(True)(fields2pelican)
test_post = filter(lambda p: p[0].startswith("Empty Page"), self.posts)
with temporary_folder() as temp:
fname = list(silent_f2p(test_post, "markdown", temp, dirpage=True))[0]
fname = next(iter(silent_f2p(test_post, "markdown", temp, dirpage=True)))
self.assertTrue(fname.endswith("pages%sempty.md" % os.path.sep))
def test_dircat(self):
@ -176,15 +176,15 @@ class TestWordpressXmlImporter(TestCaseWithCLocale):
pages_data = []
for (
title,
content,
_content,
fname,
date,
author,
categ,
tags,
status,
_date,
_author,
_categ,
_tags,
_status,
kind,
format,
_format,
) in self.posts:
if kind in {"page", "article"}:
pass
@ -197,15 +197,15 @@ class TestWordpressXmlImporter(TestCaseWithCLocale):
cust_data = []
for (
title,
content,
fname,
date,
author,
categ,
tags,
status,
_content,
_fname,
_date,
_author,
_categ,
_tags,
_status,
kind,
format,
_format,
) in self.custposts:
if kind in {"page", "article"}:
pass
@ -346,7 +346,7 @@ class TestWordpressXmlImporter(TestCaseWithCLocale):
silent_f2p = mute(True)(fields2pelican)
test_post = filter(lambda p: p[0].startswith("Code in List"), self.posts)
with temporary_folder() as temp:
md = [r(f) for f in silent_f2p(test_post, "markdown", temp)][0]
md = next(r(f) for f in silent_f2p(test_post, "markdown", temp))
self.assertTrue(re.search(r"\s+a = \[1, 2, 3\]", md))
self.assertTrue(re.search(r"\s+b = \[4, 5, 6\]", md))
@ -362,7 +362,7 @@ class TestWordpressXmlImporter(TestCaseWithCLocale):
silent_f2p = mute(True)(fields2pelican)
test_post = filter(lambda p: p[0].startswith("Code in List"), self.posts)
with temporary_folder() as temp:
md = [r(f) for f in silent_f2p(test_post, "markdown", temp)][0]
md = next(r(f) for f in silent_f2p(test_post, "markdown", temp))
sample_line = re.search(r"- This is a code sample", md).group(0)
code_line = re.search(r"\s+a = \[1, 2, 3\]", md).group(0)
self.assertTrue(sample_line.rindex("This") < code_line.rindex("a"))
@ -375,7 +375,7 @@ class TestWordpressXmlImporter(TestCaseWithCLocale):
silent_f2p = mute(True)(fields2pelican)
test_post = filter(lambda p: p[0].startswith("Post with raw data"), self.posts)
with temporary_folder() as temp:
md = [r(f) for f in silent_f2p(test_post, "markdown", temp)][0]
md = next(r(f) for f in silent_f2p(test_post, "markdown", temp))
escaped_quotes = re.search(r'\\[\'"“”‘’]', md)
self.assertFalse(escaped_quotes)
@ -387,7 +387,7 @@ class TestWordpressXmlImporter(TestCaseWithCLocale):
silent_f2p = mute(True)(fields2pelican)
test_post = filter(lambda p: p[0].startswith("Caption on image"), self.posts)
with temporary_folder() as temp:
md = [r(f) for f in silent_f2p(test_post, "markdown", temp)][0]
md = next(r(f) for f in silent_f2p(test_post, "markdown", temp))
caption = re.search(r"\[caption", md)
self.assertFalse(caption)

View file

@ -210,13 +210,10 @@ class TestUtils(LoggedTestCase):
)
# check with preserve case
for value, expected in samples:
self.assertEqual(
utils.slugify(
"Çığ", regex_subs=subs, preserve_case=True, use_unicode=True
),
"Çığ",
)
self.assertEqual(
utils.slugify("Çığ", regex_subs=subs, preserve_case=True, use_unicode=True),
"Çığ",
)
# check normalization
samples = (

View file

@ -1070,14 +1070,14 @@ def fields2pelican(
rc = subprocess.call(cmd, shell=True)
if rc < 0:
error = "Child was terminated by signal %d" % -rc
exit(error)
sys.exit(error)
elif rc > 0:
error = "Please, check your Pandoc installation."
exit(error)
sys.exit(error)
except OSError as e:
error = "Pandoc execution failed: %s" % e
exit(error)
sys.exit(error)
with open(out_filename, encoding="utf-8") as fs:
content = fs.read()
@ -1222,18 +1222,18 @@ def main():
"You must provide one of --blogger, --dotclear, "
"--medium, --tumblr, --wpfile or --feed options"
)
exit(error)
sys.exit(error)
if not os.path.exists(args.output):
try:
os.mkdir(args.output)
except OSError:
error = "Unable to create the output folder: " + args.output
exit(error)
sys.exit(error)
if args.wp_attach and input_type != "wordpress":
error = "You must be importing a wordpress xml to use the --wp-attach option"
exit(error)
sys.exit(error)
if input_type == "blogger":
fields = blogger2fields(args.input)

View file

@ -483,7 +483,7 @@ class _HTMLWordTruncator(HTMLParser):
def getoffset(self) -> int:
line_start = 0
lineno, line_offset = self.getpos()
for i in range(lineno - 1):
for _ in range(lineno - 1):
line_start = self.rawdata.index("\n", line_start) + 1
return line_start + line_offset

View file

@ -259,7 +259,7 @@ class Writer:
}
# generated pages, and write
for page_num in range(list(paginators.values())[0].num_pages):
for page_num in range(next(iter(paginators.values())).num_pages):
paginated_kwargs = kwargs.copy()
for key in paginators.keys():
paginator = paginators[key]

View file

@ -168,7 +168,6 @@ select = [
ignore = [
# suppression in order of # of violations in Dec 2023:
"B007", # unused-loop-control-variable
"T201", # print
"PLW2901", # redefined-loop-name
"SLF001", # private-member-access
@ -176,12 +175,18 @@ ignore = [
"PLR2004", # magic-value-comparison
"PLR0912", # too-many-branches
"PLR0913", # too-many-arguments
# RUF005: this is a different style of concatenating literals. It perhaps performs
# a bit better, but doesn't seem any more readable to me. So, ignore it.
"RUF005", # collection-literal-concatenation
# TODO: several classes have class variables. If that is correct, we should
# annotate them with ClassVar.
# See https://docs.astral.sh/ruff/rules/mutable-class-default/
"RUF012", # mutable-class-default
"PLR0915", # too-many-statements
# Note: we have a couple of "namespace packages" (i.e. missing __init__.py)
# Not sure if we should add __init__.py to them, or they really need to be
# namespace packages.
"INP001", # implicit-namespace-package
"RUF015", # unnecessary-iterable-allocation-for-first-element
"PLR1722", # sys-exit-alias
# ruff-format wants us to ignore ISC001. I don't love that, but okay.
# "warning: The following rules may cause conflicts when used with the formatter:
# `ISC001`. To avoid unexpected behavior, we recommend disabling these rules,