Enable various ruff rules
This commit enables a bunch of unrelated ruff rules, which only require minimal changes to the code base to enable them. The rules enabled by this commit are: - check the use of datetime objects without timezone (DTZ005) - check the performance of try-except in loops (PERF203) - check the number of function arguments (PLR0913) - check for mutable class defaults (RUF012) - check for the use of secure hashing algorithms (S324) - check for raising base exceptions (TRY002) - check for raising other exceptions where TypeErrors should be raised (TRY004)
This commit is contained in:
parent
e56ebb3f46
commit
9a5bba49cc
@ -3,6 +3,7 @@
|
||||
\\.gitea/.* @Stan @Itms
|
||||
## Linting
|
||||
\\.pre-commit-config\\.yaml @Dunedan
|
||||
ruff\\.toml @Dunedan
|
||||
|
||||
## == Build & Libraries
|
||||
(build|libraries)/.* @Itms @Stan
|
||||
|
10
ruff.toml
10
ruff.toml
@ -10,36 +10,29 @@ ignore = [
|
||||
"C90",
|
||||
"COM812",
|
||||
"D10",
|
||||
"DTZ005",
|
||||
"EM",
|
||||
"FA",
|
||||
"FIX",
|
||||
"FBT",
|
||||
"ISC001",
|
||||
"N817",
|
||||
"PERF203",
|
||||
"PERF401",
|
||||
"PLR0912",
|
||||
"PLR0913",
|
||||
"PLR0915",
|
||||
"PLR2004",
|
||||
"PLW2901",
|
||||
"PT",
|
||||
"PTH",
|
||||
"RUF012",
|
||||
"S101",
|
||||
"S310",
|
||||
"S314",
|
||||
"S324",
|
||||
"S320",
|
||||
"S603",
|
||||
"S607",
|
||||
"T20",
|
||||
"TD002",
|
||||
"TD003",
|
||||
"TRY002",
|
||||
"TRY003",
|
||||
"TRY004",
|
||||
"UP038",
|
||||
"W505"
|
||||
]
|
||||
@ -52,3 +45,6 @@ max-doc-length = 72
|
||||
|
||||
[lint.pydocstyle]
|
||||
convention = "pep257"
|
||||
|
||||
[lint.pylint]
|
||||
max-args = 8
|
||||
|
@ -1,7 +1,10 @@
|
||||
# Adapted from http://cairographics.org/freetypepython/
|
||||
|
||||
# ruff: noqa: TRY002
|
||||
|
||||
import ctypes
|
||||
import sys
|
||||
from typing import ClassVar
|
||||
|
||||
import cairo
|
||||
|
||||
@ -40,7 +43,7 @@ _surface = cairo.ImageSurface(cairo.FORMAT_A8, 0, 0)
|
||||
|
||||
|
||||
class PycairoContext(ctypes.Structure):
|
||||
_fields_ = [
|
||||
_fields_: ClassVar = [
|
||||
("PyObject_HEAD", ctypes.c_byte * object.__basicsize__),
|
||||
("ctx", ctypes.c_void_p),
|
||||
("base", ctypes.c_void_p),
|
||||
|
@ -1,6 +1,6 @@
|
||||
"""Wrapper around babel Catalog / .po handling."""
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from babel.messages.catalog import Catalog as BabelCatalog
|
||||
from babel.messages.pofile import read_po, write_po
|
||||
@ -10,7 +10,7 @@ class Catalog(BabelCatalog):
|
||||
"""Wraps a BabelCatalog for convenience."""
|
||||
|
||||
def __init__(self, *args, project=None, copyright_holder=None, **other_kwargs):
|
||||
date = datetime.now()
|
||||
date = datetime.now(tz=timezone.utc)
|
||||
super().__init__(
|
||||
*args,
|
||||
header_comment=(
|
||||
|
@ -47,7 +47,7 @@ def execute(command):
|
||||
def calculate_hash(path):
|
||||
assert os.path.isfile(path)
|
||||
with open(path, "rb") as handle:
|
||||
return hashlib.sha1(handle.read()).hexdigest()
|
||||
return hashlib.sha256(handle.read()).hexdigest()
|
||||
|
||||
|
||||
def compare_spirv(path1, path2):
|
||||
|
@ -198,10 +198,8 @@ class RelaxNGValidator:
|
||||
relaxng = lxml.etree.RelaxNG(data)
|
||||
error_count = 0
|
||||
for file in sorted(files):
|
||||
try:
|
||||
doc = lxml.etree.parse(str(file[1]))
|
||||
relaxng.assertValid(doc)
|
||||
except Exception:
|
||||
doc = lxml.etree.parse(str(file[1]))
|
||||
if not relaxng.validate(doc):
|
||||
error_count = error_count + 1
|
||||
self.logger.exception(file[1])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user