Skip to content

Commit

Permalink
Merge pull request getpelican#3320 from boxydog/d_more_ruff4
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmayer authored May 31, 2024
2 parents 2687475 + 82b48fc commit 8fd94ea
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 28 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions pelican/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion pelican/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down
2 changes: 1 addition & 1 deletion pelican/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from math import ceil

logger = logging.getLogger(__name__)
PaginationRule = namedtuple(
PaginationRule = namedtuple( # noqa: PYI024
"PaginationRule",
"min_page URL SAVE_AS",
)
Expand Down
14 changes: 6 additions & 8 deletions pelican/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions pelican/tests/test_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pelican/tools/pelican_quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 4 additions & 4 deletions pelican/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
21 changes: 13 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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"
]

0 comments on commit 8fd94ea

Please sign in to comment.