Skip to content

Commit c96faac

Browse files
Fix issues reported by ruff RET rule in scripts (project-chip#42158)
* Fix issues reported by ruff RET rule in scripts * Restyled by autopep8 * Restyled by ruff * Apply suggestion made by copilot --------- Co-authored-by: Restyled.io <[email protected]>
1 parent 8059c2d commit c96faac

File tree

87 files changed

+862
-1115
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+862
-1115
lines changed

build/chip/java/javac_runner.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ def ComputeClasspath(build_config_json):
8888
unique_jars = build_config_json['deps_info']['deps_jars']
8989
if sys.platform == 'win32':
9090
return ";".join(unique_jars)
91-
else:
92-
return ":".join(unique_jars)
91+
return ":".join(unique_jars)
9392

9493

9594
def main():

build/chip/java/kotlinc_runner.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ def ComputeClasspath(build_config_json):
8888
unique_jars = build_config_json['deps_info']['deps_jars']
8989
if sys.platform == 'win32':
9090
return ";".join(unique_jars)
91-
else:
92-
return ":".join(unique_jars)
91+
return ":".join(unique_jars)
9392

9493

9594
def main():

build/chip/java/write_build_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def ParseGnList(value):
4242
"\"", "").replace(" ", "").split(",")
4343
if not gn_list[0]:
4444
return []
45-
else:
46-
return gn_list
45+
return gn_list
46+
return None
4747

4848

4949
def GetAllDependentJars(deps_configs_data):

build/config/linux/pkg-config.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ def RewritePath(path, strip_prefix, sysroot):
120120
path = path[len(strip_prefix):]
121121
path = path.lstrip('/')
122122
return os.path.join(sysroot, path)
123-
else:
124-
return path
123+
return path
125124

126125

127126
def main():
@@ -203,7 +202,7 @@ def main():
203202
print("Error from pkg-config.")
204203
return 1
205204
sys.stdout.write(dridriverdir.strip())
206-
return
205+
return None
207206

208207
cmd = [options.pkg_config, "--cflags", "--libs"]
209208

scripts/build/build_darwin_framework.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def get_file_from_pigweed(name):
2727
for filename in glob.glob(pattern, recursive=True):
2828
if os.path.isfile(filename):
2929
return filename
30+
return None
3031

3132

3233
def run_command(command):

scripts/build/builders/ameba.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,29 @@ class AmebaApp(Enum):
3333
def ExampleName(self):
3434
if self == AmebaApp.ALL_CLUSTERS:
3535
return 'all-clusters-app'
36-
elif self == AmebaApp.ALL_CLUSTERS_MINIMAL:
36+
if self == AmebaApp.ALL_CLUSTERS_MINIMAL:
3737
return 'all-clusters-minimal-app'
38-
elif self == AmebaApp.LIGHT:
38+
if self == AmebaApp.LIGHT:
3939
return 'lighting-app'
40-
elif self == AmebaApp.LIGHT_SWITCH:
40+
if self == AmebaApp.LIGHT_SWITCH:
4141
return 'light-switch-app'
42-
elif self == AmebaApp.PIGWEED:
42+
if self == AmebaApp.PIGWEED:
4343
return 'pigweed-app'
44-
else:
45-
raise Exception('Unknown app type: %r' % self)
44+
raise Exception('Unknown app type: %r' % self)
4645

4746
@property
4847
def AppNamePrefix(self):
4948
if self == AmebaApp.ALL_CLUSTERS:
5049
return 'chip-ameba-all-clusters-app'
51-
elif self == AmebaApp.ALL_CLUSTERS_MINIMAL:
50+
if self == AmebaApp.ALL_CLUSTERS_MINIMAL:
5251
return 'chip-ameba-all-clusters-minimal-app'
53-
elif self == AmebaApp.LIGHT:
52+
if self == AmebaApp.LIGHT:
5453
return 'chip-ameba-lighting-app'
55-
elif self == AmebaApp.LIGHT_SWITCH:
54+
if self == AmebaApp.LIGHT_SWITCH:
5655
return 'chip-ameba-light-switch-app'
57-
elif self == AmebaApp.PIGWEED:
56+
if self == AmebaApp.PIGWEED:
5857
return 'chip-ameba-pigweed-app'
59-
else:
60-
raise Exception('Unknown app type: %r' % self)
58+
raise Exception('Unknown app type: %r' % self)
6159

