From 8261956a0a5a239791776e5d403b3dfd18611738 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 7 Jul 2020 12:04:51 -0400 Subject: [PATCH 1/6] renamed python package from example to less ambiguous gtsam_example --- example/CMakeLists.txt | 6 +++--- example/{example.h => gtsam_example.h} | 15 ++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) rename example/{example.h => gtsam_example.h} (71%) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index f294dc9..f381ba3 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,9 +1,9 @@ # 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 @@ -63,7 +63,7 @@ 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 "gtsam;${PROJECT_NAME}" # library to link with 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 From 0cf26797084606ba984b2294fdffa4dc1ff00b86 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 7 Jul 2020 12:05:11 -0400 Subject: [PATCH 2/6] cleaned up the setup.py file --- example/setup.py | 64 +++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/example/setup.py b/example/setup.py index 7bf5693..5ee2380 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,44 @@ 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 = ["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://gtsam.org/", + version="1.0.0", + author="Varun Agrawal", + author_email="varunagrawal@gatech.edu", + license="Simplified BSD license", + keywords="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, + install_requires=dependencies, ) From 00dbc0560cc157c5e52ec18067b0b81b376dce1f Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 7 Jul 2020 12:05:35 -0400 Subject: [PATCH 3/6] fixed typo in install instructions in tutorial --- TUTORIAL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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`. From 6346df791be37d97a63a0fa845d21451d8016cb5 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 7 Jul 2020 12:06:15 -0400 Subject: [PATCH 4/6] pick up default python and python libs rather than specific version --- example/CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index f381ba3..8f1b7dc 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -7,7 +7,14 @@ 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 From 8e36693a46601918a41ad7e0382123d2628c66e0 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 7 Jul 2020 12:06:57 -0400 Subject: [PATCH 5/6] updated wrapped package install path to be absolute --- example/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 8f1b7dc..c2f324c 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -72,7 +72,7 @@ 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("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 ) From e17b3268b97659ba4644943d27ff50eaea5fed38 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Tue, 7 Jul 2020 12:13:33 -0400 Subject: [PATCH 6/6] added extra setup.py flags to ensure the package includes the compiled .so lib --- example/setup.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/example/setup.py b/example/setup.py index 5ee2380..d0752e5 100644 --- a/example/setup.py +++ b/example/setup.py @@ -17,17 +17,17 @@ for package in packages } -dependencies = ["Cython>=0.25.2", "backports_abc>=0.5", "numpy>=1.12.0"] +dependencies = ["gtsam", "Cython>=0.25.2", "backports_abc>=0.5", "numpy>=1.12.0"] setup( name="gtsam_example", description="Simple example of wrapping projects with GTSAM", - url="https://gtsam.org/", + 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="wrapper tutorial example", + keywords="gtsam wrapper tutorial example", long_description="", long_description_content_type="text/markdown", python_requires=">=3.6", @@ -47,5 +47,9 @@ packages=packages, # Load the built shared object files 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, )