-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathsetup.py
121 lines (107 loc) · 4.69 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- coding: utf-8 -*-
# Copyright (C) 2017 Michael Hogg
# This file is part of pyoctree - See LICENSE.txt for information on usage and redistribution
from setuptools import setup, find_packages
from setuptools.extension import Extension
from codecs import open
from os import path
import sys
# Get current path
here = path.abspath(path.dirname(__file__))
# Function to open the readme file
def readme():
with open(path.join(here, 'README.rst')) as f:
return f.read()
long_description = readme()
# Function to parse command line arguments to check for openmp option. Modified from kwikteam/klustakwik2/setup.py
def parse_cmdline_args(arg):
try:
sys.argv.remove('--%s' % arg)
return True
except ValueError:
pass
return False
# Find the version
exec(open(path.join('pyoctree','version.py')).read())
try:
from Cython.Distutils import build_ext
except ImportError:
from setuptools.command.build_ext import build_ext
use_cython = False
else:
use_cython = True
# Check if user wants to use openmp
use_openmp = parse_cmdline_args('openmp')
# Supply correct openmp compiler arguments depending on os. Based on SO question:
# http://stackoverflow.com/questions/30985862/how-to-identify-compiler-before-defining-cython-extensions
# However, need to add extra link args in addition to build args, as these are required for gcc.
# From http://stackoverflow.com/questions/16737260/how-to-tell-distutils-to-use-gcc, the distutils --compiler
# option expects "unix", "msvc", "cygwin", "mingw32", "bcpp", or "emx". Therefore, should add support for
# all these, but will currently support only mscv, mingw32, and unix.
# The current code has been tested on Windows 10 and CentOS 6. The CentOS compiler type is "unix", which uses gcc by default.
BUILD_ARGS = {}
BUILD_ARGS['msvc'] = ['/openmp', '/EHsc', ]
BUILD_ARGS['mingw32'] = ['-fopenmp', ]
BUILD_ARGS['unix'] = ['-fopenmp', ] # On CentOS, "compiler" variable equals 'unix' for gcc compiler
LINK_ARGS = {}
LINK_ARGS['msvc'] = []
LINK_ARGS['mingw32'] = []
LINK_ARGS['unix'] = ['-lgomp', ] # gcc requires -lgomp for linking. Otherwise get unrecognised symbol error
# Custom class to add required dependencies for building the project
class build_ext_dependencies(build_ext):
def finalize_options(self):
build_ext.finalize_options(self)
import numpy
self.include_dirs.append(numpy.get_include())
# Custom class to add compiler depended build and link arguments
class build_ext_compiler_check(build_ext_dependencies):
def build_extensions(self):
if use_openmp:
compiler = self.compiler.compiler_type
for ext in self.extensions:
if compiler in BUILD_ARGS:
ext.extra_compile_args = BUILD_ARGS[compiler]
if compiler in LINK_ARGS:
ext.extra_link_args = LINK_ARGS[compiler]
build_ext.build_extensions(self)
cmdclass = { "build_ext": build_ext_dependencies }
ext_modules = []
if use_cython:
ext_modules += [ Extension("pyoctree.pyoctree", sources=["pyoctree/pyoctree.pyx","pyoctree/cOctree.cpp"],language="c++")]
cmdclass.update({ 'build_ext': build_ext_compiler_check })
else:
ext_modules += [ Extension("pyoctree.pyoctree", sources=["pyoctree/pyoctree.cpp","pyoctree/cOctree.cpp"],language="c++")]
cmdclass.update({ 'build_ext': build_ext_dependencies })
setup(
name = 'pyoctree',
version = __version__,
description = 'Octree structure containing 3D triangular mesh model',
long_description = long_description,
license = 'MIT license',
keywords = ["octree","triangle","mesh","python","cython","ray","tracing"],
author = 'Michael Hogg',
author_email = '[email protected]',
url = "https://github.com/mhogg/pyoctree",
download_url = "https://github.com/mhogg/pyoctree/releases",
packages = find_packages(),
include_package_data = True,
package_data = {'': ['README.rst','LICENSE.txt'],
'pyoctree': ['Examples\*']},
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Other Environment",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Cython",
"Programming Language :: C++",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
],
ext_modules = ext_modules,
cmdclass = cmdclass,
setup_requires = ["numpy"],
install_requires = ["numpy"],
)