Skip to content

Commit 22f2fc9

Browse files
authored
Enable more Python lints (#11329)
1 parent 8b7660d commit 22f2fc9

File tree

71 files changed

+305
-311
lines changed

Some content is hidden

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

71 files changed

+305
-311
lines changed

docs/snippets/all/tutorials/custom_data.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ def __init__(self: Any, positions: npt.ArrayLike, confidences: npt.ArrayLike) ->
3636
)
3737

3838
def as_component_batches(self) -> list[rr.DescribedComponentBatch]:
39-
return (
40-
list(self.points3d.as_component_batches()) # The components from Points3D
41-
+ [self.confidences] # Custom confidence data
42-
)
39+
return [
40+
*self.points3d.as_component_batches(), # The components from Points3D
41+
self.confidences, # Custom confidence data
42+
]
4343

4444

4545
def log_custom_data() -> None:

docs/snippets/compare_snippet_output.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import tomlkit
1919

2020
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/../../scripts/")
21-
from roundtrip_utils import roundtrip_env, run, run_comparison # noqa
21+
from roundtrip_utils import roundtrip_env, run, run_comparison
2222

2323
if TYPE_CHECKING:
2424
from tomlkit.container import Container
@@ -148,7 +148,11 @@ def main() -> None:
148148
if name == "__init__.py":
149149
continue
150150
name, extension = os.path.splitext(name)
151-
if extension == ".cpp" and not args.no_cpp or extension == ".py" and not args.no_py or extension == ".rs":
151+
if (
152+
(extension == ".cpp" and not args.no_cpp)
153+
or (extension == ".py" and not args.no_py)
154+
or extension == ".rs"
155+
):
152156
subdir = os.path.relpath(os.path.dirname(file), dir)
153157
examples += [Example(subdir.replace("\\", "/"), name)]
154158

