Skip to content

Commit

Permalink
Merge pull request #3314 from boxydog/more_ruff_fixes2
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmayer authored May 30, 2024
2 parents 880e976 + 3569ded commit 59756f8
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 86 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ db241feaa445375dc05e189e69287000ffe5fa8e
0bd02c00c078fe041b65fbf4eab13601bb42676d
# Apply more Ruff checks to code
9d30c5608a58d202b1c02d55651e6ac746bfb173
# Apply yet more Ruff checks to code
7577dd7603f7cb3a09922d1edb65b6eafb6e2ac7
6 changes: 3 additions & 3 deletions pelican/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def parse_arguments(argv=None):
"--relative-urls",
dest="relative_paths",
action="store_true",
help="Use relative urls in output, " "useful for site development",
help="Use relative urls in output, useful for site development",
)

parser.add_argument(
Expand All @@ -433,7 +433,7 @@ def parse_arguments(argv=None):
"--ignore-cache",
action="store_true",
dest="ignore_cache",
help="Ignore content cache " "from previous runs by not loading cache files.",
help="Ignore content cache from previous runs by not loading cache files.",
)

parser.add_argument(
Expand Down Expand Up @@ -488,7 +488,7 @@ def parse_arguments(argv=None):
"-b",
"--bind",
dest="bind",
help="IP to bind to when serving files via HTTP " "(default: 127.0.0.1)",
help="IP to bind to when serving files via HTTP (default: 127.0.0.1)",
)

