diff --git a/TUTORIAL.md b/TUTORIAL.md index adf43df..9899004 100644 --- a/TUTORIAL.md +++ b/TUTORIAL.md @@ -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`. diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index f294dc9..c2f324c 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -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 @@ -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 ) diff --git a/example/example.h b/example/gtsam_example.h similarity index 71% rename from example/example.h rename to example/gtsam_example.h index e070084..312679b 100644 --- a/example/example.h +++ b/example/gtsam_example.h @@ -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 +// 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 diff --git a/example/setup.py b/example/setup.py index 7bf5693..d0752e5 100644 --- a/example/setup.py +++ b/example/setup.py @@ -1,5 +1,6 @@ import os import sys + try: from setuptools import setup, find_packages except ImportError: @@ -7,41 +8,48 @@ 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, )