Skip to content

Commit

Permalink
Merge pull request #135 from nim65s/lints
Browse files Browse the repository at this point in the history
extend ruff config
  • Loading branch information
nim65s authored Feb 19, 2024
2 parents 0d0dfd3 + 688ae4c commit 06cfd35
Show file tree
Hide file tree
Showing 25 changed files with 1,052 additions and 963 deletions.
11 changes: 2 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
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
rev: v0.2.2
hooks:
- id: ruff
args:
- --fix
- --exit-non-zero-on-fix
- id: ruff-format
- repo: https://github.com/pappasam/toml-sort
rev: v0.23.1
hooks:
Expand All @@ -33,7 +30,3 @@ repos:
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 24.2.0
hooks:
- id: black
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down
1 change: 1 addition & 0 deletions experiments/job-runner/job_runner/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import List

import submitit

from job_runner.configs import JobEnvironmentConfig, RunnerConfig


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,10 @@ def add(self, pred_data, gt_data):
errors_TCO_xyz = errors["TCO_xyz"].cpu().numpy()[matches["cand_id"].values]
errors_TCO_norm = errors["TCO_norm"].cpu().numpy()[matches["cand_id"].values]

matches["obj_diameter"] = "match_id", [
self.mesh_db.infos[k.item()]["diameter_m"] for k in matches["label"]
]
matches["obj_diameter"] = (
"match_id",
[self.mesh_db.infos[k.item()]["diameter_m"] for k in matches["label"]],
)
matches["norm"] = "match_id", errors_norm
matches["0.1d"] = "match_id", errors_norm < 0.1 * matches["obj_diameter"]
matches["xyz"] = ("match_id", "dim3"), errors_xyz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import typing
from itertools import cycle

import numpy as np
Expand All @@ -10,7 +11,7 @@


class Plotter:
source_map = {}
source_map: typing.ClassVar = {}

@property
def hex_colors(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
4 changes: 2 additions & 2 deletions happypose/pose_estimators/megapose/evaluation/eval_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,4 @@ class TrainingConfig(omegaconf.dictconfig.DictConfig):

# Infos
global_batch_size: Optional[int] = None
hardware: HardwareConfig = HardwareConfig()
hardware: HardwareConfig = HardwareConfig() # noqa: RUF009
2 changes: 1 addition & 1 deletion happypose/toolbox/datasets/bop_scene_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion happypose/toolbox/datasets/datasets_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down
9 changes: 5 additions & 4 deletions happypose/toolbox/datasets/pose_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# Standard Library
import random
import time
import typing
from dataclasses import dataclass
from typing import List, Optional, Set, Union

Expand All @@ -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 (
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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]:
Expand Down
4 changes: 2 additions & 2 deletions happypose/toolbox/renderer/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion happypose/toolbox/utils/tensor_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Loading

0 comments on commit 06cfd35

Please sign in to comment.