Skip to content

Commit c341b7b

Browse files
Updated build system away from numpy.distutils
1 parent b400194 commit c341b7b

File tree

2 files changed

+114
-190
lines changed

2 files changed

+114
-190
lines changed

mkl_random/setup.py

Lines changed: 0 additions & 131 deletions
This file was deleted.

setup.py

Lines changed: 114 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# Copyright (c) 2017-2019, Intel Corporation
2+
# Copyright (c) 2017-2022, Intel Corporation
33
#
44
# Redistribution and use in source and binary forms, with or without
55
# modification, are permitted provided that the following conditions are met:
@@ -24,12 +24,15 @@
2424
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2525
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626

27-
from __future__ import division, print_function, absolute_import
28-
2927
import os
3028
import sys
3129
import io
3230
import re
31+
from os.path import join
32+
import Cython.Build
33+
from setuptools import setup, Extension
34+
import numpy as np
35+
3336

3437
with io.open('mkl_random/_version.py', 'rt', encoding='utf8') as f:
3538
version = re.search(r'__version__ = \'(.*?)\'', f.read()).group(1)
@@ -39,59 +42,111 @@
3942

4043
VERSION = version
4144

42-
CLASSIFIERS = ""
43-
44-
def configuration(parent_package='',top_path=None):
45-
from numpy.distutils.misc_util import Configuration
46-
47-
config = Configuration(None, parent_package, top_path)
48-
config.set_options(ignore_setup_xxx_py=True,
49-
assume_default_configuration=True,
50-
delegate_options_to_subpackages=True,
51-
quiet=False)
52-
53-
config.add_subpackage('mkl_random')
54-
55-
config.version = VERSION
56-
57-
return config
58-
59-
60-
from distutils.command.sdist import sdist
61-
def setup_package():
62-
src_path = os.path.dirname(os.path.abspath(sys.argv[0]))
63-
old_path = os.getcwd()
64-
os.chdir(src_path)
65-
sys.path.insert(0, src_path)
66-
67-
from setuptools import setup
68-
from numpy.distutils.core import setup
69-
metadata = dict(
70-
name = 'mkl_random',
71-
maintainer = "Intel Corp.",
72-
maintainer_email = "[email protected]",
73-
description = "NumPy-based Python interface to Intel (R) MKL Random Number Generation functionality",
74-
long_description = long_description,
75-
long_description_content_type="text/markdown",
76-
url = "http://github.com/IntelPython/mkl_random",
77-
author = "Intel Corporation",
78-
download_url = "http://github.com/IntelPython/mkl_random",
79-
license = 'BSD',
80-
classifiers = [_f for _f in CLASSIFIERS.split('\n') if _f],
81-
platforms = ["Windows", "Linux", "Mac OS-X"],
82-
test_suite = 'nose.collector',
83-
python_requires = '>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*',
84-
install_requires=['numpy'],
85-
configuration = configuration
86-
)
87-
88-
try:
89-
setup(**metadata)
90-
finally:
91-
del sys.path[0]
92-
os.chdir(old_path)
93-
94-
return None
95-
96-
if __name__ == '__main__':
97-
setup_package()
45+
CLASSIFIERS = CLASSIFIERS = """\
46+
Development Status :: 5 - Production/Stable
47+
Intended Audience :: Science/Research
48+
Intended Audience :: Developers
49+
License :: OSI Approved
50+
Programming Language :: C
51+
Programming Language :: Python
52+
Programming Language :: Python :: 3
53+
Programming Language :: Python :: 3.7
54+
Programming Language :: Python :: 3.8
55+
Programming Language :: Python :: 3.9
56+
Programming Language :: Python :: 3.10
57+
Programming Language :: Python :: Implementation :: CPython
58+
Topic :: Software Development
59+
Topic :: Scientific/Engineering
60+
Operating System :: Microsoft :: Windows
61+
Operating System :: POSIX
62+
Operating System :: Unix
63+
Operating System :: MacOS
64+
"""
65+
66+
67+
def extensions():
68+
mkl_root = os.environ.get('MKLROOT', None)
69+
if mkl_root:
70+
mkl_info = {
71+
'include_dirs': [join(mkl_root, 'include')],
72+
'library_dirs': [join(mkl_root, 'lib'), join(mkl_root, 'lib', 'intel64')],
73+
'libraries': ['mkl_rt']
74+
}
75+
else:
76+
try:
77+
mkl_info = get_info('mkl')
78+
except:
79+
mkl_info = dict()
80+
81+
mkl_include_dirs = mkl_info.get('include_dirs', [])
82+
mkl_library_dirs = mkl_info.get('library_dirs', [])
83+
mkl_libraries = mkl_info.get('libraries', ['mkl_rt'])
84+
85+
libs = mkl_libraries
86+
lib_dirs = mkl_library_dirs
87+
88+
if sys.platform == 'win32':
89+
libs.append('Advapi32')
90+
91+
Q = '/Q' if sys.platform.startswith('win') or sys.platform == 'cygwin' else '-'
92+
eca = [Q + "std=c++11"]
93+
if sys.platform == "linux":
94+
eca.extend(["-Wno-unused-but-set-variable", "-Wno-unused-function"])
95+
96+
defs = [('_FILE_OFFSET_BITS', '64'),
97+
('_LARGEFILE_SOURCE', '1'),
98+
('_LARGEFILE64_SOURCE', '1')]
99+
100+
exts = [
101+
Extension(
102+
"mkl_random.mklrand",
103+
[
104+
os.path.join("mkl_random", "mklrand.pyx"),
105+
os.path.join("mkl_random", "src", "mkl_distributions.cpp"),
106+
os.path.join("mkl_random", "src", "randomkit.c"),
107+
],
108+
depends = [
109+
os.path.join("mkl_random", "src", "mkl_distributions.hpp"),
110+
os.path.join("mkl_random", "src", "randomkit.h"),
111+
os.path.join("mkl_random", "src", "numpy.pxd")
112+
],
113+
include_dirs = [os.path.join("mkl_random", "src"), np.get_include()] + mkl_include_dirs,
114+
libraries = libs,
115+
library_dirs = lib_dirs,
116+
extra_compile_args = eca + [
117+
# "-ggdb", "-O0", "-Wall", "-Wextra",
118+
],
119+
define_macros=defs + [("NDEBUG",None),], # [("DEBUG", None),]
120+
language="c++"
121+
)
122+
]
123+
124+
return exts
125+
126+
127+
setup(
128+
name = "mkl_random",
129+
maintainer = "Intel Corp.",
130+
maintainer_email = "[email protected]",
131+
description = "NumPy-based Python interface to Intel (R) MKL Random Number Generation functionality",
132+
version = version,
133+
include_package_data=True,
134+
ext_modules=extensions(),
135+
cmdclass={'build_ext': Cython.Build.build_ext},
136+
zip_safe=False,
137+
long_description = long_description,
138+
long_description_content_type="text/markdown",
139+
url = "http://github.com/IntelPython/mkl_random",
140+
author = "Intel Corporation",
141+
download_url = "http://github.com/IntelPython/mkl_random",
142+
license = "BSD",
143+
classifiers = [_f for _f in CLASSIFIERS.split('\n') if _f],
144+
platforms = ["Windows", "Linux", "Mac OS-X"],
145+
test_suite = "pytest",
146+
python_requires = '>=3.7',
147+
setup_requires=["Cython",],
148+
install_requires = ["numpy >=1.16"],
149+
keywords=["MKL", "VSL", "true randomness", "pseudorandomness",
150+
"Philox", "MT-19937", "SFMT-19937", "MT-2203", "ARS-5",
151+
"R-250", "MCG-31",],
152+
)

0 commit comments

Comments
 (0)