Skip to content

Commit

Permalink
chore(python): add ruff linter as a dependency
Browse files Browse the repository at this point in the history
[no changelog]
  • Loading branch information
grdddj committed Aug 17, 2023
1 parent b151a3d commit e85e9e8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions ci/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ stdenvNoCC.mkDerivation ({
poetry
protobuf3_19
pyright
ruff
(mkBinOnlyWrapper rustNightly)
wget
zlib
Expand Down
10 changes: 7 additions & 3 deletions core/embed/firmware/bootloader_hashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def aligned_digest(data: bytes, padding: bytes) -> bytes:
(unwritten NOR-flash byte) or 0x00 (explicitly cleared byte).
"""
if len(data) > ALIGNED_SIZE:
raise ValueError(fn, "too big")
raise ValueError("too big")

assert len(padding) == 1
digest_data = data + padding * (ALIGNED_SIZE - len(data))
Expand All @@ -55,8 +55,12 @@ def bootloader_str(file: Path) -> str:
data = file.read_bytes()

suffix = file.stem[len("bootloader_") :].upper()
bytes_00 = to_uint_array(aligned_digest(data, b"\x00"))
bytes_ff = to_uint_array(aligned_digest(data, b"\xff"))

try:
bytes_00 = to_uint_array(aligned_digest(data, b"\x00"))
bytes_ff = to_uint_array(aligned_digest(data, b"\xff"))
except ValueError:
raise ValueError(f"Data too big in {file} - {len(data)} bytes")

try:
bl = FirmwareImage.parse(data)
Expand Down
6 changes: 3 additions & 3 deletions core/prof/prof.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self):
self.__files = {}

def line_tick(self, filename, lineno):
if not filename in self.__files:
if filename not in self.__files:
self.__files[filename] = set()
self.__files[filename].add(lineno)

Expand Down Expand Up @@ -120,7 +120,7 @@ def atexit():
sys.atexit(atexit)

global __prof__
if not "__prof__" in globals():
if "__prof__" not in globals():
if getenv("TREZOR_MEMPERF") == "1":
__prof__ = AllocCounter()
else:
Expand All @@ -131,4 +131,4 @@ def atexit():
if isinstance(__prof__, AllocCounter):
__prof__.last_alloc_count = micropython.alloc_count()

import main
import main # noqa: F401 (imported but unused)
2 changes: 1 addition & 1 deletion core/tools/alloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import click
from dominate import document
from dominate.tags import *
from dominate.tags import meta, style, h3, table, thead, tr, th, tbody, td, a
from dominate.util import raw

HERE = Path(__file__).resolve().parent
Expand Down
2 changes: 1 addition & 1 deletion core/tools/hid-bridge/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def __get_timestamp():


def __log_message(message):
if log_timestamps == True:
if log_timestamps is True:
print(f"{__get_timestamp()}\t{message}")
else:
print(message)
Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,11 @@ extra_standard_library = [
]
known_first_party = ["trezorlib", "apps", "coin_info", "marketcap", "ui_tests", "gitlab"]
known_third_party = ["trezor", "storage"]

[tool.ruff]
ignore = [
"E501", # line too long
"E402", # module level import not at top of file
"E741", # ambiguous variable name
]
exclude = ["tests", "mocks"]

0 comments on commit e85e9e8

Please sign in to comment.