style: allow python style check in tools

[no changelog]
This commit is contained in:
tychovrahe
2025-06-28 18:27:33 +02:00
committed by TychoVrahe
parent 438fb2554c
commit 981ddb046f
43 changed files with 222 additions and 159 deletions

View File

@@ -7,7 +7,7 @@ from pathlib import Path
import click
from mako.template import Template
from munch import munchify, Munch
from munch import Munch, munchify
HERE = Path(__file__).parent
ROOT = HERE.parent.resolve()

View File

@@ -1,8 +1,8 @@
#!/usr/bin/env python3
from pathlib import Path
import re
import subprocess
from pathlib import Path
import click
@@ -40,7 +40,7 @@ def bump_python(filename, new_version):
def hex_lit(version):
return r'"\x{:02X}"'.format(int(version))
return rf'"\x{int(version):02X}"'
@click.command()

View File

@@ -1,14 +1,13 @@
#!/usr/bin/env python3
import datetime
from pathlib import Path
import re
import subprocess
from pathlib import Path
from typing import Iterator
import click
from typing import Iterator
LINK_RE = re.compile(r"\[#(\d+)\]")
ISSUE_URL = "https://github.com/trezor/trezor-firmware/pull/{issue}"
@@ -265,7 +264,7 @@ def generate(project, version, date, check, only_models):
if only_models:
generate_filtered(project, changelog)
return 0
return
args = ["towncrier", "build", "--yes", "--version", version, "--date", date]
if check:

View File

@@ -19,7 +19,7 @@ elif len(sys.argv) == 2:
filenames = (FILE_T1, FILE_T2)
else:
print(f"Usage: {sys.argv[0]} HEX_CHALLENGE [FILE]...")
print(f" HEX_CHALLENGE: a 0-32 byte challenge in hexadecimal")
print(" HEX_CHALLENGE: a 0-32 byte challenge in hexadecimal")
exit(1)

View File

@@ -3,11 +3,13 @@ Taken from https://gist.github.com/patrickfuller/e2ea8a94badc5b6967ef3ca0a9452a
Currently writes all issues that have some Weight.
"""
import argparse
import csv
import requests
import os.path
import requests
token = None
path = os.path.dirname(os.path.realpath(__file__))
@@ -49,7 +51,6 @@ def write_issues(r, csvout):
if not weight:
continue
labels = ", ".join(labels)
date = issue["created_at"].split("T")[0]
milestone = issue["milestone"]["title"] if issue["milestone"] else ""
assignee = issue["assignee"]["login"] if issue["assignee"] else ""

View File

@@ -4,9 +4,8 @@ import subprocess
from pathlib import Path
import click
from elftools.construct import Struct, ULInt32, GreedyRange
from elftools.common.construct_utils import ULEB128
from elftools.construct import GreedyRange, Struct, ULInt32
from elftools.elf.elffile import ELFFile
SYMBOL_TYPES = ("t", "w") # text, weak

View File

@@ -49,13 +49,13 @@ from pathlib import Path
from typing import Dict # for python38 support, must be used in type aliases
from typing import List # for python38 support, must be used in type aliases
from typing import TYPE_CHECKING, Any, Iterator
import click
from typing_extensions import ( # for python37 support, is not present in typing there
Final,
TypedDict,
)
import click
if TYPE_CHECKING:
LineIgnores = List["LineIgnore"]
@@ -542,7 +542,7 @@ class PyrightTool:
ignore_statements = self.get_ignore_statements(line)
if not ignore_statements:
self.inconsistencies.append(
f"There is an empty `{self.IGNORE_PATTERN}` in {file}:{index+1}"
f"There is an empty `{self.IGNORE_PATTERN}` in {file}:{index + 1}"
)
else:
ignores.append(LineIgnore(index, ignore_statements))

View File

@@ -17,11 +17,12 @@
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
from __future__ import annotations
import click
import requests
import zipfile
from pathlib import Path
import click
import requests
from trezorlib import definitions, merkle_tree
ZIP_FILENAME = "definitions-sparse.zip"

View File

@@ -4,9 +4,9 @@
from __future__ import annotations
from typing_extensions import Literal
from typing import Tuple
from typing_extensions import Literal
Bit = Literal[0, 1]
Point = Tuple[int, int]

View File

@@ -68,11 +68,10 @@ def check_usage_of_functions(func_mapping: Dict[str, List[str]]) -> None:
is_used_mappings[func_name] = {"mapping": mapping, "is_used": False}
# Check if any of the mapping names is used - and mark it as used if so
for func_name in is_used_mappings:
for mapping in is_used_mappings[func_name]["mapping"]:
is_there = _is_used(mapping)
if is_there:
is_used_mappings[func_name]["is_used"] = True
for func_name, info in is_used_mappings.items():
for m in info["mapping"]:
if _is_used(m):
info["is_used"] = True
break
# Find unused functions and generate a report

View File

@@ -1,12 +1,12 @@
import sys
from pathlib import Path
from pyasn1.codec.der.encoder import encode
from pyasn1.codec.der.decoder import decode
from pyasn1.type.univ import BitString
from pyasn1_modules import rfc2459
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import ec
from pyasn1.codec.der.decoder import decode
from pyasn1.codec.der.encoder import encode
from pyasn1.type.univ import BitString
from pyasn1_modules import rfc2459
def load_certificate(data: bytes):

View File

@@ -37,6 +37,7 @@ Usage:
- specifying FILES_TO_MODIFY
- call the script with possible flags - see `python unify_test_files.py --help`
"""
import json
import os
import re
@@ -92,7 +93,7 @@ class FileUnifier:
else:
self.translations = {}
print(
f"{len(self.translations)} translations available (path/address and address/path)\n{80*'*'}"
f"{len(self.translations)} translations available (path/address and address/path)\n{80 * '*'}"
)
# For statistical purposes

View File

@@ -2,3 +2,4 @@
^legacy/firmware/protob/options_pb2\.py
^legacy/firmware/protob/messages_nem_pb2\.py
^legacy/vendor
^tools/automatic_battery_tester/.venv/

View File

@@ -2,8 +2,10 @@
^core/src/
^core/site_scons/
^core/tests/
^core/tools/
^crypto/
^legacy/
^storage/
^tools/
^tests/
^ci/

View File

@@ -0,0 +1,2 @@
^core/tools/
^tools/