forked from npy0/nanopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
90 lines (72 loc) · 2.54 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
# -*- coding: utf-8 -*-
import os
import sys
from setuptools import setup, Extension
def find_gcc(*min_max, dirs):
"""
Looks in `dirs` for gcc-{min_max}, starting with max.
If no gcc-{version} is found, `None` is returned.
:param min_max: tuple of min and max gcc versions
:param dirs: list of directories to look in
:return: gcc name or None
"""
for version in range(*min_max).__reversed__():
f_name = 'gcc-{0}'.format(version)
for _dir in dirs:
full_path = os.path.join(_dir, f_name)
if os.path.exists(full_path) and os.access(full_path, os.X_OK):
return f_name
return None
def get_ext_kwargs(use_gpu=False, link_omp=False, platform=None):
"""
builds extension kwargs depending on environment
:param use_gpu: use OpenCL GPU work generation
:param link_omp: Link with the OMP library (OSX)
:param platform: OS platform
:return: extension kwargs
"""
e_args = {
'name': 'nanopy.work',
'sources': ['nanopy/b2b/blake2b.c', 'nanopy/work.c'],
'extra_compile_args': [],
'extra_link_args': [],
'libraries': [],
'define_macros': [],
}
if platform == 'darwin':
if use_gpu:
e_args['define_macros'] = [('HAVE_OPENCL_OPENCL_H', '1')]
e_args['extra_link_args'] = ['-framework', 'OpenCL']
else:
if link_omp: e_args['libraries'] = ['omp']
e_args['extra_compile_args'] = ['-fopenmp']
e_args['extra_link_args'] = ['-fopenmp']
elif platform in ['linux', 'win32', 'cygwin']:
if use_gpu:
e_args['define_macros'] = [('HAVE_CL_CL_H', '1')]
e_args['libraries'] = ['OpenCL']
else:
e_args['extra_compile_args'] = ['-fopenmp']
e_args['extra_link_args'] = ['-fopenmp']
else:
raise OSError('Unsupported OS platform')
return e_args
env = os.environ
env['CC'] = os.getenv('CC') or find_gcc(
*(5, 9), dirs=os.getenv('PATH').split(os.pathsep))
setup(
name="nanopy",
version='18.0.0',
packages=['nanopy'],
description='Python implementation of NANO-related functions.',
url='https://github.com/nano128/nanopy',
author='128',
license='MIT',
python_requires='>=3.6',
install_requires=['requests', 'mnemonic'],
ext_modules=[
Extension(**get_ext_kwargs(
use_gpu=True if env.get('USE_GPU') == '1' else False,
link_omp=True if env.get('LINK_OMP') == '1' else False,
platform=sys.platform))
])