From e635c69c72fc2aeb4ccf95f6cfe75cd5bdab27a4 Mon Sep 17 00:00:00 2001 From: Justin Carpentier Date: Tue, 7 Jan 2025 10:36:53 +0100 Subject: [PATCH] pre-commit: fix missing parts --- bindings/python/pinocchio/shortcuts.py | 16 ++++----- bindings/python/pinocchio/utils.py | 14 ++++---- .../pinocchio/visualize/meshcat_visualizer.py | 36 +++++++++---------- 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/bindings/python/pinocchio/shortcuts.py b/bindings/python/pinocchio/shortcuts.py index 8d01baec0d..9858bc7695 100644 --- a/bindings/python/pinocchio/shortcuts.py +++ b/bindings/python/pinocchio/shortcuts.py @@ -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 @@ -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 @@ -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") @@ -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] @@ -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 @@ -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") @@ -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") diff --git a/bindings/python/pinocchio/utils.py b/bindings/python/pinocchio/utils.py index 2401d142f1..ffcd812476 100644 --- a/bindings/python/pinocchio/utils.py +++ b/bindings/python/pinocchio/utils.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2015-2022 CNRS INRIA +# Copyright (c) 2015-2024 CNRS INRIA # @@ -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", ] diff --git a/bindings/python/pinocchio/visualize/meshcat_visualizer.py b/bindings/python/pinocchio/visualize/meshcat_visualizer.py index c41997a767..da917be2c9 100644 --- a/bindings/python/pinocchio/visualize/meshcat_visualizer.py +++ b/bindings/python/pinocchio/visualize/meshcat_visualizer.py @@ -1,6 +1,6 @@ import warnings from pathlib import Path -from typing import ClassVar, List +from typing import ClassVar, list import numpy as np @@ -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 @@ -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 @@ -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" ) @@ -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 @@ -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`. """ @@ -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 @@ -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]) @@ -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: @@ -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 @@ -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: @@ -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: @@ -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) @@ -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