-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.py
More file actions
89 lines (76 loc) · 2.51 KB
/
setup.py
File metadata and controls
89 lines (76 loc) · 2.51 KB
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
#! /usr/bin/env python
import os
import io
from distutils.core import setup, Extension
# from setuptools import setup, Extension
import numpy as np
# NOTE: to compile, run in the current directory
# python setup.py build_ext --inplace
# python setup.py develop
try:
from Cython.Build import cythonize
# from Cython.Distutils import build_ext
except ImportError:
use_cython = False
else:
use_cython = True
def read(*filenames, **kwargs):
encoding = kwargs.get('encoding', 'utf-8')
sep = kwargs.get('sep', '\n')
buf = []
for filename in filenames:
with io.open(filename, encoding=encoding) as f:
buf.append(f.read())
return sep.join(buf)
cmdclass = {}
ext_modules = []
here = os.path.abspath(os.path.dirname(__file__))
extentions_info = [
{
"cython_sourcefile": "knapsack_python/python/cython/mthm.pyx"
},
{
"cython_sourcefile": "knapsack_python/python/cython/mthg.pyx"
},
{
"cython_sourcefile": "knapsack_python/python/cython/assign_all.pyx"
}
]
include_path = [np.get_include(), 'knapsack_python/cpp/include']
extensions = []
for extention_info in extentions_info:
sourcefiles = extention_info.get("cpp_sourcefiles", [])
cython_sourcefile = extention_info.get("cython_sourcefile")
if use_cython:
sourcefiles += [cython_sourcefile]
else:
sourcefiles += [cython_sourcefile.replace('.pyx', '.cpp')]
# NOTE: extension name must match .pyx file name
extension_name = cython_sourcefile.replace('.pyx', '').replace(os.sep, '.')
extensions.append(Extension(extension_name,
sources=sourcefiles,
include_dirs=include_path,
language='c++'))
if use_cython:
ext_modules += \
cythonize(extensions, compiler_directives={'embedsignature': True,
'profile': True})
else:
ext_modules += extensions
long_description = read('README.rst', 'CHANGELOG.rst')
setup(
name="knapsack_python",
version='0.1.3',
url='https://github.com/jhetherly/python_knapsack',
license='MIT',
author='Jeff Hetherly',
author_email='jeffrey.hetherly@gmail.com',
platforms='any',
description='Solves a variety of knapsack problems',
long_description=long_description,
install_requires=['numpy'],
packages=['knapsack_python'],
cmdclass=cmdclass,
ext_modules=ext_modules,
include_dirs=[np.get_include(), 'knapsack_python/cpp/include']
)