Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ Finally, we go into the generated `cython` directory where the `setup.py` file i

# Installing

To install the package, in the `cython` directory we can run `python setup.py build`.
To install the package, in the `cython` directory we can run `python setup.py install`.
17 changes: 12 additions & 5 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# This file should be used as a template for creating new projects with Python wrapping using the CMake tools

###################################################################################
# 1. To create your own project, replace "example" with the actual name of your project
# 1. To create your own project, replace "gtsam_example" with the actual name of your project
cmake_minimum_required(VERSION 3.0)
project(example CXX C)
project(gtsam_example CXX C)

###################################################################################
# 2. Set the python version
set(GTSAM_PYTHON_VERSION "3.6")
set(GTSAM_PYTHON_VERSION "Default" CACHE STRING "The Python version to use for wrapping")
if(GTSAM_PYTHON_VERSION STREQUAL "Default")
find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)
else()
find_package(PythonInterp ${GTSAM_PYTHON_VERSION} EXACT REQUIRED)
find_package(PythonLibs ${GTSAM_PYTHON_VERSION} EXACT REQUIRED)
endif()

###################################################################################
# 3. Find GTSAM components so we have access to the GTSAM Cython install path
Expand Down Expand Up @@ -63,9 +70,9 @@ configure_file(${PROJECT_SOURCE_DIR}/setup.py ${PROJECT_BINARY_DIR}/cython/setup

###################################################################################
# 10. Build Cython wrapper (CMake tracks the dependecy to link with GTSAM through our project's static library)
wrap_and_install_library_cython("example.h" # interface_header
wrap_and_install_library_cython("gtsam_example.h" # interface_header
"" # extra imports
"./${PROJECT_NAME}" # install path
"${PROJECT_BINARY_DIR}/cython/${PROJECT_NAME}" # install path
"gtsam;${PROJECT_NAME}" # library to link with
"wrap;gtsam" # dependencies which need to be built before wrapping
)
15 changes: 8 additions & 7 deletions example/example.h → example/gtsam_example.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@
* -------------------------------------------------------------------------- */

/**
* @file example.h
* @file gtsam_example.h
* @brief Example wrapper interface file for Python
* @author Varun Agrawal
*/

// This is an interface file for automatic Python wrapper generation. See
// gtsam.h for full documentation and more examples.
// This is an interface file for automatic Python wrapper generation.
// See gtsam.h for full documentation and more examples.

#include <src/greeting.h>

// The namespace should be the same as in the c++ source code.
namespace example {

class Greeting {
Greeting();
void sayHello() const;
void sayGoodbye() const;
Greeting();
void sayHello() const;
void sayGoodbye() const;
};

}
} // namespace example
68 changes: 38 additions & 30 deletions example/setup.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,55 @@
import os
import sys

try:
from setuptools import setup, find_packages
except ImportError:
from distutils.core import setup, find_packages

packages = find_packages()

package_data = {
package: [
f
for f in os.listdir(package.replace(".", os.path.sep))
if os.path.splitext(f)[1] in (".so", ".pyd")
]
for package in packages
}

dependencies = ["gtsam", "Cython>=0.25.2", "backports_abc>=0.5", "numpy>=1.12.0"]

setup(
name='example',
description='Simple example of wrapping projects with Python and GTSAM',
url='https://gtsam.org/',
version='1.0.0',
author='Varun Agrawal',
author_email='varunagrawal@gatech.edu',
license='Simplified BSD license',
keywords='wrapper tutorial example',
name="gtsam_example",
description="Simple example of wrapping projects with GTSAM",
url="https://github.com/borglab/gtsam-project-python/",
version="1.0.0",
author="Varun Agrawal",
author_email="varunagrawal@gatech.edu",
license="Simplified BSD license",
keywords="gtsam wrapper tutorial example",
long_description="",
long_description_content_type='text/markdown',
python_requires='>=3.6',
long_description_content_type="text/markdown",
python_requires=">=3.6",
# https://pypi.org/pypi?%3Aaction=list_classifiers
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Education',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'Operating System :: MacOS',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'License :: OSI Approved :: BSD License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Education",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Operating System :: MacOS",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
],

packages=packages,
# Load the built shared object files
package_data={package:
[f for f in os.listdir(package.replace('.', os.path.sep)) if os.path.splitext(f)[1] in ('.so', '.pyd')]
for package in packages
},
install_requires=[line.strip() for line in '''
Cython>=0.25.2
backports_abc>=0.5
numpy>=1.12.0
'''.splitlines() if len(line.strip()) > 0 and not line.strip().startswith('#')]
package_data=package_data,
include_package_data=True,
# Ensure that the compiled .so file is properly packaged
zip_safe=False,
platforms="any",
install_requires=dependencies,
)