Skip to content

Commit

Permalink
Merge branch 'main' into jennuine/ostream_precision
Browse files Browse the repository at this point in the history
Signed-off-by: Jenn Nguyen <[email protected]>
  • Loading branch information
jennuine committed Apr 12, 2022
2 parents f822dfd + 66c1609 commit c1067ba
Show file tree
Hide file tree
Showing 19 changed files with 926 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/ci/packages.apt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ liburdfdom-dev
libxml2-utils
python3-dev
python3-distutils
python3-ignition-math7
python3-psutil
python3-pybind11
ruby-dev
4 changes: 3 additions & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ jobs:
- run: mkdir build
- name: cmake
working-directory: build
run: cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/${PACKAGE}/HEAD
run: |
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/${PACKAGE}/HEAD
- run: make
working-directory: build
- run: make test
Expand Down
19 changes: 18 additions & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ endfunction()

pybind11_add_module(sdformat SHARED
src/sdf/_ignition_sdformat_pybind11.cc
src/sdf/pyBox.cc
src/sdf/pyError.cc
src/sdf/pyMesh.cc
src/sdf/pyParserConfig.cc
src/sdf/pySphere.cc
)

target_link_libraries(sdformat PRIVATE
Expand All @@ -48,15 +52,28 @@ target_link_libraries(sdformat PRIVATE
configure_build_install_location(sdformat)

if (BUILD_TESTING)
pybind11_add_module(sdformattest SHARED
test/_ignition_sdformattest_pybind11.cc
)

target_link_libraries(sdformattest PRIVATE
${PROJECT_LIBRARY_TARGET_NAME}
ignition-utils${IGN_UTILS_VER}::ignition-utils${IGN_UTILS_VER}
)

set(python_tests
pyBox_TEST
pyError_TEST
pyMesh_TEST
pyParserConfig_TEST
pySphere_TEST
)

foreach (test ${python_tests})
add_test(NAME ${test}.py COMMAND
"${Python3_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/python/test/${test}.py")
set(_env_vars)
list(APPEND _env_vars "PYTHONPATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/python/:${CMAKE_BINARY_DIR}/lib")
list(APPEND _env_vars "PYTHONPATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/python/:${CMAKE_BINARY_DIR}/lib:$ENV{PYTHONPATH}")
list(APPEND _env_vars "LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}:$ENV{LD_LIBRARY_PATH}")
set_tests_properties(${test}.py PROPERTIES
ENVIRONMENT "${_env_vars}")
Expand Down
8 changes: 8 additions & 0 deletions python/src/sdf/_ignition_sdformat_pybind11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@

#include <pybind11/pybind11.h>

#include "pyBox.hh"
#include "pyError.hh"
#include "pyMesh.hh"
#include "pyParserConfig.hh"
#include "pySphere.hh"

PYBIND11_MODULE(sdformat, m) {
m.doc() = "sdformat Python Library.";

sdf::python::defineBox(m);
sdf::python::defineError(m);
sdf::python::defineMesh(m);
sdf::python::defineParserConfig(m);
sdf::python::defineSphere(m);
}
54 changes: 54 additions & 0 deletions python/src/sdf/pyBox.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "pyBox.hh"

#include <pybind11/pybind11.h>

#include "sdf/Box.hh"

using namespace pybind11::literals;

namespace sdf
{
// Inline bracket to help doxygen filtering.
inline namespace SDF_VERSION_NAMESPACE {
namespace python
{
/////////////////////////////////////////////////
void defineBox(pybind11::object module)
{
pybind11::class_<sdf::Box>(module, "Box")
.def(pybind11::init<>())
.def(pybind11::init<sdf::Box>())
.def("size", &sdf::Box::Size,
"Get the box size in meters.")
.def("set_size", &sdf::Box::SetSize,
"Set the box size in meters.")
.def(
"shape",
pybind11::overload_cast<>(&sdf::Box::Shape, pybind11::const_),
pybind11::return_value_policy::reference,
"Get a mutable Ignition Math representation of this Box.")
.def("__copy__", [](const sdf::Box &self) {
return sdf::Box(self);
})
.def("__deepcopy__", [](const sdf::Box &self, pybind11::dict) {
return sdf::Box(self);
}, "memo"_a);
}
} // namespace python
} // namespace SDF_VERSION_NAMESPACE
} // namespace sdf
41 changes: 41 additions & 0 deletions python/src/sdf/pyBox.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef SDFORMAT_PYTHON_BOX_HH_
#define SDFORMAT_PYTHON_BOX_HH_

#include <pybind11/pybind11.h>

#include "sdf/Box.hh"

#include "sdf/config.hh"

namespace sdf
{
// Inline bracket to help doxygen filtering.
inline namespace SDF_VERSION_NAMESPACE {
namespace python
{
/// Define a pybind11 wrapper for an sdf::Box
/**
* \param[in] module a pybind11 module to add the definition to
*/
void defineBox(pybind11::object module);
} // namespace python
} // namespace SDF_VERSION_NAMESPACE
} // namespace sdf

#endif // SDFORMAT_PYTHON_BOX_HH_
13 changes: 11 additions & 2 deletions python/src/sdf/pyError.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include "sdf/Error.hh"

using namespace pybind11::literals;

namespace sdf
{
// Inline bracket to help doxygen filtering.
Expand Down Expand Up @@ -77,9 +79,16 @@ void defineError(pybind11::object module)
{
return self == true;
},
"Sets the XML path that is associated with this error.")
"True if this Error's Code() != NONE. In otherwords, this is "
"true when there is an error, or false otherwise.")
.def("__str__", toString)
.def("__repr__", toString);
.def("__repr__", toString)
.def("__copy__", [](const sdf::Error &self) {
return sdf::Error(self);
})
.def("__deepcopy__", [](const sdf::Error &self, pybind11::dict) {
return sdf::Error(self);
}, "memo"_a);

pybind11::enum_<sdf::ErrorCode>(errorModule, "ErrorCode")
.value("NONE", sdf::ErrorCode::NONE)
Expand Down
73 changes: 73 additions & 0 deletions python/src/sdf/pyMesh.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "pyMesh.hh"

#include <pybind11/pybind11.h>

#include "sdf/ParserConfig.hh"
#include "sdf/Mesh.hh"

using namespace pybind11::literals;

namespace sdf
{
// Inline bracket to help doxygen filtering.
inline namespace SDF_VERSION_NAMESPACE {
namespace python
{
/////////////////////////////////////////////////
void defineMesh(pybind11::object module)
{
pybind11::class_<sdf::Mesh>(module, "Mesh")
.def(pybind11::init<>())
.def(pybind11::init<sdf::Mesh>())
.def("uri", &sdf::Mesh::Uri,
"Get the mesh's URI.")
.def("set_uri", &sdf::Mesh::SetUri,
"Set the mesh's URI.")
.def("file_path", &sdf::Mesh::FilePath,
"The path to the file where this element was loaded from.")
.def("set_file_path", &sdf::Mesh::SetFilePath,
"Set the path to the file where this element was loaded from.")
.def("scale", &sdf::Mesh::Scale,
"Get the mesh's scale factor.")
.def("set_scale", &sdf::Mesh::SetScale,
"Set the mesh's scale factor.")
.def("submesh", &sdf::Mesh::Submesh,
"A submesh, contained with the mesh at the specified URI, may "
"optionally be specified. If specified, this submesh should be used "
"instead of the entire mesh.")
.def("set_submesh", &sdf::Mesh::SetSubmesh,
"Set the mesh's submesh. See Submesh() for more information.")
.def("center_submesh", &sdf::Mesh::CenterSubmesh,
"Get whether the submesh should be centered at 0,0,0. This will "
"effectively remove any transformations on the submesh before the "
"poses from parent links and models are applied. The return value is "
"only applicable if a SubMesh has been specified.")
.def("set_center_submesh", &sdf::Mesh::SetCenterSubmesh,
"Set whether the submesh should be centered. See CenterSubmesh() "
"for more information.")
.def("__copy__", [](const sdf::Mesh &self) {
return sdf::Mesh(self);
})
.def("__deepcopy__", [](const sdf::Mesh &self, pybind11::dict) {
return sdf::Mesh(self);
}, "memo"_a);
}
} // namespace python
} // namespace SDF_VERSION_NAMESPACE
} // namespace sdf
41 changes: 41 additions & 0 deletions python/src/sdf/pyMesh.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef SDFORMAT_PYTHON_MESH_HH_
#define SDFORMAT_PYTHON_MESH_HH_

#include <pybind11/pybind11.h>

#include "sdf/Mesh.hh"

#include "sdf/config.hh"

namespace sdf
{
// Inline bracket to help doxygen filtering.
inline namespace SDF_VERSION_NAMESPACE {
namespace python
{
/// Define a pybind11 wrapper for an sdf::Mesh
/**
* \param[in] module a pybind11 module to add the definition to
*/
void defineMesh(pybind11::object module);
} // namespace python
} // namespace SDF_VERSION_NAMESPACE
} // namespace sdf

#endif // SDFORMAT_PYTHON_MESH_HH_
Loading

0 comments on commit c1067ba

Please sign in to comment.