Skip to content

Commit

Permalink
pre-commit: fix missing parts
Browse files Browse the repository at this point in the history
  • Loading branch information
jcarpent committed Jan 7, 2025
1 parent d4fdd44 commit e635c69
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
16 changes: 7 additions & 9 deletions bindings/python/pinocchio/shortcuts.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# ruff: noqa: E501
#
# Copyright (c) 2018-2020 CNRS INRIA
# Copyright (c) 2018-2024 CNRS INRIA
#

## In this file, some shortcuts are provided ##

from typing import Tuple

from . import WITH_HPP_FCL, WITH_HPP_FCL_BINDINGS
from . import pinocchio_pywrap_default as pin

Expand All @@ -15,7 +13,7 @@

def buildModelsFromUrdf(
filename, *args, **kwargs
) -> Tuple[pin.Model, pin.GeometryModel, pin.GeometryModel]:
) -> tuple[pin.Model, pin.GeometryModel, pin.GeometryModel]:
"""Parse the URDF file given in input and return a Pinocchio Model followed by corresponding GeometryModels of types specified by geometry_types, in the same order as listed.
Arguments:
- filename - name of the urdf file to load
Expand All @@ -26,7 +24,7 @@ def buildModelsFromUrdf(
- meshLoader - object used to load meshes (default - hpp::fcl::MeshLoader)
- geometry_types - Which geometry model to load. Can be pin.GeometryType.COLLISION, pin.GeometryType.VISUAL or both. (default - [pin.GeometryType.COLLISION, pin.GeometryType.VISUAL])
Return:
Tuple of the models, in this order : model, collision model, and visual model.
tuple of the models, in this order : model, collision model, and visual model.
Example:
model, collision_model, visual_model = buildModelsFromUrdf(filename, root_joint, verbose, meshLoader, geometry_types, root_joint_name="root_joint_name")
Expand Down Expand Up @@ -63,7 +61,7 @@ def _buildModelsFromUrdf(
verbose=False,
meshLoader=None,
geometry_types=None,
) -> Tuple[pin.Model, pin.GeometryModel, pin.GeometryModel]:
) -> tuple[pin.Model, pin.GeometryModel, pin.GeometryModel]:
if geometry_types is None:
geometry_types = [pin.GeometryType.COLLISION, pin.GeometryType.VISUAL]

Expand Down Expand Up @@ -119,7 +117,7 @@ def createDatas(*models):

def buildModelsFromSdf(
filename, *args, **kwargs
) -> Tuple[pin.Model, pin.GeometryModel, pin.GeometryModel]:
) -> tuple[pin.Model, pin.GeometryModel, pin.GeometryModel]:
"""Parse the Sdf file given in input and return a Pinocchio Model and a list of Constraint Models, followed by corresponding GeometryModels of types specified by geometry_types, in the same order as listed.
Arguments:
- filename - name of the urdf file to load
Expand All @@ -132,7 +130,7 @@ def buildModelsFromSdf(
- meshLoader - object used to load meshes (default - hpp::fcl::MeshLoader)
- geometry_types - Which geometry model to load. Can be pin.GeometryType.COLLISION, pin.GeometryType.VISUAL, both or None. (default - None])
Return:
Tuple of the models, in this order : model, collision model, and visual model.
tuple of the models, in this order : model, collision model, and visual model.
Example:
model, collision_model, visual_model = buildModelsFromSdf(filename, root_joint, root_link_name, parent_guidance, verbose, meshLoader, geometry_types, root_joint_name="root_joint_name")
Expand Down Expand Up @@ -241,7 +239,7 @@ def buildModelsFromMJCF(filename, *args, **kwargs):
- geometry_types - Which geometry model to load. Can be pin.GeometryType.COLLISION, pin.GeometryType.VISUAL or both. (default - [pin.GeometryType.COLLISION, pin.GeometryType.VISUAL])
- contacts - Boolean to know if contraint models are wanted (default - False)
Return:
Tuple of the models, in this order : model, collision model, and visual model, or model, constraint_list, collision model, and visual model, if contacts is True.
tuple of the models, in this order : model, collision model, and visual model, or model, constraint_list, collision model, and visual model, if contacts is True.
Example:
model, collision_model, visual_model = buildModelsFromMJCF(filename, root_joint, verbose, meshLoader, geometry_types, root_joint_name="root_joint_name")
Expand Down
14 changes: 7 additions & 7 deletions bindings/python/pinocchio/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2015-2022 CNRS INRIA
# Copyright (c) 2015-2024 CNRS INRIA
#


Expand Down Expand Up @@ -96,17 +96,17 @@ def fromListToVectorOfString(items):


__all__ = [
"np",
"npl",
"eye",
"zero",
"rand",
"fromListToVectorOfString",
"isapprox",
"matrixToRpy",
"mprint",
"np",
"npToTTuple",
"npToTuple",
"npl",
"rand",
"rotate",
"rpyToMatrix",
"matrixToRpy",
"fromListToVectorOfString",
"zero",
]
36 changes: 18 additions & 18 deletions bindings/python/pinocchio/visualize/meshcat_visualizer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import warnings
from pathlib import Path
from typing import ClassVar, List
from typing import ClassVar, list

import numpy as np

Expand All @@ -21,9 +21,9 @@

