From ad7c53a6c1544bf3abfed83bb9a1312244f30ae7 Mon Sep 17 00:00:00 2001 From: Will Stott Date: Wed, 7 Sep 2022 16:56:48 +0100 Subject: [PATCH 1/3] python: Don't import more than is used in the tests - should cause a failure due to gz.math not always being imported. Signed-off-by: Will Stott --- python/test/pyAirPressure_TEST.py | 1 - python/test/pyAltimeter_TEST.py | 1 - python/test/pyAtmosphere_TEST.py | 2 +- python/test/pyCapsule_TEST.py | 2 -- python/test/pyCylinder_TEST.py | 2 -- python/test/pyEllipsoid_TEST.py | 2 +- python/test/pyJointAxis_TEST.py | 2 +- python/test/pyLidar_TEST.py | 2 +- python/test/pyMagnetometer_TEST.py | 1 - python/test/pyModel_TEST.py | 2 +- python/test/pyPlane_TEST.py | 2 +- python/test/pyRoot_TEST.py | 2 +- python/test/pySphere_TEST.py | 1 - python/test/pyWorld_TEST.py | 2 +- 14 files changed, 8 insertions(+), 16 deletions(-) diff --git a/python/test/pyAirPressure_TEST.py b/python/test/pyAirPressure_TEST.py index 0b294ade5..11d65a072 100644 --- a/python/test/pyAirPressure_TEST.py +++ b/python/test/pyAirPressure_TEST.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from gz.math import Vector3d from sdformat import AirPressure, Noise import sdformat as sdf import unittest diff --git a/python/test/pyAltimeter_TEST.py b/python/test/pyAltimeter_TEST.py index ff9b9498c..491777a6a 100644 --- a/python/test/pyAltimeter_TEST.py +++ b/python/test/pyAltimeter_TEST.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from gz.math import Vector3d from sdformat import Altimeter, Noise import sdformat as sdf import unittest diff --git a/python/test/pyAtmosphere_TEST.py b/python/test/pyAtmosphere_TEST.py index e5162159b..42132c622 100644 --- a/python/test/pyAtmosphere_TEST.py +++ b/python/test/pyAtmosphere_TEST.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from gz.math import Pose3d, Temperature +from gz.math import Temperature from sdformat import Atmosphere import sdformat as sdf import unittest diff --git a/python/test/pyCapsule_TEST.py b/python/test/pyCapsule_TEST.py index 1e375dd6e..5bd5e54b7 100644 --- a/python/test/pyCapsule_TEST.py +++ b/python/test/pyCapsule_TEST.py @@ -14,8 +14,6 @@ import copy -from gz.math import Vector3d, Capsuled - import math from sdformat import Capsule diff --git a/python/test/pyCylinder_TEST.py b/python/test/pyCylinder_TEST.py index 7294abb54..ea88693c4 100644 --- a/python/test/pyCylinder_TEST.py +++ b/python/test/pyCylinder_TEST.py @@ -14,8 +14,6 @@ import copy -from gz.math import Vector3d - import math from sdformat import Cylinder diff --git a/python/test/pyEllipsoid_TEST.py b/python/test/pyEllipsoid_TEST.py index c77105f7d..33b855dbd 100644 --- a/python/test/pyEllipsoid_TEST.py +++ b/python/test/pyEllipsoid_TEST.py @@ -13,7 +13,7 @@ # limitations under the License. import copy -from gz.math import Vector3d, Ellipsoidd +from gz.math import Vector3d import math from sdformat import Ellipsoid import unittest diff --git a/python/test/pyJointAxis_TEST.py b/python/test/pyJointAxis_TEST.py index b5f68f34f..9263f9a80 100644 --- a/python/test/pyJointAxis_TEST.py +++ b/python/test/pyJointAxis_TEST.py @@ -13,7 +13,7 @@ # limitations under the License. import copy -from gz.math import Pose3d, Vector3d +from gz.math import Vector3d from sdformat import JointAxis, Error, SDFErrorsException import math import unittest diff --git a/python/test/pyLidar_TEST.py b/python/test/pyLidar_TEST.py index b9ea1b7bb..26137a77c 100644 --- a/python/test/pyLidar_TEST.py +++ b/python/test/pyLidar_TEST.py @@ -13,7 +13,7 @@ # limitations under the License. import copy -from gz.math import Angle, Pose3d, Vector3d, Helpers +from gz.math import Angle, Helpers from sdformat import Lidar, Error, Noise import math import unittest diff --git a/python/test/pyMagnetometer_TEST.py b/python/test/pyMagnetometer_TEST.py index 6a7597346..8b9efb377 100644 --- a/python/test/pyMagnetometer_TEST.py +++ b/python/test/pyMagnetometer_TEST.py @@ -13,7 +13,6 @@ # limitations under the License. import copy -from gz.math import Pose3d from sdformat import Magnetometer, Noise import sdformat as sdf import unittest diff --git a/python/test/pyModel_TEST.py b/python/test/pyModel_TEST.py index efb0aa303..20ae63e0b 100644 --- a/python/test/pyModel_TEST.py +++ b/python/test/pyModel_TEST.py @@ -13,7 +13,7 @@ # limitations under the License. import copy -from gz.math import Pose3d, Vector3d +from gz.math import Pose3d from sdformat import (Plugin, Model, Joint, Link, Error, Frame, SemanticPose, SDFErrorsException) import sdformat as sdf diff --git a/python/test/pyPlane_TEST.py b/python/test/pyPlane_TEST.py index bd0729f02..221626018 100644 --- a/python/test/pyPlane_TEST.py +++ b/python/test/pyPlane_TEST.py @@ -14,7 +14,7 @@ import copy from sdformat import Plane -from gz.math import Vector3d, Vector2d, Planed +from gz.math import Vector3d, Vector2d import unittest diff --git a/python/test/pyRoot_TEST.py b/python/test/pyRoot_TEST.py index 3bd90e9e1..475846aa1 100644 --- a/python/test/pyRoot_TEST.py +++ b/python/test/pyRoot_TEST.py @@ -13,7 +13,7 @@ # limitations under the License. import copy -from gz.math import Vector3d, Pose3d +from gz.math import Pose3d from sdformat import (Error, Model, Light, Root, SDF_VERSION, SDFErrorsException, SDF_PROTOCOL_VERSION, World) import sdformat as sdf diff --git a/python/test/pySphere_TEST.py b/python/test/pySphere_TEST.py index 370d574d5..f1a80221b 100644 --- a/python/test/pySphere_TEST.py +++ b/python/test/pySphere_TEST.py @@ -13,7 +13,6 @@ # limitations under the License. import copy -from gz.math import Sphered import math from sdformat import Sphere import unittest diff --git a/python/test/pyWorld_TEST.py b/python/test/pyWorld_TEST.py index 88d929ccd..c54a419d8 100644 --- a/python/test/pyWorld_TEST.py +++ b/python/test/pyWorld_TEST.py @@ -13,7 +13,7 @@ # limitations under the License. import copy -from gz.math import Color, Pose3d, Vector3d, SphericalCoordinates +from gz.math import Color, Vector3d, SphericalCoordinates from sdformat import Atmosphere, Gui, Physics, Plugin, Error, Frame, Light, Model, Scene, World import sdformat as sdf import unittest From 70597a1fcb79e1af93f56aee4bd172f5f63fd01b Mon Sep 17 00:00:00 2001 From: Will Stott Date: Wed, 7 Sep 2022 11:40:14 +0100 Subject: [PATCH 2/3] python: Import gz.math at startup to fix #1129 Signed-off-by: Will Stott --- python/src/sdf/_gz_sdformat_pybind11.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/src/sdf/_gz_sdformat_pybind11.cc b/python/src/sdf/_gz_sdformat_pybind11.cc index 294819cde..869e536c7 100644 --- a/python/src/sdf/_gz_sdformat_pybind11.cc +++ b/python/src/sdf/_gz_sdformat_pybind11.cc @@ -65,6 +65,10 @@ PYBIND11_MODULE(sdformat, m) { m.doc() = "sdformat Python Library."; + // Import the gz.math library to automatically add the type conversions + // this module requires to pass mathematical types to python code. + pybind11::module::import("gz.math"); + sdf::python::defineAirPressure(m); sdf::python::defineAltimeter(m); sdf::python::defineAtmosphere(m); From 874a8c74b944807b7caee6fff986a67281481cea Mon Sep 17 00:00:00 2001 From: "Addisu Z. Taddese" Date: Thu, 29 Sep 2022 21:22:07 -0500 Subject: [PATCH 3/3] Use versioned gz.math module Signed-off-by: Addisu Z. Taddese --- python/src/sdf/_gz_sdformat_pybind11.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/python/src/sdf/_gz_sdformat_pybind11.cc b/python/src/sdf/_gz_sdformat_pybind11.cc index 1a017dce0..0e64d1e8a 100644 --- a/python/src/sdf/_gz_sdformat_pybind11.cc +++ b/python/src/sdf/_gz_sdformat_pybind11.cc @@ -16,6 +16,7 @@ #include #include +#include #include "pyAirPressure.hh" #include "pyAltimeter.hh" @@ -67,7 +68,9 @@ PYBIND11_MODULE(BINDINGS_MODULE_NAME, m) { // Import the gz.math library to automatically add the type conversions // this module requires to pass mathematical types to python code. - pybind11::module::import("gz.math"); + std::string gzMathModule = + std::string("gz.math") + std::to_string(GZ_MATH_MAJOR_VERSION); + pybind11::module::import(gzMathModule.c_str()); sdf::python::defineAirPressure(m); sdf::python::defineAltimeter(m);