-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathsetup.py
52 lines (39 loc) · 1.87 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
###############################################################################
# // SPDX-License-Identifier: Apache-2.0
# // Copyright : JP Morgan Chase & Co
###############################################################################
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import subprocess
import os
import sys
environment_variable_name = "QOKIT_NO_C_ENV"
QOKIT_PYTHON_ONLY = False
QOKIT_NO_C_ENV = False # used for tests only
environment_variable_value = os.environ.get(environment_variable_name, None)
if environment_variable_value is not None:
QOKIT_NO_C_ENV = True
path = "./qokit/fur/c/csim/src/"
sources = [os.path.join(path, "diagonal.c"), os.path.join(path, "fur.c"), os.path.join(path, "qaoa_fur.c")]
extensions = []
if not QOKIT_PYTHON_ONLY:
if sys.platform in ["win32"]:
extensions.append(Extension("simulator", sources=sources, include_dirs=[os.path.join(path, "")], extra_compile_args=["/d2FH4-"]))
elif sys.platform.startswith("darwin"):
extensions.append(Extension("simulator", sources=sources, include_dirs=[os.path.join(path, "")], extra_compile_args=["-Xpreprocessor"]))
else:
extensions.append(Extension("simulator", sources=sources, include_dirs=[os.path.join(path, "")]))
class SimulatorBuild(build_ext):
def run(self):
subprocess.call(["make", "clean", "-C", path])
try:
if not QOKIT_PYTHON_ONLY:
if QOKIT_NO_C_ENV:
raise Exception("No C/C++ enviroment setup")
subprocess.call(["make", "-C", path])
super().run
except Exception as e:
print("No C/C++ enviroment setup to compile the C simulator. Installing Python Simulator")
with open("README.md", "r") as f:
long_description = f.read()
setup(ext_modules=extensions, cmdclass={"build_ext": SimulatorBuild})