@@ -299,7 +303,7 @@ def build_rust_snippets(build_env: dict[str, str], release: bool, target: str |
299303
run(cmd, env=build_env, timeout=12000)
300304
elapsed = time.time() - start_time
301305
print(f"Snippets built in {elapsed:.1f} seconds")
302-
print("")
306+
print()
303307

304308

305309
def build_python_sdk(build_env: dict[str, str]) -> None:
@@ -309,7 +313,7 @@ def build_python_sdk(build_env: dict[str, str]) -> None:
309313
run(["pixi", "run", "py-build", "--quiet"], env=build_env, timeout=12000)
310314
elapsed = time.time() - start_time
311315
print(f"rerun-sdk for Python built in {elapsed:.1f} seconds")
312-
print("")
316+
print()
313317

314318

315319
def build_cpp_snippets() -> None:
@@ -319,7 +323,7 @@ def build_cpp_snippets() -> None:
319323
run(["pixi", "run", "-e", "cpp", "cpp-build-snippets"], timeout=12000)
320324
elapsed = time.time() - start_time
321325
print(f"rerun-sdk for C++ built in {elapsed:.1f} seconds")
322-
print("")
326+
print()
323327

324328

325329
def run_python(example: Example) -> str:
@@ -331,7 +335,7 @@ def run_python(example: Example) -> str:
331335
if python_executable is None:
332336
python_executable = "python3"
333337

334-
cmd = [python_executable, main_path] + example.extra_args()
338+
cmd = [python_executable, main_path, *example.extra_args()]
335339

336340
env = roundtrip_env(save_path=output_path)
337341
run(cmd, env=env, timeout=30)
@@ -368,7 +372,7 @@ def run_prebuilt_cpp(example: Example) -> str:
368372
output_path = example.output_path("cpp")
369373

370374
extension = ".exe" if os.name == "nt" else ""
371-
cmd = [f"./build/debug/docs/snippets/{example.name}{extension}"] + example.extra_args()
375+
cmd = [f"./build/debug/docs/snippets/{example.name}{extension}", *example.extra_args()]
372376
env = roundtrip_env(save_path=output_path)
373377
run(cmd, env=env, timeout=30)
374378

examples/python/depth_guided_stable_diffusion/depth_guided_stable_diffusion/__main__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@
3030

3131
IMAGE_NAME_TO_URL: Final = {
3232
"sitting_wooden_figure": "https://storage.googleapis.com/rerun-example-datasets/stable_diffusion/sitting_wooden_figure.jpg",
33-
# noqa: E501 line too long
3433
"old_man": "https://github.com/Stability-AI/stablediffusion/raw/main/assets/stable-samples/depth2img/old_man.png",
35-
# noqa: E501 line too long
3634
"fantasy": "https://github.com/Stability-AI/stablediffusion/raw/main/assets/stable-samples/depth2img/depth2fantasy.jpeg",
37-
# noqa: E501 line too long
3835
}
3936
IMAGE_NAMES: Final = list(IMAGE_NAME_TO_URL.keys())
4037

@@ -52,8 +49,7 @@ def get_downloaded_path(dataset_dir: Path, image_name: str) -> str:
5249
with requests.get(image_url, stream=True) as req:
5350
req.raise_for_status()
5451
with open(destination_path, "wb") as f:
55-
for chunk in req.iter_content(chunk_size=8192):
56-
f.write(chunk)
52+
f.writelines(req.iter_content(chunk_size=8192))
5753
return str(destination_path)
5854

5955

examples/python/detect_and_track_objects/detect_and_track_objects.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,7 @@ def get_downloaded_path(dataset_dir: Path, video_name: str) -> str:
402402
with requests.get(source_path, stream=True) as req:
403403
req.raise_for_status()
404404
with open(destination_path, "wb") as f:
405-
for chunk in req.iter_content(chunk_size=8192):
406-
f.write(chunk)
405+
f.writelines(req.iter_content(chunk_size=8192))
407406
return str(destination_path)
408407

409408

examples/python/external_data_loader/rerun-loader-python-file.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import argparse
77
import os
8+
import sys
89

910
import rerun as rr # pip install rerun-sdk
1011

@@ -63,7 +64,7 @@ def main() -> None:
6364

6465
# Inform the Rerun Viewer that we do not support that kind of file.
6566
if not is_file or not is_python_file:
66-
exit(rr.EXTERNAL_DATA_LOADER_INCOMPATIBLE_EXIT_CODE)
67+
sys.exit(rr.EXTERNAL_DATA_LOADER_INCOMPATIBLE_EXIT_CODE)
6768

6869
app_id = "rerun_example_external_data_loader"
6970
if args.application_id is not None:

examples/python/human_pose_tracking/human_pose_tracking.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ def download(url: str, destination_path: Path) -> None:
193193
with requests.get(url, stream=True) as req:
194194
req.raise_for_status()
195195
with open(destination_path, "wb") as f:
196-
for chunk in req.iter_content(chunk_size=8192):
197-
f.write(chunk)
196+
f.writelines(req.iter_content(chunk_size=8192))
198197

199198

200199
def main() -> None:

examples/python/imu_signals/imu_signals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _download_dataset(root: Path, dataset_url: str = DATASET_URL) -> None:
7777
pb.update(len(data))
7878
file.write(data)
7979

80-
if total_size != 0 and pb.n != total_size:
80+
if total_size not in (0, pb.n):
8181
raise RuntimeError("Failed to download complete dataset!")
8282

8383
print("Extracting dataset…")

examples/python/lidar/lidar/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import argparse
55
import pathlib
6+
import sys
67
from typing import Final
78

89
import matplotlib
@@ -40,7 +41,7 @@ def ensure_scene_available(root_dir: pathlib.Path, dataset_version: str, scene_n
4041
nusc = nuscenes.NuScenes(version=dataset_version, dataroot=root_dir, verbose=True)
4142
else:
4243
print(f"Could not find dataset at {root_dir} and could not automatically download specified scene.")
43-
exit()
44+
sys.exit()
4445

4546
scene_names = [s["name"] for s in nusc.scene]
4647
if scene_name not in scene_names:

examples/python/multiprocess_logging/multiprocess_logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def task(child_index: int) -> None:
3131
"log",
3232
rr.TextLog(
3333
f"Logging from pid={os.getpid()}, thread={threading.get_ident()} using the rerun recording id {rr.get_recording_id()}",
34-
), # noqa: E501 line too long
34+
),
3535
)
3636
if child_index == 0:
3737
rr.log(title, rr.Boxes2D(array=[5, 5, 80, 80], array_format=rr.Box2DFormat.XYWH, labels=title))

examples/python/nuscenes_dataset/nuscenes_dataset/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import argparse
55
import pathlib
6+
import sys
67
from typing import Any, Final
78

89
import matplotlib
@@ -51,7 +52,7 @@ def ensure_scene_available(root_dir: pathlib.Path, dataset_version: str, scene_n
5152
nusc = nuscenes.NuScenes(version=dataset_version, dataroot=root_dir, verbose=True)
5253
else:
5354
print(f"Could not find dataset at {root_dir} and could not automatically download specified scene.")
54-
exit()
55+
sys.exit()
5556

5657
scene_names = [s["name"] for s in nusc.scene]
5758
if scene_name not in scene_names:

0 commit comments

Comments
 (0)