Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extend ruff config #135

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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"] = (

Check warning on line 265 in happypose/pose_estimators/cosypose/cosypose/evaluation/meters/pose_meters.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/evaluation/meters/pose_meters.py#L265

Added line #L265 was not covered by tests
"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 @@
self.bodies = self.body_cache.get_bodies_by_ids(ids)

def visuals_rand(self):
bodies = [self.background] + [self.plane]
bodies = [self.background, self.plane]

Check warning on line 123 in happypose/pose_estimators/cosypose/cosypose/recording/bop_recording_scene.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/recording/bop_recording_scene.py#L123

Added line #L123 was not covered by tests
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 (

Check warning on line 25 in happypose/pose_estimators/cosypose/cosypose/scripts/run_bop_inference.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/scripts/run_bop_inference.py#L25

Added line #L25 was not covered by tests
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 (

Check warning on line 28 in happypose/pose_estimators/cosypose/cosypose/scripts/run_bop_inference.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/scripts/run_bop_inference.py#L28

Added line #L28 was not covered by tests
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

Check warning on line 70 in happypose/pose_estimators/cosypose/cosypose/scripts/run_bop_inference.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/scripts/run_bop_inference.py#L70

Added line #L70 was not covered by tests

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 (

Check warning on line 12 in happypose/pose_estimators/cosypose/cosypose/scripts/run_colmap_reconstruction.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/scripts/run_colmap_reconstruction.py#L12

Added line #L12 was not covered by tests
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 (

Check warning on line 31 in happypose/pose_estimators/cosypose/cosypose/scripts/run_cosypose_eval.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/scripts/run_cosypose_eval.py#L31

Added line #L31 was not covered by tests
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 (

Check warning on line 34 in happypose/pose_estimators/cosypose/cosypose/scripts/run_cosypose_eval.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/scripts/run_cosypose_eval.py#L34

Added line #L34 was not covered by tests
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 (

Check warning on line 40 in happypose/pose_estimators/cosypose/cosypose/scripts/run_cosypose_eval.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/scripts/run_cosypose_eval.py#L40

Added line #L40 was not covered by tests
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

Check warning on line 68 in happypose/pose_estimators/cosypose/cosypose/scripts/run_cosypose_eval.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/scripts/run_cosypose_eval.py#L68

Added line #L68 was not covered by tests

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

Check warning on line 29 in happypose/pose_estimators/cosypose/cosypose/scripts/run_custom_scenario.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/scripts/run_custom_scenario.py#L29

Added line #L29 was not covered by tests

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 (

Check warning on line 17 in happypose/pose_estimators/cosypose/cosypose/scripts/run_detection_eval.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/scripts/run_detection_eval.py#L17

Added line #L17 was not covered by tests
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 (

Check warning on line 20 in happypose/pose_estimators/cosypose/cosypose/scripts/run_detection_eval.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/scripts/run_detection_eval.py#L20

Added line #L20 was not covered by tests
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 (

Check warning on line 23 in happypose/pose_estimators/cosypose/cosypose/scripts/run_detection_eval.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/scripts/run_detection_eval.py#L23

Added line #L23 was not covered by tests
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 @@

@property
def device(self):
return list(self.tensors.values())[0].device
return next(iter(self.tensors.values())).device

Check warning on line 68 in happypose/pose_estimators/cosypose/cosypose/utils/tensor_collection.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/utils/tensor_collection.py#L68

Added line #L68 was not covered by tests

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

Check warning on line 16 in happypose/pose_estimators/cosypose/cosypose/visualization/multiview.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/visualization/multiview.py#L16

Added line #L16 was not covered by tests

from .plotter import Plotter

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

Check warning on line 1 in happypose/pose_estimators/cosypose/cosypose/visualization/plotter.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/visualization/plotter.py#L1

Added line #L1 was not covered by tests
from itertools import cycle

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


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

Check warning on line 14 in happypose/pose_estimators/cosypose/cosypose/visualization/plotter.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/visualization/plotter.py#L14

Added line #L14 was not covered by tests

@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 (

Check warning on line 6 in happypose/pose_estimators/cosypose/cosypose/visualization/singleview.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/cosypose/cosypose/visualization/singleview.py#L6

Added line #L6 was not covered by tests
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 @@
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")

Check warning on line 48 in happypose/pose_estimators/megapose/scripts/make_shapenet_statistics.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/megapose/scripts/make_shapenet_statistics.py#L48

Added line #L48 was not covered by tests
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")

Check warning on line 53 in happypose/pose_estimators/megapose/scripts/make_shapenet_statistics.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/megapose/scripts/make_shapenet_statistics.py#L53

Added line #L53 was not covered by tests
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")

Check warning on line 58 in happypose/pose_estimators/megapose/scripts/make_shapenet_statistics.py

View check run for this annotation

Codecov / codecov/patch

happypose/pose_estimators/megapose/scripts/make_shapenet_statistics.py#L58

Added line #L58 was not covered by tests
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 @@

# 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 (

Check warning on line 226 in happypose/toolbox/datasets/datasets_cfg.py

View check run for this annotation

Codecov / codecov/patch

happypose/toolbox/datasets/datasets_cfg.py#L226

Added line #L226 was not covered by tests
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 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 @@

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

Check warning on line 242 in happypose/toolbox/datasets/pose_dataset.py

View check run for this annotation

Codecov / codecov/patch

happypose/toolbox/datasets/pose_dataset.py#L242

Added line #L242 was not covered by tests
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 @@

@property
def device(self):
return list(self.tensors.values())[0].device
return next(iter(self.tensors.values())).device

Check warning on line 84 in happypose/toolbox/utils/tensor_collection.py

View check run for this annotation

Codecov / codecov/patch

happypose/toolbox/utils/tensor_collection.py#L84

Added line #L84 was not covered by tests

def __getstate__(self):
return {"tensors": self.tensors}
Expand Down
Loading
Loading