# DaeMeshGeometry
import xml.etree.ElementTree as Et
from typing import Any, Dict, Optional, Set, Union
from typing import Any, Optional, Union

MsgType = Dict[str, Union[str, bytes, bool, float, "MsgType"]]
MsgType = dict[str, Union[str, bytes, bool, float, "MsgType"]]

try:
import hppfcl
Expand Down Expand Up @@ -110,7 +110,7 @@ def lower(self, object_data: Any) -> MsgType:
}

class DaeMeshGeometry(mg.ReferenceSceneElement):
def __init__(self, dae_path: str, cache: Optional[Set[str]] = None) -> None:
def __init__(self, dae_path: str, cache: Optional[set[str]] = None) -> None:
"""Load Collada files with texture images.
Inspired from
https://gist.github.com/danzimmerman/a392f8eadcf1166eb5bd80e3922dbdc5
Expand All @@ -131,7 +131,7 @@ def __init__(self, dae_path: str, cache: Optional[Set[str]] = None) -> None:
self.dae_raw = text_file.read()

# Parse the image resource in Collada file
img_resource_paths: List[Path] = []
img_resource_paths: list[Path] = []
img_lib_element = Et.parse(dae_path).find(
"{http://www.collada.org/2005/11/COLLADASchema}library_images"
)
Expand All @@ -143,7 +143,7 @@ def __init__(self, dae_path: str, cache: Optional[Set[str]] = None) -> None:
]

# Convert textures to data URL for Three.js ColladaLoader to load them
self.img_resources: Dict[str, str] = {}
self.img_resources: dict[str, str] = {}
for img_path in img_resource_paths:
img_key = str(img_path)
# Return empty string if already in cache
Expand All @@ -164,7 +164,7 @@ def __init__(self, dae_path: str, cache: Optional[Set[str]] = None) -> None:
img_uri = f"data:image/png;base64,{img_data.decode('utf-8')}"
self.img_resources[img_key] = img_uri

def lower(self) -> Dict[str, Any]:
def lower(self) -> dict[str, Any]:
"""Pack data into a dictionary of the format that must be passed to
`Visualizer.window.send`.
"""
Expand Down Expand Up @@ -665,7 +665,7 @@ def reset(self):
self.static_objects = []

def setBackgroundColor(self, preset_name: str = "gray", col_top=None, col_bot=None):
"""Set the background."""
"""set the background."""
if col_top is not None:
if col_bot is None:
col_bot = col_top
Expand All @@ -682,7 +682,7 @@ def setCameraPosition(self, position: np.ndarray):
self.viewer.set_cam_pos(position)

def setCameraPreset(self, preset_key: str):
"""Set the camera angle and position using a given preset."""
"""set the camera angle and position using a given preset."""
assert preset_key in self.CAMERA_PRESETS
cam_val = self.CAMERA_PRESETS[preset_key]
self.setCameraTarget(cam_val[0])
Expand Down Expand Up @@ -846,7 +846,7 @@ def loadViewerGeometryObject(self, geometry_object, geometry_type, color=None):
meshcat_node.set_object(obj)
elif isinstance(obj, (mg.Geometry, mg.ReferenceSceneElement)):
material = mg.MeshPhongMaterial()
# Set material color from URDF, converting for triplet of doubles to a
# set material color from URDF, converting for triplet of doubles to a
# single int.

def to_material_color(rgba) -> int:
Expand Down Expand Up @@ -915,7 +915,7 @@ def loadViewerModel(
collision_color = color
visual_color = color

# Set viewer to use to gepetto-gui.
# set viewer to use to gepetto-gui.
self.viewerRootNodeName = rootNodeName

# Collisions
Expand Down Expand Up @@ -1038,7 +1038,7 @@ def captureImage(self, w=None, h=None):
return img_arr

def displayCollisions(self, visibility):
"""Set whether to display collision objects or not."""
"""set whether to display collision objects or not."""
if self.collision_model is None:
self.display_collisions = False
else:
Expand All @@ -1049,7 +1049,7 @@ def displayCollisions(self, visibility):
self.updatePlacements(pin.GeometryType.COLLISION)

def displayVisuals(self, visibility):
"""Set whether to display visual objects or not."""
"""set whether to display visual objects or not."""
if self.visual_model is None:
self.display_visuals = False
else:
Expand All @@ -1060,7 +1060,7 @@ def displayVisuals(self, visibility):
self.updatePlacements(pin.GeometryType.VISUAL)

def displayFrames(self, visibility, frame_ids=None, axis_length=0.2, axis_width=2):
"""Set whether to display frames or not."""
"""set whether to display frames or not."""
self.display_frames = visibility
if visibility:
self.initializeFrames(frame_ids, axis_length, axis_width)
Expand Down Expand Up @@ -1112,10 +1112,10 @@ def drawFrameVelocities(self, frame_id: int, v_scale=0.2, color=FRAME_VEL_COLOR)

def _draw_vectors_from_frame(
self,
vecs: List[np.ndarray],
frame_ids: List[int],
vec_names: List[str],
colors: List[int],
vecs: list[np.ndarray],
frame_ids: list[int],
vec_names: list[str],
colors: list[int],
):
"""Draw vectors extending from given frames."""
import meshcat.geometry as mg
Expand Down

0 comments on commit e635c69

Please sign in to comment.