-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python: Added basic structure (#932)
Signed-off-by: ahcorde <[email protected]>
- Loading branch information
Showing
6 changed files
with
156 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# sdformat Python API | ||
|
||
This example shows how to use sdformat's Python API. | ||
|
||
In the | ||
[examples/python](https://github.com/ignitionrobotics/sdformat/blob/main/examples/python) | ||
folder there is a Python script that shows how to make use of this API. | ||
|
||
> If you compiled sdformat from source you should modify your `PYTHONPATH`: | ||
> | ||
> ```bash | ||
> export PYTHONPATH=$PYTHONPATH:<path to ws>/install/lib/python | ||
> ``` | ||
Now you can run the example: | ||
```bash | ||
$ python3 python_sdformat.py | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# 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. | ||
|
||
import sdformat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug") | ||
# pybind11 logic for setting up a debug build when both a debug and release | ||
# python interpreter are present in the system seems to be pretty much broken. | ||
# This works around the issue. | ||
set(PYTHON_LIBRARIES "${PYTHON_DEBUG_LIBRARIES}") | ||
endif() | ||
|
||
|
||
if(USE_SYSTEM_PATHS_FOR_PYTHON_INSTALLATION) | ||
if(${CMAKE_VERSION} VERSION_LESS "3.12.0") | ||
execute_process( | ||
COMMAND "${PYTHON_EXECUTABLE}" -c "if True: | ||
from distutils import sysconfig as sc | ||
print(sc.get_python_lib(plat_specific=True))" | ||
OUTPUT_VARIABLE Python3_SITEARCH | ||
OUTPUT_STRIP_TRAILING_WHITESPACE) | ||
else() | ||
# Get install variable from Python3 module | ||
# Python3_SITEARCH is available from 3.12 on, workaround if needed: | ||
find_package(Python3 COMPONENTS Interpreter) | ||
endif() | ||
|
||
if(USE_DIST_PACKAGES_FOR_PYTHON) | ||
string(REPLACE "site-packages" "dist-packages" IGN_PYTHON_INSTALL_PATH ${Python3_SITEARCH}) | ||
endif() | ||
else() | ||
# If not a system installation, respect local paths | ||
set(IGN_PYTHON_INSTALL_PATH ${IGN_LIB_INSTALL_DIR}/python) | ||
endif() | ||
|
||
# Set the build location and install location for a CPython extension | ||
function(configure_build_install_location _library_name) | ||
# Install library for actual use | ||
install(TARGETS ${_library_name} | ||
DESTINATION "${IGN_PYTHON_INSTALL_PATH}" | ||
) | ||
endfunction() | ||
|
||
pybind11_add_module(sdformat SHARED | ||
src/sdf/_ignition_sdformat_pybind11.cc | ||
) | ||
|
||
target_link_libraries(sdformat PRIVATE | ||
${PROJECT_LIBRARY_TARGET_NAME} | ||
) | ||
|
||
configure_build_install_location(sdformat) | ||
|
||
if (BUILD_TESTING) | ||
set(python_tests | ||
) | ||
|
||
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/") | ||
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}") | ||
endforeach() | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* 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 <pybind11/pybind11.h> | ||
|
||
PYBIND11_MODULE(sdformat, m) { | ||
m.doc() = "sdformat Python Library."; | ||
} |