parser.add_argument(
Expand Down
4 changes: 2 additions & 2 deletions pelican/contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(
self._context = context
self.translations = []

local_metadata = dict()
local_metadata = {}
local_metadata.update(metadata)

# set metadata as attributes
Expand Down Expand Up @@ -357,7 +357,7 @@ def _find_path(path: str) -> Optional[Content]:
origin = joiner(siteurl, Author(path, self.settings).url)
else:
logger.warning(
"Replacement Indicator '%s' not recognized, " "skipping replacement",
"Replacement Indicator '%s' not recognized, skipping replacement",
what,
)

Expand Down
6 changes: 4 additions & 2 deletions pelican/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,16 @@ def _include_path(self, path, extensions=None):

return False

def get_files(self, paths, exclude=[], extensions=None):
def get_files(self, paths, exclude=None, extensions=None):
"""Return a list of files to use, based on rules
:param paths: the list pf paths to search (relative to self.path)
:param exclude: the list of path to exclude
:param extensions: the list of allowed extensions (if False, all
extensions are allowed)
"""
if exclude is None:
exclude = []
# backward compatibility for older generators
if isinstance(paths, str):
paths = [paths]
Expand Down Expand Up @@ -1068,7 +1070,7 @@ def _link_staticfile(self, sc):
except OSError as err:
if err.errno == errno.EXDEV: # 18: Invalid cross-device link
logger.debug(
"Cross-device links not valid. " "Creating symbolic links instead."
"Cross-device links not valid. Creating symbolic links instead."
)
self.fallback_to_symlinks = True
self._link_staticfile(sc)
Expand Down
5 changes: 2 additions & 3 deletions pelican/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ def _from_settings(self, key):
if not self.has_next():
rule = p
break
else:
if p.min_page <= self.number:
rule = p
elif p.min_page <= self.number:
rule = p

if not rule:
return ""
Expand Down
4 changes: 2 additions & 2 deletions pelican/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def __init__(self, *args, **kwargs):
self._language_code = lang_code
else:
logger.warning(
"Docutils has no localization for '%s'." " Using 'en' instead.",
"Docutils has no localization for '%s'. Using 'en' instead.",
lang_code,
)
self._language_code = "en"
Expand Down Expand Up @@ -320,7 +320,7 @@ def _parse_metadata(self, meta):
elif not DUPLICATES_DEFINITIONS_ALLOWED.get(name, True):
if len(value) > 1:
logger.warning(
"Duplicate definition of `%s` " "for %s. Using first one.",
"Duplicate definition of `%s` for %s. Using first one.",
name,
self._source_path,
)
Expand Down
2 changes: 1 addition & 1 deletion pelican/rstdirectives.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class abbreviation(nodes.Inline, nodes.TextElement):
pass


def abbr_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
def abbr_role(typ, rawtext, text, lineno, inliner, options=None, content=None):
text = utils.unescape(text)
m = _abbr_re.search(text)
if m is None:
Expand Down
8 changes: 4 additions & 4 deletions pelican/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def handle_deprecated_settings(settings: Settings) -> Settings:
and not isinstance(settings[key], Path)
and "%s" in settings[key]
):
logger.warning("%%s usage in %s is deprecated, use {lang} " "instead.", key)
logger.warning("%%s usage in %s is deprecated, use {lang} instead.", key)
try:
settings[key] = _printf_s_to_format_field(settings[key], "lang")
except ValueError:
Expand All @@ -470,7 +470,7 @@ def handle_deprecated_settings(settings: Settings) -> Settings:
and not isinstance(settings[key], Path)
and "%s" in settings[key]
):
logger.warning("%%s usage in %s is deprecated, use {slug} " "instead.", key)
logger.warning("%%s usage in %s is deprecated, use {slug} instead.", key)
try:
settings[key] = _printf_s_to_format_field(settings[key], "slug")
except ValueError:
Expand Down Expand Up @@ -614,7 +614,7 @@ def configure_settings(settings: Settings) -> Settings:
if key in settings and not isinstance(settings[key], types):
value = settings.pop(key)
logger.warn(
"Detected misconfigured %s (%s), " "falling back to the default (%s)",
"Detected misconfigured %s (%s), falling back to the default (%s)",
key,
value,
DEFAULT_CONFIG[key],
Expand Down Expand Up @@ -676,7 +676,7 @@ def configure_settings(settings: Settings) -> Settings:
if any(settings.get(k) for k in feed_keys):
if not settings.get("SITEURL"):
logger.warning(
"Feeds generated without SITEURL set properly may" " not be valid"
"Feeds generated without SITEURL set properly may not be valid"
)

if "TIMEZONE" not in settings:
Expand Down
28 changes: 13 additions & 15 deletions pelican/tests/test_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def test_get_content(self):
args["settings"] = settings

# Tag
args["content"] = "A simple test, with a " '<a href="|tag|tagname">link</a>'
args["content"] = 'A simple test, with a <a href="|tag|tagname">link</a>'
page = Page(**args)
content = page.get_content("http://notmyidea.org")
self.assertEqual(
Expand All @@ -326,9 +326,7 @@ def test_get_content(self):
)

# Category
args["content"] = (
"A simple test, with a " '<a href="|category|category">link</a>'
)
args["content"] = 'A simple test, with a <a href="|category|category">link</a>'
page = Page(**args)
content = page.get_content("http://notmyidea.org")
self.assertEqual(
Expand All @@ -350,7 +348,7 @@ def test_intrasite_link(self):

# Classic intrasite link via filename
args["content"] = (
"A simple test, with a " '<a href="|filename|article.rst">link</a>'
'A simple test, with a <a href="|filename|article.rst">link</a>'
)
content = Page(**args).get_content("http://notmyidea.org")
self.assertEqual(
Expand Down Expand Up @@ -401,7 +399,7 @@ def test_intrasite_link(self):

# also test for summary in metadata
parsed = (
"A simple summary test, with a " '<a href="|filename|article.rst">link</a>'
'A simple summary test, with a <a href="|filename|article.rst">link</a>'
)
linked = (
"A simple summary test, with a "
Expand Down Expand Up @@ -594,7 +592,7 @@ def test_intrasite_link_markdown_spaces(self):

# An intrasite link via filename with %20 as a space
args["content"] = (
"A simple test, with a " '<a href="|filename|article%20spaces.rst">link</a>'
'A simple test, with a <a href="|filename|article%20spaces.rst">link</a>'
)
content = Page(**args).get_content("http://notmyidea.org")
self.assertEqual(
Expand Down Expand Up @@ -834,10 +832,10 @@ def test_attach_to_ignores_subsequent_calls(self):

otherdir_settings = self.settings.copy()
otherdir_settings.update(
dict(
PAGE_SAVE_AS=os.path.join("otherpages", "{slug}.html"),
PAGE_URL="otherpages/{slug}.html",
)
{
"PAGE_SAVE_AS": os.path.join("otherpages", "{slug}.html"),
"PAGE_URL": "otherpages/{slug}.html",
}
)
otherdir_page = Page(
content="other page",
Expand Down Expand Up @@ -892,7 +890,7 @@ def test_attach_to_does_not_override_an_override(self):
"""
customstatic = Static(
content=None,
metadata=dict(save_as="customfoo.jpg", url="customfoo.jpg"),
metadata={"save_as": "customfoo.jpg", "url": "customfoo.jpg"},
settings=self.settings,
source_path=os.path.join("dir", "foo.jpg"),
context=self.settings.copy(),
Expand Down Expand Up @@ -1066,9 +1064,9 @@ def test_not_save_as_draft(self):

static = Static(
content=None,
metadata=dict(
status="draft",
),
metadata={
"status": "draft",
},
settings=self.settings,
source_path=os.path.join("dir", "foo.jpg"),
context=self.settings.copy(),
Expand Down
12 changes: 5 additions & 7 deletions pelican/tests/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_recognise_kind_and_title(self):
)
comment_titles = {x[0] for x in test_posts if x[8] == "comment"}
self.assertEqual(
{"Mishka, always a pleasure to read your " "adventures!..."}, comment_titles
{"Mishka, always a pleasure to read your adventures!..."}, comment_titles
)

def test_recognise_status_with_correct_filename(self):
Expand Down Expand Up @@ -478,7 +478,7 @@ def test_galleries_added_to_header(self):
attachments=["output/test1", "output/test2"],
)
self.assertEqual(
header, ("test\n####\n" ":attachments: output/test1, " "output/test2\n\n")
header, ("test\n####\n:attachments: output/test1, output/test2\n\n")
)

def test_galleries_added_to_markdown_header(self):
Expand Down Expand Up @@ -521,10 +521,10 @@ def test_attachments_associated_with_correct_post(self):
self.assertEqual(self.attachments[post], expected)
elif post == "with-excerpt":
expected_invalid = (
"http://thisurlisinvalid.notarealdomain/" "not_an_image.jpg"
"http://thisurlisinvalid.notarealdomain/not_an_image.jpg"
)
expected_pelikan = (
"http://en.wikipedia.org/wiki/" "File:Pelikan_Walvis_Bay.jpg"
"http://en.wikipedia.org/wiki/File:Pelikan_Walvis_Bay.jpg"
)
self.assertEqual(
self.attachments[post], {expected_invalid, expected_pelikan}
Expand All @@ -533,9 +533,7 @@ def test_attachments_associated_with_correct_post(self):
expected_invalid = "http://thisurlisinvalid.notarealdomain"
self.assertEqual(self.attachments[post], {expected_invalid})
else:
self.fail(
"all attachments should match to a " f"filename or None, {post}"
)
self.fail(f"all attachments should match to a filename or None, {post}")

def test_download_attachments(self):
real_file = os.path.join(CUR_DIR, "content/article.rst")
Expand Down
2 changes: 1 addition & 1 deletion pelican/tests/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ def test_article_with_footnote(self):
"modified": SafeDatetime(2012, 11, 1),
"multiline": [
"Line Metadata should be handle properly.",
"See syntax of Meta-Data extension of " "Python Markdown package:",
"See syntax of Meta-Data extension of Python Markdown package:",
"If a line is indented by 4 or more spaces,",
"that line is assumed to be an additional line of the value",
"for the previous keyword.",
Expand Down
4 changes: 2 additions & 2 deletions pelican/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,14 +922,14 @@ class TestSanitisedJoin(unittest.TestCase):
def test_detect_parent_breakout(self):
with self.assertRaisesRegex(
RuntimeError,
"Attempted to break out of output directory to " "(.*?:)?/foo/test",
"Attempted to break out of output directory to (.*?:)?/foo/test",
): # (.*?:)? accounts for Windows root
utils.sanitised_join("/foo/bar", "../test")

def test_detect_root_breakout(self):
with self.assertRaisesRegex(
RuntimeError,
"Attempted to break out of output directory to " "(.*?:)?/test",
"Attempted to break out of output directory to (.*?:)?/test",
): # (.*?:)? accounts for Windows root
utils.sanitised_join("/foo/bar", "/test")

Expand Down
4 changes: 2 additions & 2 deletions pelican/tools/pelican_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ def fields2pelican(

if posts_require_pandoc:
logger.error(
"Pandoc must be installed to import the following posts:" "\n {}".format(
"Pandoc must be installed to import the following posts:\n {}".format(
"\n ".join(posts_require_pandoc)
)
)
Expand Down Expand Up @@ -1232,7 +1232,7 @@ def main():
exit(error)

if args.wp_attach and input_type != "wordpress":
error = "You must be importing a wordpress xml " "to use the --wp-attach option"
error = "You must be importing a wordpress xml to use the --wp-attach option"
exit(error)

if input_type == "blogger":
Expand Down
Loading

0 comments on commit 59756f8

Please sign in to comment.