From 6e773a2bd545a7c2e01f712a43789ab8ccc213b5 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Mon, 19 Feb 2024 19:10:53 +0100 Subject: [PATCH] extend ruff config mostly to remove useless noqa --- .pre-commit-config.yaml | 4 ---- docs/conf.py | 2 +- experiments/job-runner/job_runner/utils.py | 1 + .../pose_estimators/cosypose/cosypose/datasets/bop.py | 2 +- .../cosypose/cosypose/recording/bop_recording_scene.py | 2 +- .../cosypose/cosypose/scripts/run_bop_inference.py | 8 +++----- .../cosypose/scripts/run_colmap_reconstruction.py | 2 +- .../cosypose/cosypose/scripts/run_cosypose_eval.py | 10 ++++------ .../cosypose/cosypose/scripts/run_custom_scenario.py | 2 +- .../cosypose/cosypose/scripts/run_detection_eval.py | 6 +++--- .../cosypose/cosypose/utils/tensor_collection.py | 2 +- .../cosypose/cosypose/visualization/multiview.py | 4 +--- .../cosypose/cosypose/visualization/plotter.py | 3 ++- .../cosypose/cosypose/visualization/singleview.py | 2 +- .../pose_estimators/megapose/evaluation/eval_config.py | 4 ++-- .../megapose/scripts/make_shapenet_statistics.py | 6 +++--- .../megapose/training/training_config.py | 2 +- happypose/toolbox/datasets/bop_scene_dataset.py | 2 +- happypose/toolbox/datasets/datasets_cfg.py | 2 +- happypose/toolbox/datasets/pose_dataset.py | 9 +++++---- happypose/toolbox/renderer/types.py | 4 ++-- happypose/toolbox/utils/tensor_collection.py | 2 +- pyproject.toml | 7 +++++-- 23 files changed, 42 insertions(+), 46 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dbab8a98..37f1d05f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,8 +1,4 @@ repos: -- repo: https://github.com/PyCQA/isort - rev: 5.13.2 - hooks: - - id: isort - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.2.1 hooks: diff --git a/docs/conf.py b/docs/conf.py index 09fd7443..505493af 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -10,7 +10,7 @@ import happypose project = happypose.__name__ -copyright = f"2023, {happypose.__author__}" # noqa: A001 +copyright = f"2023, {happypose.__author__}" author = happypose.__author__ release = happypose.__version__ diff --git a/experiments/job-runner/job_runner/utils.py b/experiments/job-runner/job_runner/utils.py index 2b24a298..ceb9dc41 100644 --- a/experiments/job-runner/job_runner/utils.py +++ b/experiments/job-runner/job_runner/utils.py @@ -3,6 +3,7 @@ from typing import List import submitit + from job_runner.configs import JobEnvironmentConfig, RunnerConfig diff --git a/happypose/pose_estimators/cosypose/cosypose/datasets/bop.py b/happypose/pose_estimators/cosypose/cosypose/datasets/bop.py index e94fcff8..f1b7e985 100644 --- a/happypose/pose_estimators/cosypose/cosypose/datasets/bop.py +++ b/happypose/pose_estimators/cosypose/cosypose/datasets/bop.py @@ -13,7 +13,7 @@ from happypose.toolbox.lib3d.transform import Transform sys.path.append(str(BOP_TOOLKIT_DIR)) -from bop_toolkit_lib import inout # noqa +from bop_toolkit_lib import inout sys.path = sys.path[:-1] diff --git a/happypose/pose_estimators/cosypose/cosypose/recording/bop_recording_scene.py b/happypose/pose_estimators/cosypose/cosypose/recording/bop_recording_scene.py index 8a88f680..ad95fa6e 100644 --- a/happypose/pose_estimators/cosypose/cosypose/recording/bop_recording_scene.py +++ b/happypose/pose_estimators/cosypose/cosypose/recording/bop_recording_scene.py @@ -120,7 +120,7 @@ def pick_rand_objects(self): self.bodies = self.body_cache.get_bodies_by_ids(ids) def visuals_rand(self): - bodies = [self.background] + [self.plane] + bodies = [self.background, self.plane] if self.textures_on_objects and self.np_random.rand() > 0.9: bodies = self.bodies + bodies for body in bodies: diff --git a/happypose/pose_estimators/cosypose/cosypose/scripts/run_bop_inference.py b/happypose/pose_estimators/cosypose/cosypose/scripts/run_bop_inference.py index b2148347..33525ec4 100644 --- a/happypose/pose_estimators/cosypose/cosypose/scripts/run_bop_inference.py +++ b/happypose/pose_estimators/cosypose/cosypose/scripts/run_bop_inference.py @@ -22,10 +22,10 @@ make_object_dataset, make_scene_dataset, ) -from happypose.pose_estimators.cosypose.cosypose.datasets.wrappers.multiview_wrapper import ( # noqa: E501 +from happypose.pose_estimators.cosypose.cosypose.datasets.wrappers.multiview_wrapper import ( MultiViewWrapper, ) -from happypose.pose_estimators.cosypose.cosypose.evaluation.pred_runner.bop_predictions import ( # noqa: E501 +from happypose.pose_estimators.cosypose.cosypose.evaluation.pred_runner.bop_predictions import ( BopPredictionRunner, ) from happypose.pose_estimators.cosypose.cosypose.evaluation.runner_utils import ( @@ -67,9 +67,7 @@ init_distributed_mode, ) from happypose.pose_estimators.cosypose.cosypose.utils.logging import get_logger -from happypose.toolbox.renderer.bullet_batch_renderer import ( # noqa: E501 - BulletBatchRenderer, -) +from happypose.toolbox.renderer.bullet_batch_renderer import BulletBatchRenderer torch.multiprocessing.set_sharing_strategy("file_system") torch.backends.cudnn.deterministic = True diff --git a/happypose/pose_estimators/cosypose/cosypose/scripts/run_colmap_reconstruction.py b/happypose/pose_estimators/cosypose/cosypose/scripts/run_colmap_reconstruction.py index 26d87463..7ef2d504 100644 --- a/happypose/pose_estimators/cosypose/cosypose/scripts/run_colmap_reconstruction.py +++ b/happypose/pose_estimators/cosypose/cosypose/scripts/run_colmap_reconstruction.py @@ -9,7 +9,7 @@ from happypose.pose_estimators.cosypose.cosypose.datasets.datasets_cfg import ( make_scene_dataset, ) -from happypose.pose_estimators.cosypose.cosypose.datasets.wrappers.multiview_wrapper import ( # noqa: E501 +from happypose.pose_estimators.cosypose.cosypose.datasets.wrappers.multiview_wrapper import ( MultiViewWrapper, ) diff --git a/happypose/pose_estimators/cosypose/cosypose/scripts/run_cosypose_eval.py b/happypose/pose_estimators/cosypose/cosypose/scripts/run_cosypose_eval.py index 82ef8662..7759c156 100644 --- a/happypose/pose_estimators/cosypose/cosypose/scripts/run_cosypose_eval.py +++ b/happypose/pose_estimators/cosypose/cosypose/scripts/run_cosypose_eval.py @@ -28,16 +28,16 @@ make_scene_dataset, ) from happypose.pose_estimators.cosypose.cosypose.datasets.samplers import ListSampler -from happypose.pose_estimators.cosypose.cosypose.datasets.wrappers.multiview_wrapper import ( # noqa: E501 +from happypose.pose_estimators.cosypose.cosypose.datasets.wrappers.multiview_wrapper import ( MultiViewWrapper, ) -from happypose.pose_estimators.cosypose.cosypose.evaluation.eval_runner.pose_eval import ( # noqa: E501 +from happypose.pose_estimators.cosypose.cosypose.evaluation.eval_runner.pose_eval import ( PoseEvaluation, ) from happypose.pose_estimators.cosypose.cosypose.evaluation.meters.pose_meters import ( PoseErrorMeter, ) -from happypose.pose_estimators.cosypose.cosypose.evaluation.pred_runner.multiview_predictions import ( # noqa: E501 +from happypose.pose_estimators.cosypose.cosypose.evaluation.pred_runner.multiview_predictions import ( MultiviewPredictionRunner, ) from happypose.pose_estimators.cosypose.cosypose.evaluation.runner_utils import ( @@ -65,9 +65,7 @@ ) from happypose.pose_estimators.cosypose.cosypose.utils.logging import get_logger from happypose.toolbox.lib3d.transform import Transform -from happypose.toolbox.renderer.bullet_batch_renderer import ( # noqa: E501 - BulletBatchRenderer, -) +from happypose.toolbox.renderer.bullet_batch_renderer import BulletBatchRenderer logger = get_logger(__name__) diff --git a/happypose/pose_estimators/cosypose/cosypose/scripts/run_custom_scenario.py b/happypose/pose_estimators/cosypose/cosypose/scripts/run_custom_scenario.py index e4d96469..f0923679 100644 --- a/happypose/pose_estimators/cosypose/cosypose/scripts/run_custom_scenario.py +++ b/happypose/pose_estimators/cosypose/cosypose/scripts/run_custom_scenario.py @@ -26,7 +26,7 @@ from happypose.pose_estimators.cosypose.cosypose.visualization.multiview import nms3d sys.path.append(str(BOP_TOOLKIT_DIR)) -from bop_toolkit_lib import inout # noqa +from bop_toolkit_lib import inout logger = get_logger(__name__) diff --git a/happypose/pose_estimators/cosypose/cosypose/scripts/run_detection_eval.py b/happypose/pose_estimators/cosypose/cosypose/scripts/run_detection_eval.py index 8fbf89af..26fc54df 100644 --- a/happypose/pose_estimators/cosypose/cosypose/scripts/run_detection_eval.py +++ b/happypose/pose_estimators/cosypose/cosypose/scripts/run_detection_eval.py @@ -14,13 +14,13 @@ from happypose.pose_estimators.cosypose.cosypose.datasets.datasets_cfg import ( make_scene_dataset, ) -from happypose.pose_estimators.cosypose.cosypose.evaluation.eval_runner.detection_eval import ( # noqa: E501 +from happypose.pose_estimators.cosypose.cosypose.evaluation.eval_runner.detection_eval import ( DetectionEvaluation, ) -from happypose.pose_estimators.cosypose.cosypose.evaluation.meters.detection_meters import ( # noqa: E501 +from happypose.pose_estimators.cosypose.cosypose.evaluation.meters.detection_meters import ( DetectionMeter, ) -from happypose.pose_estimators.cosypose.cosypose.evaluation.pred_runner.detections import ( # noqa: E501 +from happypose.pose_estimators.cosypose.cosypose.evaluation.pred_runner.detections import ( DetectionRunner, ) from happypose.pose_estimators.cosypose.cosypose.evaluation.runner_utils import ( diff --git a/happypose/pose_estimators/cosypose/cosypose/utils/tensor_collection.py b/happypose/pose_estimators/cosypose/cosypose/utils/tensor_collection.py index f8ff076e..a9695056 100644 --- a/happypose/pose_estimators/cosypose/cosypose/utils/tensor_collection.py +++ b/happypose/pose_estimators/cosypose/cosypose/utils/tensor_collection.py @@ -65,7 +65,7 @@ def tensors(self): @property def device(self): - return list(self.tensors.values())[0].device + return next(iter(self.tensors.values())).device def __getstate__(self): return {"tensors": self.tensors} diff --git a/happypose/pose_estimators/cosypose/cosypose/visualization/multiview.py b/happypose/pose_estimators/cosypose/cosypose/visualization/multiview.py index 49ea1d30..e438eb7a 100644 --- a/happypose/pose_estimators/cosypose/cosypose/visualization/multiview.py +++ b/happypose/pose_estimators/cosypose/cosypose/visualization/multiview.py @@ -13,9 +13,7 @@ from happypose.toolbox.lib3d.rotations import euler2quat from happypose.toolbox.lib3d.transform import Transform from happypose.toolbox.lib3d.transform_ops import invert_transform_matrices -from happypose.toolbox.renderer.bullet_scene_renderer import ( # noqa: E501 - BulletSceneRenderer, -) +from happypose.toolbox.renderer.bullet_scene_renderer import BulletSceneRenderer from .plotter import Plotter diff --git a/happypose/pose_estimators/cosypose/cosypose/visualization/plotter.py b/happypose/pose_estimators/cosypose/cosypose/visualization/plotter.py index 2f3129a5..7ac14250 100644 --- a/happypose/pose_estimators/cosypose/cosypose/visualization/plotter.py +++ b/happypose/pose_estimators/cosypose/cosypose/visualization/plotter.py @@ -1,3 +1,4 @@ +import typing from itertools import cycle import numpy as np @@ -10,7 +11,7 @@ class Plotter: - source_map = {} + source_map: typing.ClassVar = {} @property def hex_colors(self): diff --git a/happypose/pose_estimators/cosypose/cosypose/visualization/singleview.py b/happypose/pose_estimators/cosypose/cosypose/visualization/singleview.py index e651489b..263dd323 100644 --- a/happypose/pose_estimators/cosypose/cosypose/visualization/singleview.py +++ b/happypose/pose_estimators/cosypose/cosypose/visualization/singleview.py @@ -3,7 +3,7 @@ from happypose.pose_estimators.cosypose.cosypose.datasets.augmentations import ( CropResizeToAspectAugmentation, ) -from happypose.pose_estimators.cosypose.cosypose.datasets.wrappers.augmentation_wrapper import ( # noqa: E501 +from happypose.pose_estimators.cosypose.cosypose.datasets.wrappers.augmentation_wrapper import ( AugmentationWrapper, ) diff --git a/happypose/pose_estimators/megapose/evaluation/eval_config.py b/happypose/pose_estimators/megapose/evaluation/eval_config.py index 5e65d1a0..598eb921 100644 --- a/happypose/pose_estimators/megapose/evaluation/eval_config.py +++ b/happypose/pose_estimators/megapose/evaluation/eval_config.py @@ -59,7 +59,7 @@ class EvalConfig: ds_name: str = "ycbv.bop19" # Inference - inference: InferenceConfig = InferenceConfig() + inference: InferenceConfig = InferenceConfig() # noqa RUF009 # Run management result_id: Optional[str] = None @@ -75,7 +75,7 @@ class EvalConfig: # Infos global_batch_size: Optional[int] = None - hardware: HardwareConfig = HardwareConfig() + hardware: HardwareConfig = HardwareConfig() # noqa RUF009 # Debug debug: bool = False diff --git a/happypose/pose_estimators/megapose/scripts/make_shapenet_statistics.py b/happypose/pose_estimators/megapose/scripts/make_shapenet_statistics.py index 56d94054..210526f2 100644 --- a/happypose/pose_estimators/megapose/scripts/make_shapenet_statistics.py +++ b/happypose/pose_estimators/megapose/scripts/make_shapenet_statistics.py @@ -45,17 +45,17 @@ def measure_memory(gltf_path): if "GeomVertexData arrays occupy" in line: print(line) l_ = line.split(" ") - idx = [n for n, w in enumerate(l_) if w == "occupy"][0] + idx = next(n for n, w in enumerate(l_) if w == "occupy") mems.append(float(l_[idx + 1])) elif "GeomPrimitive arrays occupy" in line: print(line) l_ = line.split(" ") - idx = [n for n, w in enumerate(l_) if w == "occupy"][0] + idx = next(n for n, w in enumerate(l_) if w == "occupy") mems.append(float(l_[idx + 1])) elif "texture memory required" in line: print(line) l_ = line.split(" ") - idx = [n for n, w in enumerate(l_) if w == "minimum"][0] + idx = next(n for n, w in enumerate(l_) if w == "minimum") mems.append(float(l_[idx + 1])) tot_mem_kb = sum(mems) stats = { diff --git a/happypose/pose_estimators/megapose/training/training_config.py b/happypose/pose_estimators/megapose/training/training_config.py index 563485a8..206b6af3 100644 --- a/happypose/pose_estimators/megapose/training/training_config.py +++ b/happypose/pose_estimators/megapose/training/training_config.py @@ -142,4 +142,4 @@ class TrainingConfig(omegaconf.dictconfig.DictConfig): # Infos global_batch_size: Optional[int] = None - hardware: HardwareConfig = HardwareConfig() + hardware: HardwareConfig = HardwareConfig() # noqa: RUF009 diff --git a/happypose/toolbox/datasets/bop_scene_dataset.py b/happypose/toolbox/datasets/bop_scene_dataset.py index d1a9c0af..5bd592c5 100644 --- a/happypose/toolbox/datasets/bop_scene_dataset.py +++ b/happypose/toolbox/datasets/bop_scene_dataset.py @@ -41,7 +41,7 @@ sys.path.append(str(BOP_TOOLKIT_DIR)) # Third Party -from bop_toolkit_lib import inout # noqa +from bop_toolkit_lib import inout sys.path = sys.path[:-1] diff --git a/happypose/toolbox/datasets/datasets_cfg.py b/happypose/toolbox/datasets/datasets_cfg.py index 756f182f..605bc992 100644 --- a/happypose/toolbox/datasets/datasets_cfg.py +++ b/happypose/toolbox/datasets/datasets_cfg.py @@ -223,7 +223,7 @@ def make_scene_dataset( # Synthetic datasets elif "synthetic." in ds_name: - from happypose.pose_estimators.cosypose.cosypose.datasets.synthetic_dataset import ( # noqa: E501 + from happypose.pose_estimators.cosypose.cosypose.datasets.synthetic_dataset import ( SyntheticSceneDataset, ) diff --git a/happypose/toolbox/datasets/pose_dataset.py b/happypose/toolbox/datasets/pose_dataset.py index 1562b850..e12edef8 100644 --- a/happypose/toolbox/datasets/pose_dataset.py +++ b/happypose/toolbox/datasets/pose_dataset.py @@ -16,6 +16,7 @@ # Standard Library import random import time +import typing from dataclasses import dataclass from typing import List, Optional, Set, Union @@ -40,11 +41,11 @@ PillowColor, PillowContrast, PillowSharpness, + VOCBackgroundAugmentation, ) from happypose.toolbox.datasets.augmentations import ( SceneObservationAugmentation as SceneObsAug, ) -from happypose.toolbox.datasets.augmentations import VOCBackgroundAugmentation # HappyPose from happypose.toolbox.datasets.scene_dataset import ( @@ -105,8 +106,8 @@ class NoObjectError(Exception): class PoseDataset(torch.utils.data.IterableDataset): - RGB_DIMS = [0, 1, 2] - DEPTH_DIMS = [3] + RGB_DIMS: typing.ClassVar = [0, 1, 2] + DEPTH_DIMS: typing.ClassVar = [3] def __init__( self, @@ -238,7 +239,7 @@ def collate_fn(self, list_data: List[PoseData]) -> BatchPoseData: has_depth = [d.depth is not None for d in list_data] if all(has_depth): - batch_data.depths = torch.from_numpy(np.stack([d.depth for d in list_data])) # type: ignore # noqa + batch_data.depths = torch.from_numpy(np.stack([d.depth for d in list_data])) # type: ignore return batch_data def make_data_from_obs(self, obs: SceneObservation) -> Union[PoseData, None]: diff --git a/happypose/toolbox/renderer/types.py b/happypose/toolbox/renderer/types.py index 72d389ba..abae1b4a 100644 --- a/happypose/toolbox/renderer/types.py +++ b/happypose/toolbox/renderer/types.py @@ -92,7 +92,7 @@ class CameraRenderingData: class Panda3dCameraData: K: np.ndarray resolution: Tuple[int, int] - TWC: Transform = Transform((0.0, 0.0, 0.0, 1.0), (0.0, 0.0, 0.0)) + TWC: Transform = Transform((0.0, 0.0, 0.0, 1.0), (0.0, 0.0, 0.0)) # noqa: RUF009 z_near: float = 0.1 z_far: float = 10 node_name: str = "camera" @@ -153,7 +153,7 @@ class Panda3dLightData: @dataclass class Panda3dObjectData: label: str - TWO: Transform = Transform((0.0, 0.0, 0.0, 1.0), (0.0, 0.0, 0.0)) + TWO: Transform = Transform((0.0, 0.0, 0.0, 1.0), (0.0, 0.0, 0.0)) # noqa: RUF009 color: Optional[RgbaColor] = None material: Optional[p3d.core.Material] = None remove_mesh_material: bool = False diff --git a/happypose/toolbox/utils/tensor_collection.py b/happypose/toolbox/utils/tensor_collection.py index bf6120d4..21fa1635 100644 --- a/happypose/toolbox/utils/tensor_collection.py +++ b/happypose/toolbox/utils/tensor_collection.py @@ -81,7 +81,7 @@ def tensors(self): @property def device(self): - return list(self.tensors.values())[0].device + return next(iter(self.tensors.values())).device def __getstate__(self): return {"tensors": self.tensors} diff --git a/pyproject.toml b/pyproject.toml index e8497945..2b884d90 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -102,9 +102,12 @@ priority = "primary" changelog = "https://github.com/agimus-project/happypose/blob/main/CHANGELOG.md" [tool.ruff] +extend-exclude = ["deps"] +target-version = "py38" + +[tool.ruff.lint] extend-ignore = ["D203", "D213"] -# extend-select = ["A", "B", "C", "COM", "D", "EM", "EXE", "G", "N", "PTH", "RET", "RUF", "UP", "W", "YTT"] -target-version = "py39" +extend-select = ["I", "RUF", "W"] [tool.tomlsort] all = true