-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
111 lines (91 loc) · 3.62 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
from __future__ import print_function
import distutils.cmd
import setuptools
import os
import sys
import shutil
import subprocess
import platform
with open("README.md", "r") as fh:
long_description = fh.read()
def check_rust_bitness():
toolchain = subprocess.Popen(['rustup', 'show', 'active-toolchain'], stdout=subprocess.PIPE).communicate()[0]
toolchain = str(toolchain)
python_bitness = platform.architecture()[0]
if python_bitness == "32bit":
if not "i686" in toolchain:
print("WARNING: Python interpreter is 32-bit, while default Rust target toolchain is not 32-bit.\n"
"\tUse \"rustup target list\" to list all the available Rust target toolchains.\n"
"\tUse \"rustup target add {toolchain_name}\" to include a compatible Rust target toolchain.\n"
"\tUse \"rustup default {toolchain_name}\" to set a default target toolchain.\n",
file=sys.stderr)
if python_bitness == "64bit":
if not "64" in toolchain:
print("WARNING: Python interpreter is 64-bit, while default Rust target toolchain is not 64-bit.\n"
"\tUse \"rustup target list\" to list all the available Rust target toolchains.\n"
"\tUse \"rustup target add {toolchain_name}\" to include a compatible Rust target toolchain.\n"
"\tUse \"rustup default {toolchain_name}\" to set a default target toolchain.\n",
file=sys.stderr)
def build_native(spec):
check_rust_bitness()
build = spec.add_external_build(
cmd=['cargo', 'build', '--release'],
path='./rust'
)
spec.add_cffi_module(
module_path='kde_ocl._ffi',
dylib=lambda: build.find_dylib('kde_ocl_sys', in_path='target/release'),
header_filename=lambda: build.find_header('kde-ocl-sys.h', in_path='target'),
rtld_flags=['NOW', 'NODELETE']
)
class CleanCommand(distutils.cmd.Command):
"""
Our custom command to clean out junk files.
"""
description = "Cleans out all generated files and folders."
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
files_to_delete = ["kde_ocl/_ffi.py", "kde_ocl/_ffi__ffi.py", "kde_ocl/_ffi__lib.so", "kde_ocl/_ffi__lib.pyd",
"rust/src/open_cl_code.rs"]
for file in files_to_delete:
if os.path.exists(file):
os.remove(file)
current_dir = os.getcwd()
os.chdir('rust')
os.system("cargo clean")
os.chdir(current_dir)
folders_to_delete = [".eggs", "kde_ocl.egg-info", "build"]
for folder in folders_to_delete:
if os.path.exists(folder):
shutil.rmtree(folder)
setuptools.setup(
name="kde_ocl",
version="0.1.0",
author="David Atienza",
author_email="[email protected]",
description="An OpenCL implementation of Kernel Density Estimation",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/davenza/kde_ocl",
packages=["kde_ocl"],
classifiers=[
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
zip_safe=False,
platforms="any",
setup_requires=["milksnake"],
install_requires=["milksnake", "numpy", "six"],
milksnake_tasks=[
build_native
],
cmdclass={
"clean": CleanCommand,
},
)