diff --git a/docs/conf.py b/docs/conf.py index 8d8078a27..8f14a0187 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -29,7 +29,7 @@ master_doc = "index" project = project_data.get("name").upper() year = datetime.datetime.now().date().year -copyright = f"2010–{year}" +copyright = f"2010–{year}" # noqa: RUF001 exclude_patterns = ["_build"] release = project_data.get("version") version = ".".join(release.split(".")[:1]) diff --git a/pelican/__init__.py b/pelican/__init__.py index ab6b0225f..20d177063 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -294,7 +294,7 @@ def __call__(self, parser, namespace, values, option_string=None): raise ValueError( "Extra settings must be specified as KEY=VALUE pairs " f"but you specified {item}" - ) + ) from None try: overrides[k] = json.loads(v) except json.decoder.JSONDecodeError: @@ -305,7 +305,7 @@ def __call__(self, parser, namespace, values, option_string=None): "Use -e KEY='\"string\"' to specify a string value; " "-e KEY=null to specify None; " "-e KEY=false (or true) to specify False (or True)." - ) + ) from None setattr(namespace, self.dest, overrides) diff --git a/pelican/generators.py b/pelican/generators.py index fdcc62ce4..a2bf2f448 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -1040,7 +1040,7 @@ def _source_is_newer(self, staticfile): save_as = os.path.join(self.output_path, staticfile.save_as) s_mtime = os.path.getmtime(source_path) d_mtime = os.path.getmtime(save_as) - return s_mtime - d_mtime > 0.000001 + return s_mtime - d_mtime > 0.000001 # noqa: PLR2004 def _link_or_copy_staticfile(self, sc): if self.settings["STATIC_CREATE_LINKS"]: diff --git a/pelican/paginator.py b/pelican/paginator.py index 92cb26b17..4a7c1aa2f 100644 --- a/pelican/paginator.py +++ b/pelican/paginator.py @@ -5,7 +5,7 @@ from math import ceil logger = logging.getLogger(__name__) -PaginationRule = namedtuple( +PaginationRule = namedtuple( # noqa: PYI024 "PaginationRule", "min_page URL SAVE_AS", ) diff --git a/pelican/server.py b/pelican/server.py index 71cd2d810..ebf13677e 100644 --- a/pelican/server.py +++ b/pelican/server.py @@ -53,14 +53,12 @@ class ComplexHTTPRequestHandler(server.SimpleHTTPRequestHandler): extensions_map = { **server.SimpleHTTPRequestHandler.extensions_map, - **{ - # web fonts - ".oft": "font/oft", - ".sfnt": "font/sfnt", - ".ttf": "font/ttf", - ".woff": "font/woff", - ".woff2": "font/woff2", - }, + # web fonts + ".oft": "font/oft", + ".sfnt": "font/sfnt", + ".ttf": "font/ttf", + ".woff": "font/woff", + ".woff2": "font/woff2", } def translate_path(self, path): diff --git a/pelican/tests/test_importer.py b/pelican/tests/test_importer.py index b00970f4a..0349a175e 100644 --- a/pelican/tests/test_importer.py +++ b/pelican/tests/test_importer.py @@ -376,7 +376,7 @@ def r(f): test_post = filter(lambda p: p[0].startswith("Post with raw data"), self.posts) with temporary_folder() as temp: md = next(r(f) for f in silent_f2p(test_post, "markdown", temp)) - escaped_quotes = re.search(r'\\[\'"“”‘’]', md) + escaped_quotes = re.search(r'\\[\'"“”‘’]', md) # noqa: RUF001 self.assertFalse(escaped_quotes) def test_convert_caption_to_figure(self): @@ -505,7 +505,7 @@ def setUp(self): def test_recognise_attachments(self): self.assertTrue(self.attachments) - self.assertTrue(len(self.attachments.keys()) == 3) + self.assertEqual(3, len(self.attachments.keys())) def test_attachments_associated_with_correct_post(self): self.assertTrue(self.attachments) diff --git a/pelican/tools/pelican_quickstart.py b/pelican/tools/pelican_quickstart.py index 2f62e4bc9..9be107d08 100755 --- a/pelican/tools/pelican_quickstart.py +++ b/pelican/tools/pelican_quickstart.py @@ -79,7 +79,7 @@ # Create a 'marked' default path, to determine if someone has supplied # a path on the command-line. -class _DEFAULT_PATH_TYPE(str): +class _DEFAULT_PATH_TYPE(str): # noqa: SLOT000 is_default_path = True diff --git a/pelican/utils.py b/pelican/utils.py index 43acdd7fb..6dc4825e0 100644 --- a/pelican/utils.py +++ b/pelican/utils.py @@ -81,7 +81,7 @@ def strip_zeros(x): # test for valid C89 directives only if candidate[-1] in c89_directives: # check for '-' prefix - if len(candidate) == 3: + if len(candidate) == 3: # noqa: PLR2004 # '-' prefix candidate = f"%{candidate[-1]}" conversion = strip_zeros @@ -232,7 +232,7 @@ def get_date(string: str) -> datetime.datetime: try: return dateutil.parser.parse(string, default=default) except (TypeError, ValueError): - raise ValueError(f"{string!r} is not a valid date") + raise ValueError(f"{string!r} is not a valid date") from None @contextmanager @@ -666,13 +666,13 @@ def process_translations( raise TypeError( f"Cannot unpack {translation_id}, 'translation_id' must be falsy, a" " string or a collection of strings" - ) + ) from None except AttributeError: raise AttributeError( f"Cannot use {translation_id} as 'translation_id', there " "appear to be items without these metadata " "attributes" - ) + ) from None for id_vals, items in groupby(content_list, attrgetter(*translation_id)): # prepare warning string diff --git a/pyproject.toml b/pyproject.toml index 606a05bac..ccd75f9f2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -168,11 +168,8 @@ select = [ ignore = [ # suppression in order of # of violations in Dec 2023: - "T201", # print "PLW2901", # redefined-loop-name "SLF001", # private-member-access - "RUF001", # ambiguous-unicode-character-string - "PLR2004", # magic-value-comparison "PLR0912", # too-many-branches "PLR0913", # too-many-arguments # RUF005: this is a different style of concatenating literals. It perhaps performs @@ -193,15 +190,10 @@ ignore = [ # either by removing them from the `select` or `extend-select` configuration, # or adding them to the `ignore` configuration." "ISC001", # single-line-implicit-string-concatenation - "B904", # raise-without-from-inside-except "UP031", # printf-string-formatting # PERF203 has minimal performance impact, and you have to catch the exception # inside the loop if you want to ignore it, so let's ignore PERF203. "PERF203", # try-except-in-loop - # TODO: these only have one violation each in Dec 2023: - "SLOT000", # no-slots-in-str-subclass - "PYI024", # collections-named-tuple - "PIE800", # unnecessary-spread ] [tool.ruff.lint.extend-per-file-ignores] @@ -210,3 +202,16 @@ ignore = [ # allow imports after a call to a function, see the file "E402" ] +"pelican/tests/test_utils.py" = [ + # the tests have a bunch of unicode characters + "RUF001" +] +"pelican/tests/test_generators.py" = [ + # the tests have a bunch of constants, why not + "PLR2004" +] + +"pelican/tools/*.py}" = [ + # this is a command-line utility, prints are fine + "T201" +]