forked from Ezibenroc/PyRoaringBitMap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·130 lines (110 loc) · 3.89 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
130
#! /usr/bin/env python3
from setuptools import setup
from setuptools.extension import Extension
from distutils.sysconfig import get_config_vars
import os
import sys
import subprocess
import platform
VERSION = '0.2.9'
PKG_DIR = 'pyroaring'
PLATFORM_WINDOWS = (platform.system() == 'Windows')
PLATFORM_MACOSX = (platform.system() == 'Darwin')
def chdir(func, directory):
old_dir = os.getcwd()
os.chdir(directory)
res = func()
os.chdir(old_dir)
return res
def run(args):
proc = subprocess.Popen(args, stdout=subprocess.PIPE)
stdout, stderr = proc.communicate()
if proc.returncode != 0:
sys.exit('Error with the command %s.\n' % ' '.join(args))
return stdout.decode('ascii').strip()
def git_version():
return run(['git', 'rev-parse', 'HEAD'])
def git_tag():
return run(['git', 'describe', '--always', '--dirty'])
def write_version(filename, version_dict):
with open(filename, 'w') as f:
for version_name in version_dict:
f.write('%s = "%s"\n' % (version_name, version_dict[version_name]))
# Remove -Wstrict-prototypes option
# See http://stackoverflow.com/a/29634231/4110059
if not PLATFORM_WINDOWS:
cfg_vars = get_config_vars()
for key, value in cfg_vars.items():
if type(value) == str:
cfg_vars[key] = value.replace("-Wstrict-prototypes", "")
try:
with open('README.rst') as f:
long_description = ''.join(f.readlines())
except (IOError, ImportError, RuntimeError):
print('Could not generate long description.')
long_description = ''
USE_CYTHON = os.path.exists(os.path.join(PKG_DIR, 'pyroaring.pyx'))
if USE_CYTHON:
print('Building pyroaring from Cython sources.')
from amalgamation import amalgamate
amalgamate(PKG_DIR)
from Cython.Build import cythonize
ext = 'pyx'
write_version(os.path.join(PKG_DIR, 'version.pxi'), {
'__version__': VERSION,
'__git_version__': git_version(),
'__croaring_version__': chdir(git_tag, 'CRoaring'),
'__croaring_git_version__': chdir(git_version, 'CRoaring'),
})
else:
print('Building pyroaring from C sources.')
ext = 'cpp'
if PLATFORM_WINDOWS:
compile_args = []
else:
compile_args = ['-D__STDC_LIMIT_MACROS', '-D__STDC_CONSTANT_MACROS', '-D _GLIBCXX_ASSERTIONS']
if PLATFORM_MACOSX:
compile_args.append('-mmacosx-version-min=10.14')
else:
compile_args.append('-std=c99')
if 'DEBUG' in os.environ:
compile_args.extend(['-O0', '-g'])
else:
compile_args.append('-O3')
if 'ARCHI' in os.environ:
if os.environ['ARCHI'] != "generic":
compile_args.extend(['-march=%s' % os.environ['ARCHI']])
else:
compile_args.append('-march=native')
filename = os.path.join(PKG_DIR, 'pyroaring.%s' % ext)
pyroaring = Extension('pyroaring',
sources=[filename, os.path.join(PKG_DIR, 'roaring.c')],
extra_compile_args=compile_args,
)
if USE_CYTHON:
pyroaring = cythonize(pyroaring, compiler_directives={'binding': True})
else:
pyroaring = [pyroaring]
setup(
name='pyroaring',
ext_modules=pyroaring,
version=VERSION,
description='Fast and lightweight set for unsigned 32 bits integers.',
long_description=long_description,
url='https://github.com/Ezibenroc/PyRoaringBitMap',
author='Tom Cornebize',
author_email='tom.cornebize@gmail.com',
license='MIT',
classifiers=[
'License :: OSI Approved :: MIT License',
'Intended Audience :: Developers',
'Operating System :: POSIX :: Linux',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],
)