6260

6361
class AmebaBuilder(Builder):

scripts/build/builders/android.py

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,24 @@ class AndroidBoard(Enum):
3333
def TargetCpuName(self):
3434
if self == AndroidBoard.ARM or self == AndroidBoard.AndroidStudio_ARM:
3535
return "arm"
36-
elif self == AndroidBoard.ARM64 or self == AndroidBoard.AndroidStudio_ARM64:
36+
if self == AndroidBoard.ARM64 or self == AndroidBoard.AndroidStudio_ARM64:
3737
return "arm64"
38-
elif self == AndroidBoard.X64 or self == AndroidBoard.AndroidStudio_X64:
38+
if self == AndroidBoard.X64 or self == AndroidBoard.AndroidStudio_X64:
3939
return "x64"
40-
elif self == AndroidBoard.X86 or self == AndroidBoard.AndroidStudio_X86:
40+
if self == AndroidBoard.X86 or self == AndroidBoard.AndroidStudio_X86:
4141
return "x86"
42-
else:
43-
raise Exception("Unknown board type: %r" % self)
42+
raise Exception("Unknown board type: %r" % self)
4443

4544
def AbiName(self):
4645
if self.TargetCpuName() == "arm":
4746
return "armeabi-v7a"
48-
elif self.TargetCpuName() == "arm64":
47+
if self.TargetCpuName() == "arm64":
4948
return "arm64-v8a"
50-
elif self.TargetCpuName() == "x64":
49+
if self.TargetCpuName() == "x64":
5150
return "x86_64"
52-
elif self.TargetCpuName() == "x86":
51+
if self.TargetCpuName() == "x86":
5352
return "x86"
54-
else:
55-
raise Exception("Unknown board type: %r" % self)
53+
raise Exception("Unknown board type: %r" % self)
5654

5755
def IsIde(self):
5856
if (
@@ -62,8 +60,7 @@ def IsIde(self):
6260
or self == AndroidBoard.AndroidStudio_X86
6361
):
6462
return True
65-
else:
66-
return False
63+
return False
6764

6865

6966
class AndroidApp(Enum):
@@ -78,16 +75,15 @@ class AndroidApp(Enum):
7875
def AppName(self):
7976
if self == AndroidApp.CHIP_TOOL:
8077
return "CHIPTool"
81-
elif self == AndroidApp.CHIP_TEST:
78+
if self == AndroidApp.CHIP_TEST:
8279
return "CHIPTest"
83-
elif self == AndroidApp.TV_SERVER:
80+
if self == AndroidApp.TV_SERVER:
8481
return "tv-server"
85-
elif self == AndroidApp.TV_CASTING_APP:
82+
if self == AndroidApp.TV_CASTING_APP:
8683
return "tv-casting"
87-
elif self == AndroidApp.VIRTUAL_DEVICE_APP:
84+
if self == AndroidApp.VIRTUAL_DEVICE_APP:
8885
return "virtual-device-app"
89-
else:
90-
raise Exception("Unknown app type: %r" % self)
86+
raise Exception("Unknown app type: %r" % self)
9187

9288
def AppGnArgs(self):
9389
gn_args = {}
@@ -106,26 +102,23 @@ def AppGnArgs(self):
106102
def ExampleName(self):
107103
if self == AndroidApp.TV_SERVER:
108104
return "tv-app"
109-
elif self == AndroidApp.TV_CASTING_APP:
105+
if self == AndroidApp.TV_CASTING_APP:
110106
return "tv-casting-app"
111-
elif self == AndroidApp.VIRTUAL_DEVICE_APP:
107+
if self == AndroidApp.VIRTUAL_DEVICE_APP:
112108
return "virtual-device-app"
113-
elif self == AndroidApp.CHIP_TEST:
109+
if self == AndroidApp.CHIP_TEST:
114110
return "chip-test"
115-
else:
116-
return None
111+
return None
117112

