Skip to content

Commit 85518ac

Browse files
authored
Merge pull request #3 from borglab/feature/package-improvements
Packaging Improvements
2 parents 8587668 + e17b326 commit 85518ac

File tree

4 files changed

+59
-43
lines changed

4 files changed

+59
-43
lines changed

TUTORIAL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,4 @@ Finally, we go into the generated `cython` directory where the `setup.py` file i
121121

122122
# Installing
123123

124-
To install the package, in the `cython` directory we can run `python setup.py build`.
124+
To install the package, in the `cython` directory we can run `python setup.py install`.

example/CMakeLists.txt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
# This file should be used as a template for creating new projects with Python wrapping using the CMake tools
22

33
###################################################################################
4-
# 1. To create your own project, replace "example" with the actual name of your project
4+
# 1. To create your own project, replace "gtsam_example" with the actual name of your project
55
cmake_minimum_required(VERSION 3.0)
6-
project(example CXX C)
6+
project(gtsam_example CXX C)
77

88
###################################################################################
99
# 2. Set the python version
10-
set(GTSAM_PYTHON_VERSION "3.6")
10+
set(GTSAM_PYTHON_VERSION "Default" CACHE STRING "The Python version to use for wrapping")
11+
if(GTSAM_PYTHON_VERSION STREQUAL "Default")
12+
find_package(PythonInterp REQUIRED)
13+
find_package(PythonLibs REQUIRED)
14+
else()
15+
find_package(PythonInterp ${GTSAM_PYTHON_VERSION} EXACT REQUIRED)
16+
find_package(PythonLibs ${GTSAM_PYTHON_VERSION} EXACT REQUIRED)
17+
endif()
1118

1219
###################################################################################
1320
# 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
6370

6471
###################################################################################
6572
# 10. Build Cython wrapper (CMake tracks the dependecy to link with GTSAM through our project's static library)
66-
wrap_and_install_library_cython("example.h" # interface_header
73+
wrap_and_install_library_cython("gtsam_example.h" # interface_header
6774
"" # extra imports
68-
"./${PROJECT_NAME}" # install path
75+
"${PROJECT_BINARY_DIR}/cython/${PROJECT_NAME}" # install path
6976
"gtsam;${PROJECT_NAME}" # library to link with
7077
"wrap;gtsam" # dependencies which need to be built before wrapping
7178
)

example/example.h renamed to example/gtsam_example.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,23 @@
1010
* -------------------------------------------------------------------------- */
1111

1212
/**
13-
* @file example.h
13+
* @file gtsam_example.h
1414
* @brief Example wrapper interface file for Python
1515
* @author Varun Agrawal
1616
*/
1717

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

2121
#include <src/greeting.h>
2222

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

2526
class Greeting {
26-
Greeting();
27-
void sayHello() const;
28-
void sayGoodbye() const;
27+
Greeting();
28+
void sayHello() const;
29+
void sayGoodbye() const;
2930
};
3031

31-
}
32+
} // namespace example

example/setup.py

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,55 @@
11
import os
22
import sys
3+
34
try:
45
from setuptools import setup, find_packages
56
except ImportError:
67
from distutils.core import setup, find_packages
78

89
packages = find_packages()
910

11+
package_data = {
12+
package: [
13+
f
14+
for f in os.listdir(package.replace(".", os.path.sep))
15+
if os.path.splitext(f)[1] in (".so", ".pyd")
16+
]
17+
for package in packages
18+
}
19+
20+
dependencies = ["gtsam", "Cython>=0.25.2", "backports_abc>=0.5", "numpy>=1.12.0"]
21+
1022
setup(
11-
name='example',
12-
description='Simple example of wrapping projects with Python and GTSAM',
13-
url='https://gtsam.org/',
14-
version='1.0.0',
15-
author='Varun Agrawal',
16-
author_email='[email protected]',
17-
license='Simplified BSD license',
18-
keywords='wrapper tutorial example',
23+
name="gtsam_example",
24+
description="Simple example of wrapping projects with GTSAM",
25+
url="https://github.com/borglab/gtsam-project-python/",
26+
version="1.0.0",
27+
author="Varun Agrawal",
28+
author_email="[email protected]",
29+
license="Simplified BSD license",
30+
keywords="gtsam wrapper tutorial example",
1931
long_description="",
20-
long_description_content_type='text/markdown',
21-
python_requires='>=3.6',
32+
long_description_content_type="text/markdown",
33+
python_requires=">=3.6",
2234
# https://pypi.org/pypi?%3Aaction=list_classifiers
2335
classifiers=[
24-
'Development Status :: 5 - Production/Stable',
25-
'Intended Audience :: Education',
26-
'Intended Audience :: Developers',
27-
'Intended Audience :: Science/Research',
28-
'Operating System :: MacOS',
29-
'Operating System :: Microsoft :: Windows',
30-
'Operating System :: POSIX',
31-
'License :: OSI Approved :: BSD License',
32-
'Programming Language :: Python :: 2',
33-
'Programming Language :: Python :: 3',
36+
"Development Status :: 5 - Production/Stable",
37+
"Intended Audience :: Education",
38+
"Intended Audience :: Developers",
39+
"Intended Audience :: Science/Research",
40+
"Operating System :: MacOS",
41+
"Operating System :: Microsoft :: Windows",
42+
"Operating System :: POSIX",
43+
"License :: OSI Approved :: BSD License",
44+
"Programming Language :: Python :: 2",
45+
"Programming Language :: Python :: 3",
3446
],
35-
3647
packages=packages,
3748
# Load the built shared object files
38-
package_data={package:
39-
[f for f in os.listdir(package.replace('.', os.path.sep)) if os.path.splitext(f)[1] in ('.so', '.pyd')]
40-
for package in packages
41-
},
42-
install_requires=[line.strip() for line in '''
43-
Cython>=0.25.2
44-
backports_abc>=0.5
45-
numpy>=1.12.0
46-
'''.splitlines() if len(line.strip()) > 0 and not line.strip().startswith('#')]
49+
package_data=package_data,
50+
include_package_data=True,
51+
# Ensure that the compiled .so file is properly packaged
52+
zip_safe=False,
53+
platforms="any",
54+
install_requires=dependencies,
4755
)

0 commit comments

Comments
 (0)