Reworked python directory structure. Added readme on constructing python module. Added first unit test for point2. Everything needed to get it passing is also here, including some renaming of variables and emitted library names

Conflicts:
	cmake/GtsamPythonWrap.cmake
	python/handwritten/examples/OdometeryExample.py
	wrap/Module.cpp
release/4.3a0
Andrew Melim 2014-12-17 10:44:56 -08:00 committed by Ellon Mendes
parent 4e00f70e82
commit 20f5c46507
19 changed files with 71 additions and 17 deletions

View File

@ -36,24 +36,46 @@ function(wrap_python TARGET_NAME PYTHON_MODULE_DIRECTORY)
ENDIF()
ENDIF(APPLE)
if(MSVC)
add_library(${moduleName}_python MODULE ${ARGN})
set_target_properties(${moduleName}_python PROPERTIES
OUTPUT_NAME ${moduleName}_python
CLEAN_DIRECT_OUTPUT 1
VERSION 1
SOVERSION 0
SUFFIX ".pyd")
target_link_libraries(${moduleName}_python ${Boost_PYTHON_LIBRARY} ${PYTHON_LIBRARY} ${gtsamLib}) #temp
# Create a static library version
add_library(${TARGET_NAME} SHARED ${ARGN})
set(PYLIB_OUTPUT_FILE $<TARGET_FILE:${moduleName}_python>)
message(${PYLIB_OUTPUT_FILE})
get_filename_component(PYLIB_OUTPUT_NAME ${PYLIB_OUTPUT_FILE} NAME_WE)
set(PYLIB_SO_NAME ${PYLIB_OUTPUT_NAME}.pyd)
target_link_libraries(${TARGET_NAME} ${Boost_PYTHON_LIBRARY} ${PYTHON_LIBRARY} gtsam-shared)
set_target_properties(${TARGET_NAME} PROPERTIES
OUTPUT_NAME ${TARGET_NAME}
CLEAN_DIRECT_OUTPUT 1
VERSION 1
SOVERSION 0)
ELSE()
# Create a shared library
add_library(${moduleName}_python SHARED ${generated_cpp_file})
set_target_properties(${moduleName}_python PROPERTIES
OUTPUT_NAME ${moduleName}_python
CLEAN_DIRECT_OUTPUT 1)
target_link_libraries(${moduleName}_python ${Boost_PYTHON_LIBRARY} ${PYTHON_LIBRARY} ${gtsamLib}) #temp
# On OSX and Linux, the python library must end in the extension .so. Build this
# filename here.
get_property(PYLIB_OUTPUT_FILE TARGET ${moduleName}_python PROPERTY LOCATION)
set(PYLIB_OUTPUT_FILE $<TARGET_FILE:${moduleName}_python>)
message(${PYLIB_OUTPUT_FILE})
get_filename_component(PYLIB_OUTPUT_NAME ${PYLIB_OUTPUT_FILE} NAME_WE)
set(PYLIB_SO_NAME lib${moduleName}_python.so)
ENDIF(MSVC)
# On OSX and Linux, the python library must end in the extension .so. Build this
# filename here.
#get_property(PYLIB_OUTPUT_FILE TARGET ${TARGET_NAME} PROPERTY LOCATION)
set(PYLIB_OUTPUT_FILE $<TARGET_FILE:${TARGET_NAME}>)
get_filename_component(PYLIB_OUTPUT_NAME ${PYLIB_OUTPUT_FILE} NAME_WE)
set(PYLIB_SO_NAME ${PYLIB_OUTPUT_NAME}.so)
# Installs the library in the gtsam folder, which is used by setup.py to create the gtsam package
set(PYTHON_MODULE_DIRECTORY ${CMAKE_SOURCE_DIR}/python/gtsam)
# Cause the library to be output in the correct directory.
add_custom_command(TARGET ${moduleName}_python
POST_BUILD
COMMAND cp -v ${PYLIB_OUTPUT_FILE} ${PYTHON_MODULE_DIRECTORY}/${PYLIB_SO_NAME}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMENT "Copying library files to python directory" )
# Cause the library to be output in the correct directory.
add_custom_command(TARGET ${TARGET_NAME}
@ -65,4 +87,4 @@ function(wrap_python TARGET_NAME PYTHON_MODULE_DIRECTORY)
get_directory_property(AMCF ADDITIONAL_MAKE_CLEAN_FILES)
list(APPEND AMCF ${PYTHON_MODULE_DIRECTORY}/${PYLIB_SO_NAME})
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${AMCF}")
endfunction(wrap_python)
endfunction(wrap_python)

12
python/README.txt Normal file
View File

@ -0,0 +1,12 @@
This directory contains the basic setup script and directory structure for the gtsam python module.
During the build of gtsam, when GTSAM_BUILD_PYTHON is enabled, the following instructions will run.
* Wrap parses gtsam.h and constructs a cpp file called ${moduleName}_python.cpp
* This file is then compiled and linked with BoostPython, generating a shared library which can then be imported by python
* The shared library is then copied to python/gtsam
* The user can use the setup.py script to build and install a python package, allowing easy importing into a python project. Examples:
* python setup.py sdist ---- Builds a tarball of the python package which can then be distributed
* python setup.py install ---- Installs the package into the python dist-packages folder. Can then be imported from any python file.
* To run the unit tests, you must first install the package on your path (TODO: Make this easier)
TODO: There are many issues with this build system, but these are the basics.

View File

@ -1 +1 @@
from libgtsam import *
from libgtsam_python import *

BIN
python/gtsam/libgtsam_python.so Executable file

Binary file not shown.

View File

@ -0,0 +1,13 @@
import unittest
from gtsam import *
#https://docs.python.org/2/library/unittest.html
class TestPoint2(unittest.TestCase):
def setUp(self):
self.point = Point2()
def test_constructor(self):
pass
if __name__ == '__main__':
unittest.main()

View File

@ -0,0 +1,7 @@
#!/usr/bin/env python
from gtsam import *
import numpy_eigen as npe
noisemodel = DiagonalNoiseModel.Sigmas([0.1, 0.1, 0.1])
graph = NonlinearFactorGraph()
initialEstimate = Values()

2
python/setup.py Normal file → Executable file
View File

@ -11,5 +11,5 @@ setup(name='GTSAM',
author_email='Andrew.Melim@gatech.edu',
url='http://www.python.org/sigs/distutils-sig/',
packages=['gtsam'],
package_data={'gtsam' : ['libgtsam.so']},
package_data={'gtsam' : ['libgtsam_python.so']},
)