From b6d3b6589935f8e2ea6d01e2ff6f8ee3a308af8c Mon Sep 17 00:00:00 2001 From: boxydog Date: Thu, 30 May 2024 10:33:40 -0500 Subject: [PATCH 1/3] More ruff checks --- pyproject.toml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c84c35b0b..5546d1cf0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -190,19 +190,10 @@ ignore = [ "PLR5501", # collapsible-else-if "PERF203", # try-except-in-loop "B006", # mutable-argument-default - "PLR1714", # repeated-equality-comparison - "PERF401", # manual-list-comprehension # TODO: these only have one violation each in Dec 2023: "SLOT000", # no-slots-in-str-subclass "PYI024", # collections-named-tuple - "PLW0603", # global-statement "PIE800", # unnecessary-spread - "ISC003", # explicit-string-concatenation - "EXE002", # shebang-missing-executable-file - "C401", # unnecessary-generator-set - "C416", # unnecessary `list` comprehension - "B028", # no-explicit-stacklevel - "B008", # function-call-in-default-argument ] [tool.ruff.lint.extend-per-file-ignores] From 9d30c5608a58d202b1c02d55651e6ac746bfb173 Mon Sep 17 00:00:00 2001 From: boxydog Date: Thu, 30 May 2024 10:33:50 -0500 Subject: [PATCH 2/3] Code changes for more ruff checks --- pelican/server.py | 7 +++---- pelican/settings.py | 2 +- pelican/tests/test_importer.py | 29 ++++++++++++++--------------- pelican/tests/test_testsuite.py | 2 +- samples/pelican.conf.py | 0 5 files changed, 19 insertions(+), 21 deletions(-) mode change 100755 => 100644 samples/pelican.conf.py diff --git a/pelican/server.py b/pelican/server.py index 61729bf12..71cd2d810 100644 --- a/pelican/server.py +++ b/pelican/server.py @@ -32,19 +32,18 @@ def parse_arguments(): "--cert", default="./cert.pem", nargs="?", - help="Path to certificate file. " + "Relative to current directory", + help="Path to certificate file. Relative to current directory", ) parser.add_argument( "--key", default="./key.pem", nargs="?", - help="Path to certificate key file. " + "Relative to current directory", + help="Path to certificate key file. Relative to current directory", ) parser.add_argument( "--path", default=".", - help="Path to pelican source directory to serve. " - + "Relative to current directory", + help="Path to pelican source directory to serve. Relative to current directory", ) return parser.parse_args() diff --git a/pelican/settings.py b/pelican/settings.py index 0585b3bec..ea6fae774 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -223,7 +223,7 @@ def getabs(maybe_relative, base_path=path): # parameters to docutils directive handlers, so we have to have a # variable here that we'll import from within Pygments.run (see # rstdirectives.py) to see what the user defaults were. - global PYGMENTS_RST_OPTIONS + global PYGMENTS_RST_OPTIONS # noqa: PLW0603 PYGMENTS_RST_OPTIONS = settings.get("PYGMENTS_RST_OPTIONS", None) return settings diff --git a/pelican/tests/test_importer.py b/pelican/tests/test_importer.py index 469184cd5..e69e321fb 100644 --- a/pelican/tests/test_importer.py +++ b/pelican/tests/test_importer.py @@ -152,11 +152,12 @@ def test_dirpage_directive_for_page_kind(self): def test_dircat(self): silent_f2p = mute(True)(fields2pelican) - test_posts = [] - for post in self.posts: - # check post kind - if len(post[5]) > 0: # Has a category - test_posts.append(post) + test_posts = [ + post + for post in self.posts + # check post has a category + if len(post[5]) > 0 + ] with temporary_folder() as temp: fnames = list(silent_f2p(test_posts, "markdown", temp, dircat=True)) subs = DEFAULT_CONFIG["SLUG_REGEX_SUBSTITUTIONS"] @@ -185,7 +186,7 @@ def test_unless_custom_post_all_items_should_be_pages_or_posts(self): kind, format, ) in self.posts: - if kind == "page" or kind == "article": + if kind in {"page", "article"}: pass else: pages_data.append((title, fname)) @@ -206,7 +207,7 @@ def test_recognise_custom_post_type(self): kind, format, ) in self.custposts: - if kind == "article" or kind == "page": + if kind in {"page", "article"}: pass else: cust_data.append((title, kind)) @@ -266,11 +267,12 @@ def test_custom_posts_put_in_own_dir_and_catagory_sub_dir(self): def test_wp_custpost_true_dirpage_false(self): # pages should only be put in their own directory when dirpage = True silent_f2p = mute(True)(fields2pelican) - test_posts = [] - for post in self.custposts: + test_posts = [ + post + for post in self.custposts # check post kind - if post[8] == "page": - test_posts.append(post) + if post[8] == "page" + ] with temporary_folder() as temp: fnames = list( silent_f2p( @@ -748,10 +750,7 @@ def test_mediumpost2field(self): def test_mediumposts2field(self): """Parse all posts in an export directory""" - posts = [ - fields - for fields in mediumposts2fields(f"{self.test_content_root}/medium_posts") - ] + posts = list(mediumposts2fields(f"{self.test_content_root}/medium_posts")) self.assertEqual(1, len(posts)) self.assertEqual(self.post_tuple, posts[0]) diff --git a/pelican/tests/test_testsuite.py b/pelican/tests/test_testsuite.py index a9a0c2003..938d2bdf4 100644 --- a/pelican/tests/test_testsuite.py +++ b/pelican/tests/test_testsuite.py @@ -6,4 +6,4 @@ class TestSuiteTest(unittest.TestCase): def test_error_on_warning(self): with self.assertRaises(UserWarning): - warnings.warn("test warning") + warnings.warn("test warning") # noqa: B028 diff --git a/samples/pelican.conf.py b/samples/pelican.conf.py old mode 100755 new mode 100644 From 144b2edf88026a764b1978f4cb0f27e150d1334e Mon Sep 17 00:00:00 2001 From: Justin Mayer Date: Thu, 30 May 2024 19:40:45 +0200 Subject: [PATCH 3/3] Ignore more Ruff fixes in `git blame` --- .git-blame-ignore-revs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 2809b6586..fddd0764d 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -9,3 +9,5 @@ db241feaa445375dc05e189e69287000ffe5fa8e 6d8597addb17d5fa3027ead91427939e8e4e89ec # Upgrade Ruff from 0.1.x to 0.4.x 0bd02c00c078fe041b65fbf4eab13601bb42676d +# Apply more Ruff checks to code +9d30c5608a58d202b1c02d55651e6ac746bfb173