-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
executable file
·129 lines (103 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
122
123
124
125
126
127
128
129
import platform
from setuptools import setup, Extension, find_packages
import os
import glob
import platform
# 2024-08-08 KWS Need to derive the architecture. Can't assume x86_64 anymore.
arch = platform.machine()
moduleDirectory = os.path.dirname(os.path.realpath(__file__))
exec(open(moduleDirectory + "/gkhtm/__version__.py").read())
#sources = glob.glob('src/*.cpp') + glob.glob('src/*.i')
def readme():
with open(moduleDirectory + '/README.md') as f:
return f.read()
if platform.system() == 'Darwin':
# MacOS
extra_compile_args = ['-c', '-g', '-D_BOOL_EXISTS', '-D__macosx', '-UDIAGNOSE', '-Wno-deprecated', '-Wno-self-assign', '-Wno-address-of-temporary', '-Wno-format', '-Wno-dangling-else', '-Wno-unused-private-field', '-arch', arch, '-stdlib=libc++']
extra_link_args = ['-arch', arch]
from distutils.sysconfig import get_config_var
from distutils.version import LooseVersion
if 'MACOSX_DEPLOYMENT_TARGET' not in os.environ:
current_system = LooseVersion(platform.mac_ver()[0])
python_target = LooseVersion(
get_config_var('MACOSX_DEPLOYMENT_TARGET'))
if python_target < '10.9' and current_system >= '10.9':
os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.9'
else:
# Assumes Linux
extra_compile_args = ['-c', '-fPIC', '-g', '-Wall', '-D_BOOL_EXISTS', '-D__unix', '-UDIAGNOSE', '-Wno-deprecated', '-fpermissive', '-std=c++11']
extra_link_args = []
static_include_dirs = ['gkhtm/htm/include']
plib_include_dirs = static_include_dirs.copy()
plib_include_dirs.append('gkhtm')
htm_sources = glob.glob('gkhtm/htm/src/*.cpp')
# Missing .c file
htm_sources.append('gkhtm/htm/cc_aux.c')
libraries = ['htm']
library_dirs = ['build']
# 2020-06-17 KWS Attempt to build the static library. This took many hours of figuring out, but
# after doing so, I realised that we have all the .o files necessary to build into
# the python shared library, so in fact, this code is not necessary. I've left it
# here for posterity.
from setuptools import Command
sources = htm_sources.copy()
from distutils.ccompiler import new_compiler
from sysconfig import get_paths
import os
project_name = "htm"
build_dir = os.path.join(os.path.dirname(__file__), 'build')
class BuildStaticLib(Command):
description = 'build static lib'
user_options = [] # do not remove, needs to be stubbed out!
python_info = get_paths()
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
# Create compiler with default options
print("Compiling Static Library...")
c = new_compiler()
# Add include directories etc.
for d in static_include_dirs:
c.add_include_dir(d)
# Don't need python includes for this library, but leave in
# for future reference.
#c.add_include_dir(self.python_info['include'])
# Compile into .o files
objects = c.compile(sources, extra_postargs = extra_compile_args)
# Create static or shared library
c.create_static_lib(objects, project_name, output_dir=build_dir)
# Note to self - do NOT specify the swig output _wrap.cpp file. This will cause the compiler
# to compile it twice and then attempt to link it twice. This file is implicit from the call
# to swig.
# ALSO - swig version 3.0+ is required. This does NOT work with version 2 for some reason.
htm_sources += ['gkhtm/gkhtm.i', 'gkhtm/HTMCircleRegion.cpp', 'gkhtm/HTMCircleAllIDsCassandra.cpp']
#htm_module = Extension('gkhtm._gkhtm', swig_opts=['-modern', '-c++'], extra_compile_args=extra_compile_args, extra_link_args=extra_link_args, sources=htm_sources, include_dirs=plib_include_dirs, libraries = libraries, library_dirs = library_dirs)
htm_module = Extension('gkhtm._gkhtm', swig_opts=['-modern', '-c++'], extra_compile_args=extra_compile_args, extra_link_args=extra_link_args, sources=htm_sources, include_dirs=plib_include_dirs)
ext_modules = []
ext_modules.append(htm_module)
packages = ['gkhtm']
setup(
name="gkhtm",
description='HTM library interface for Python',
long_description=readme(),
cmdclass = {'buildstatic': BuildStaticLib},
ext_modules=ext_modules,
long_description_content_type="text/markdown",
version=__version__,
author='genghisken',
author_email='[email protected]',
license='MIT',
url='https://github.com/genghisken/gkhtm',
packages=find_packages(),
classifiers=[
'Development Status :: 4 - Beta',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.6',
'Topic :: Utilities',
],
python_requires='>=3.6',
include_package_data=True,
zip_safe=False
)