118113
def Modules(self):
119114
if self == AndroidApp.TV_SERVER:
120115
return ["platform-app", "content-app"]
121-
else:
122-
return None
116+
return None
123117

124118
def BuildRoot(self, root):
125119
if self == AndroidApp.CHIP_TEST:
126120
return os.path.join(root, 'examples/android/CHIPTest')
127-
else:
128-
return None
121+
return None
129122

130123

131124
class AndroidProfile(Enum):
@@ -136,10 +129,9 @@ class AndroidProfile(Enum):
136129
def ProfileName(self):
137130
if self == AndroidProfile.RELEASE:
138131
return 'release'
139-
elif self == AndroidProfile.DEBUG:
132+
if self == AndroidProfile.DEBUG:
140133
return 'debug'
141-
else:
142-
raise Exception('Unknown profile type: %r' % self)
134+
raise Exception('Unknown profile type: %r' % self)
143135

144136

145137
class AndroidBuilder(Builder):
@@ -190,17 +182,16 @@ def _find_sdk_manager(self, for_purpose="validation"):
190182
checked_details.append(f"{path} (test environment - assumed valid)")
191183
logging.info(f"Using SDK manager for {for_purpose} from test environment: {sdk_manager}")
192184
break
193-
else:
194-
# Real environment - check actual file existence
195-
exists = os.path.isfile(path)
196-
executable = os.access(path, os.X_OK)
197-
checked_details.append(f"{path} (exists: {exists}, executable: {executable})")
198-
logging.debug(f"Checking SDK manager path for {for_purpose}: {path} - exists: {exists}, executable: {executable}")
185+
# Real environment - check actual file existence
186+
exists = os.path.isfile(path)
187+
executable = os.access(path, os.X_OK)
188+
checked_details.append(f"{path} (exists: {exists}, executable: {executable})")
189+
logging.debug(f"Checking SDK manager path for {for_purpose}: {path} - exists: {exists}, executable: {executable}")
199190

200-
if exists and executable:
201-
sdk_manager = path
202-
logging.info(f"Found SDK manager for {for_purpose} at: {sdk_manager}")
203-
break
191+
if exists and executable:
192+
sdk_manager = path
193+
logging.info(f"Found SDK manager for {for_purpose} at: {sdk_manager}")
194+
break
204195

205196
return sdk_manager, checked_details
206197

@@ -223,7 +214,7 @@ def validate_build_environment(self):
223214
android_ndk_home = os.environ.get("ANDROID_NDK_HOME", "")
224215
android_home = os.environ.get("ANDROID_HOME", "")
225216

226-
logging.info(f"Android environment paths:")
217+
logging.info("Android environment paths:")
227218
logging.info(f" ANDROID_NDK_HOME: {android_ndk_home}")
228219
logging.info(f" ANDROID_HOME: {android_home}")
229220

@@ -246,7 +237,7 @@ def validate_build_environment(self):
246237
possible_fixes = [
247238
f"1. Install Android SDK Command Line Tools in {android_home}",
248239
f"2. Fix permissions: chmod +x {android_home}/cmdline-tools/*/bin/sdkmanager",
249-
f"3. Verify ANDROID_HOME points to correct SDK directory"
240+
"3. Verify ANDROID_HOME points to correct SDK directory"
250241
]
251242

