-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
126 lines (102 loc) · 4.62 KB
/
setup.py
File metadata and controls
126 lines (102 loc) · 4.62 KB
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
from __future__ import print_function
import setuptools
import sys
import os
import platform
import subprocess
import numpy
import setuptools
import sys
from Cython.Build import cythonize
from setuptools.command.develop import develop
from setuptools.command.install import install
from setuptools.extension import Extension
MKIDSHM_DIR = 'mkidcontrol/packetmaster3/mkidshm'
def compile_and_install_software():
"""Used the subprocess module to compile/install the C software."""
if 'linux' not in platform.system().lower():
print('Not Linux, skipping compile/install of libmkidshm.so')
return
src_paths = ['./' + MKIDSHM_DIR]
cmds = ["gcc -shared -o libmkidshm.so -fPIC mkidshm.c -lrt -lpthread"]
def get_virtualenv_path():
"""Used to work out path to install compiled binaries to."""
if hasattr(sys, 'real_prefix'):
return sys.prefix
if hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix:
return sys.prefix
if 'conda' in sys.prefix:
return sys.prefix
return None
venv = get_virtualenv_path()
try:
for cmd, src_path in zip(cmds, src_paths):
if venv:
cmd += ' --prefix=' + os.path.abspath(venv)
subprocess.check_call(cmd, cwd=src_path, shell=True)
except Exception as e:
print(str(e))
raise e
class CustomInstall(install):
"""Custom handler for the 'install' command."""
def run(self):
compile_and_install_software()
super(CustomInstall, self).run()
class CustomDevelop(develop):
"""Custom handler for the 'install' command."""
def run(self):
compile_and_install_software()
super(CustomDevelop, self).run()
extensions = [Extension(name="mkidcontrol.packetmaster3.sharedmem",
sources=['mkidcontrol/packetmaster3/sharedmem.pyx'],
include_dirs=[numpy.get_include(), os.path.abspath(MKIDSHM_DIR)],
extra_compile_args=['-shared', '-fPIC'],
library_dirs=[MKIDSHM_DIR],
runtime_library_dirs=[os.path.abspath(MKIDSHM_DIR)],
extra_link_args=['-O3', '-lmkidshm', '-lrt', '-lpthread']), # '-Wl',f'-rpath={MKIDSHM_DIR}']),
Extension(name="mkidcontrol.packetmaster3.packetmaster",
sources=['mkidcontrol/packetmaster3/pmthreads.c', 'mkidcontrol/packetmaster3/packetmaster.pyx'],
include_dirs=[numpy.get_include(), 'mkidcontrol/packetmaster3/packetmaster', MKIDSHM_DIR],
library_dirs=[MKIDSHM_DIR],
runtime_library_dirs=[os.path.abspath(MKIDSHM_DIR)],
extra_compile_args=['-O3', '-shared', '-fPIC'],
extra_link_args=['-lmkidshm', '-lrt', '-lpthread'])
]
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name='mkidcontrol',
version='0.8.0',
author='Noah Swimmer',
author_email='nswimmer@ucsb.edu',
description='MKID Instrument Control Software',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/MazinLab/mkidcontrol.git',
packages=setuptools.find_packages(),
scripts=['mkidcontrol/agents/picturec/quenchAgent.py',
'mkidcontrol/agents/xkid/heatswitchAgent.py',
'mkidcontrol/agents/lakeshore240Agent.py',
'mkidcontrol/agents/lakeshore336Agent.py',
'mkidcontrol/agents/lakeshore372Agent.py',
'mkidcontrol/agents/lakeshore625Agent.py',
'mkidcontrol/agents/picturec/currentduinoAgent.py',
'mkidcontrol/agents/picturec/hemttempAgent.py',
'mkidcontrol/controlflask/mkidDirector.py',
'mkidcontrol/agents/picturec/sim960Agent.py',
'mkidcontrol/agents/picturec/sim921Agent.py',
'mkidcontrol/agents/xkid/laserflipperAgent.py',
'mkidcontrol/agents/xkid/conexAgent.py',
'mkidcontrol/agents/xkid/focusAgent.py',
'mkidcontrol/agents/xkid/filterwheelAgent.py',
'mkidcontrol/agents/xkid/magnetAgent.py',
'mkidcontrol/agents/xkid/observingAgent.py'],
ext_modules=cythonize(extensions),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: OS Independent",
],
cmdclass={'install': CustomInstall, 'develop': CustomDevelop}
)
# https://docs.python.org/3/distutils/setupscript.html#installing-package-data