Skip to content

Commit b268746

Browse files
pdgendtkartben
authored andcommitted
scripts: list_boards: Fix linter issues
Fix issues reported by ruff. Signed-off-by: Pieter De Gendt <[email protected]>
1 parent 963fda5 commit b268746

File tree

2 files changed

+29
-41
lines changed

2 files changed

+29
-41
lines changed

.ruff-excludes.toml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -568,16 +568,6 @@
568568
"UP036", # https://docs.astral.sh/ruff/rules/outdated-version-block
569569
"UP038", # https://docs.astral.sh/ruff/rules/non-pep604-isinstance
570570
]
571-
"./scripts/list_boards.py" = [
572-
"E731", # https://docs.astral.sh/ruff/rules/lambda-assignment
573-
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
574-
"SIM102", # https://docs.astral.sh/ruff/rules/collapsible-if
575-
"UP006", # https://docs.astral.sh/ruff/rules/non-pep585-annotation
576-
"UP007", # https://docs.astral.sh/ruff/rules/non-pep604-annotation-union
577-
"UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes
578-
"UP032", # https://docs.astral.sh/ruff/rules/f-string
579-
"UP035", # https://docs.astral.sh/ruff/rules/deprecated-import
580-
]
581571
"./scripts/list_hardware.py" = [
582572
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports
583573
"UP006", # https://docs.astral.sh/ruff/rules/non-pep585-annotation

scripts/list_boards.py

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
# SPDX-License-Identifier: Apache-2.0
55

66
import argparse
7-
from collections import defaultdict, Counter
8-
from dataclasses import dataclass, field
97
import itertools
8+
import sys
9+
from collections import Counter, defaultdict
10+
from dataclasses import dataclass, field
1011
from pathlib import Path
12+
13+
import list_hardware
1114
import pykwalify.core
12-
import sys
13-
from typing import List, Union
1415
import yaml
15-
import list_hardware
1616
from list_hardware import unique_paths
1717

1818
try:
@@ -21,7 +21,7 @@
2121
from yaml import SafeLoader
2222

2323
BOARD_SCHEMA_PATH = str(Path(__file__).parent / 'schemas' / 'board-schema.yml')
24-
with open(BOARD_SCHEMA_PATH, 'r') as f:
24+
with open(BOARD_SCHEMA_PATH) as f:
2525
board_schema = yaml.load(f.read(), Loader=SafeLoader)
2626

2727
BOARD_VALIDATOR = pykwalify.core.Core(schema_data=board_schema, source_data={})
@@ -41,7 +41,7 @@
4141
@dataclass
4242
class Revision:
4343
name: str
44-
variants: List[str] = field(default_factory=list)
44+
variants: list[str] = field(default_factory=list)
4545

4646
@staticmethod
4747
def from_dict(revision):
@@ -54,7 +54,7 @@ def from_dict(revision):
5454
@dataclass
5555
class Variant:
5656
name: str
57-
variants: List[str] = field(default_factory=list)
57+
variants: list[str] = field(default_factory=list)
5858

5959
@staticmethod
6060
def from_dict(variant):
@@ -67,14 +67,14 @@ def from_dict(variant):
6767
@dataclass
6868
class Cpucluster:
6969
name: str
70-
variants: List[str] = field(default_factory=list)
70+
variants: list[str] = field(default_factory=list)
7171

7272

7373
@dataclass
7474
class Soc:
7575
name: str
76-
cpuclusters: List[str] = field(default_factory=list)
77-
variants: List[str] = field(default_factory=list)
76+
cpuclusters: list[str] = field(default_factory=list)
77+
variants: list[str] = field(default_factory=list)
7878

7979
@staticmethod
8080
def from_soc(soc, variants):
@@ -94,17 +94,17 @@ def from_soc(soc, variants):
9494
class Board:
9595
name: str
9696
# HWMv1 only supports a single Path, and requires Board dataclass to be hashable.
97-
directories: Union[Path, List[Path]]
97+
directories: Path | list[Path]
9898
hwm: str
9999
full_name: str = None
100100
arch: str = None
101101
vendor: str = None
102102
revision_format: str = None
103103
revision_default: str = None
104104
revision_exact: bool = False
105-
revisions: List[str] = field(default_factory=list, compare=False)
106-
socs: List[Soc] = field(default_factory=list, compare=False)
107-
variants: List[str] = field(default_factory=list, compare=False)
105+
revisions: list[str] = field(default_factory=list, compare=False)
106+
socs: list[Soc] = field(default_factory=list, compare=False)
107+
variants: list[str] = field(default_factory=list, compare=False)
108108

109109
@property
110110
def dir(self):
@@ -125,15 +125,14 @@ def from_qualifier(self, qualifiers):
125125
node = s
126126
break
127127

128-
if n > 1:
129-
if node.cpuclusters:
130-
cpu_qualifier = qualifiers_list.pop(0)
131-
for c in node.cpuclusters:
132-
if c.name == cpu_qualifier:
133-
node = c
134-
break
135-
else:
136-
node = Variant(None)
128+
if n > 1 and node.cpuclusters:
129+
cpu_qualifier = qualifiers_list.pop(0)
130+
for c in node.cpuclusters:
131+
if c.name == cpu_qualifier:
132+
node = c
133+
break
134+
else:
135+
node = Variant(None)
137136

138137
for q in qualifiers_list:
139138
for v in node.variants:
@@ -235,8 +234,7 @@ def load_v2_boards(board_name, board_yml, systems):
235234
BOARD_VALIDATOR.source = b
236235
BOARD_VALIDATOR.validate()
237236
except pykwalify.errors.SchemaError as e:
238-
sys.exit('ERROR: Malformed "build" section in file: {}\n{}'
239-
.format(board_yml.as_posix(), e))
237+
sys.exit(f'ERROR: Malformed "build" section in file: {board_yml.as_posix()}\n{e}')
240238

241239
mutual_exclusive = {'board', 'boards'}
242240
if len(mutual_exclusive - b.keys()) < 1:
@@ -257,10 +255,9 @@ def load_v2_boards(board_name, board_yml, systems):
257255
continue
258256

259257
# Create board
260-
if board_name is not None:
261-
if board['name'] != board_name:
262-
# Not the board we're looking for, ignore.
263-
continue
258+
if board_name is not None and board['name'] != board_name:
259+
# Not the board we're looking for, ignore.
260+
continue
264261

265262
board_revision = board.get('revision')
266263
if board_revision is not None and board_revision.get('format') != 'custom':
@@ -421,7 +418,8 @@ def dump_v2_boards(args):
421418
for b in boards.values():
422419
qualifiers_list = board_v2_qualifiers(b)
423420
if args.cmakeformat is not None:
424-
notfound = lambda x: x or 'NOTFOUND'
421+
def notfound(x):
422+
return x or 'NOTFOUND'
425423
info = args.cmakeformat.format(
426424
NAME='NAME;' + b.name,
427425
DIR='DIR;' + ';'.join(

0 commit comments

Comments
 (0)