252243
raise Exception(

scripts/build/builders/asr.py

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,54 +35,52 @@ class ASRApp(Enum):
3535
def ExampleName(self):
3636
if self == ASRApp.ALL_CLUSTERS:
3737
return 'all-clusters-app'
38-
elif self == ASRApp.ALL_CLUSTERS_MINIMAL:
38+
if self == ASRApp.ALL_CLUSTERS_MINIMAL:
3939
return 'all-clusters-minimal-app'
40-
elif self == ASRApp.LIGHT:
40+
if self == ASRApp.LIGHT:
4141
return 'lighting-app'
42-
elif self == ASRApp.LIGHT_SWITCH:
42+
if self == ASRApp.LIGHT_SWITCH:
4343
return 'light-switch-app'
44-
elif self == ASRApp.LOCK:
44+
if self == ASRApp.LOCK:
4545
return 'lock-app'
46-
elif self == ASRApp.BRIDGE:
46+
if self == ASRApp.BRIDGE:
4747
return 'bridge-app'
48-
elif self == ASRApp.TEMPERATURE_MEASUREMENT:
48+
if self == ASRApp.TEMPERATURE_MEASUREMENT:
4949
return 'temperature-measurement-app'
50-
elif self == ASRApp.THERMOSTAT:
50+
if self == ASRApp.THERMOSTAT:
5151
return 'thermostat'
52-
elif self == ASRApp.OTA_REQUESTOR:
52+
if self == ASRApp.OTA_REQUESTOR:
5353
return 'ota-requestor-app'
54-
elif self == ASRApp.DISHWASHER:
54+
if self == ASRApp.DISHWASHER:
5555
return 'dishwasher-app'
56-
elif self == ASRApp.REFRIGERATOR:
56+
if self == ASRApp.REFRIGERATOR:
5757
return 'refrigerator-app'
58-
else:
59-
raise Exception('Unknown app type: %r' % self)
58+
raise Exception('Unknown app type: %r' % self)
6059

6160
def AppNamePrefix(self):
6261
if self == ASRApp.ALL_CLUSTERS:
6362
return 'chip-asr-all-clusters-app'
64-
elif self == ASRApp.ALL_CLUSTERS_MINIMAL:
63+
if self == ASRApp.ALL_CLUSTERS_MINIMAL:
6564
return 'chip-asr-all-clusters-minimal-app'
66-
elif self == ASRApp.LIGHT:
65+
if self == ASRApp.LIGHT:
6766
return 'chip-asr-lighting-app'
68-
elif self == ASRApp.LIGHT_SWITCH:
67+
if self == ASRApp.LIGHT_SWITCH:
6968
return 'chip-asr-light-switch-app'
70-
elif self == ASRApp.LOCK:
69+
if self == ASRApp.LOCK:
7170
return 'chip-asr-lock-example'
72-
elif self == ASRApp.BRIDGE:
71+
if self == ASRApp.BRIDGE:
7372
return 'chip-asr-bridge-example'
74-
elif self == ASRApp.TEMPERATURE_MEASUREMENT:
73+
if self == ASRApp.TEMPERATURE_MEASUREMENT:
7574
return 'chip-asr-temperature-measurement-example'
76-
elif self == ASRApp.THERMOSTAT:
75+
if self == ASRApp.THERMOSTAT:
7776
return 'chip-asr-thermostat-example'
78-
elif self == ASRApp.OTA_REQUESTOR:
77+
if self == ASRApp.OTA_REQUESTOR:
7978
return 'chip-asr-ota-requestor-example'
80-
elif self == ASRApp.DISHWASHER:
79+
if self == ASRApp.DISHWASHER:
8180
return 'chip-asr-dishwasher-example'
82-
elif self == ASRApp.REFRIGERATOR:
81+
if self == ASRApp.REFRIGERATOR:
8382
return 'chip-asr-refrigerator-example'
84-
else:
85-
raise Exception('Unknown app type: %r' % self)
83+
raise Exception('Unknown app type: %r' % self)
8684

8785
def BuildRoot(self, root):
8886
return os.path.join(root, 'examples', self.ExampleName(), 'asr')
@@ -96,12 +94,11 @@ class ASRBoard(Enum):
9694
def GetIC(self):
9795
if self == ASRBoard.ASR582X:
9896
return 'asr582x'
99-
elif self == ASRBoard.ASR595X:
97+
if self == ASRBoard.ASR595X:
10098
return 'asr595x'
101-
elif self == ASRBoard.ASR550X:
99+
if self == ASRBoard.ASR550X:
102100
return 'asr550x'
103-
else:
104-
raise Exception('Unknown board #: %r' % self)
101+
raise Exception('Unknown board #: %r' % self)
105102

106103

107104
class ASRBuilder(GnBuilder):

0 commit comments

Comments
 (0)