lint: Enable more ruff ulesets

Minor fixes were needed, the only possibly interesting one is
the one in RequestsFetcher (use "yield from").

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
This commit is contained in:
Jussi Kukkonen 2024-03-27 15:29:53 +02:00
parent e1f8f73185
commit 009e1ddbf4
6 changed files with 14 additions and 8 deletions

View file

@ -80,7 +80,7 @@ def close(self, role: str, md: Metadata) -> None:
md.signed.version += 1
md.signed.expires = datetime.now(timezone.utc) + self.expiry_period
with open(f"{self.key_dir}/{role}", "rt", encoding="utf-8") as f:
with open(f"{self.key_dir}/{role}", encoding="utf-8") as f:
signer = SSlibSigner(json.loads(f.read()))
md.sign(signer, append=False)
@ -126,7 +126,7 @@ def add_delegation(self, role: str) -> bool:
return False
# Store the private key using rolename as filename
with open(f"{self.key_dir}/{role}", "wt", encoding="utf-8") as f:
with open(f"{self.key_dir}/{role}", "w", encoding="utf-8") as f:
f.write(json.dumps(keydict))
print(f"Uploaded new delegation, stored key in {self.key_dir}/{role}")

View file

@ -84,19 +84,26 @@ line-length=80
select = [
"A", # flake8-builtins
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"D", # pydocstyle
"DTZ", # flake8-datetimez
"E", # pycodestyle
"F", # pyflakes
"I", # isort
"ISC", # flake8-implicit-str-concat
"N", # pep8-naming
"PL", # pylint
"RET", # flake8-return
"S", # flake8-bandit
"SIM", # flake8-simplify
"UP", # pyupgrade
"W", # pycodestyle-warning
]
ignore = ["D400","D415","D213","D205","D202","D107","D407","D413","D212","D104","D406","D105","D411","D401","D200","D203", "PLR0913", "PLR2004"]
ignore = [
"D400", "D415", "D213", "D205", "D202", "D107", "D407", "D413", "D212", "D104", "D406", "D105", "D411", "D401", "D200", "D203",
"PLR0913", "PLR2004",
"ISC001", # incompatible with ruff formatter
]
[tool.ruff.lint.per-file-ignores]
"tests/*" = [

View file

@ -69,7 +69,7 @@ def verify_generation(md: Metadata, path: str) -> None:
if static_md_bytes != md_bytes:
raise ValueError(
f"Generated data != local data at {path}. Generate a new "
+ "metadata with 'python generated_data/generate_md.py'"
"metadata with 'python generated_data/generate_md.py'"
)

View file

@ -306,7 +306,7 @@ def test_update_timestamp_with_same_timestamp(self) -> None:
# Update timestamp with the same version.
with self.assertRaises(exceptions.EqualVersionNumberError):
self.trusted_set.update_timestamp((self.metadata[Timestamp.type]))
self.trusted_set.update_timestamp(self.metadata[Timestamp.type])
# Every object has a unique id() if they are equal, this means timestamp
# was not updated.

View file

@ -113,7 +113,7 @@ def wait_for_server(
succeeded = True
except socket.timeout:
pass
except IOError as e:
except OSError as e:
# ECONNREFUSED is expected while the server is not started
if e.errno not in [errno.ECONNREFUSED]:
logger.warning(

View file

@ -106,8 +106,7 @@ def _chunks(self, response: "requests.Response") -> Iterator[bytes]:
"""
try:
for data in response.iter_content(self.chunk_size):
yield data
yield from response.iter_content(self.chunk_size)
except (
requests.exceptions.ConnectionError,
requests.exceptions.Timeout,