forked from theQRL/qrllib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·74 lines (57 loc) · 2.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import subprocess
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
from distutils.sysconfig import get_python_inc
import distutils.sysconfig as sysconfig
import versioneer
import pkg_resources # part of setuptools
class CMakeBuild(build_ext):
def run(self):
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
env = os.environ.copy()
env['CXXFLAGS'] = env.get('CXXFLAGS', '')
env['CXXFLAGS'] += ' -DVERSION_INFO=\\"' + self.distribution.get_version() + '\\"'
for ext in self.extensions:
extension_path = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
cmake_call = ['cmake', ext.sourcedir,
'-DBUILD_PYTHON=ON',
'-DBUILD_TESTS=OFF',
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extension_path,
'-DCMAKE_BUILD_TYPE=Release']
# Detect conda
if sys.platform == 'darwin' and 'CONDA_DEFAULT_ENV' in os.environ:
print('OSX + Conda environment detected')
python_include_dir = get_python_inc()
python_library = os.path.join(sysconfig.get_config_var('LIBDIR'), sysconfig.get_config_var('LDLIBRARY'))
cmake_call.extend(['-DPYTHON_INCLUDE_DIR=' + python_include_dir,
'-DPYTHON_LIBRARY=' + python_library])
subprocess.check_call(cmake_call, cwd=self.build_temp, env=env)
subprocess.check_call(['cmake', '--build', '.',
'--config', 'Release', '--', '-j2'], cwd=self.build_temp)
class CMakeExtension(Extension):
def __init__(self, name, sourcedir='', *args, **kw):
Extension.__init__(self, name, sources=[], *args, **kw)
self.sourcedir = os.path.abspath(sourcedir)
def setup_package():
needs_sphinx = {'build_sphinx', 'upload_docs'}.intersection(sys.argv)
sphinx = ['sphinx'] if needs_sphinx else []
cmake = []
try:
version = pkg_resources.require("pyqrllib")[0].version
except:
version = versioneer.get_version()
# noinspection PyInterpreter
setup(setup_requires=['six', 'pytest-runner', 'pyscaffold>3'] + sphinx + cmake,
packages=['pyqrllib', ],
tests_require=['pytest', 'pytest-cov'],
ext_modules=[CMakeExtension('pyqrllib')],
version=version,
cmdclass=dict(build_ext=CMakeBuild),
use_pyscaffold=True)
if __name__ == "__main__":
setup_package()