forked from QuTech-Delft/OpenQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
120 lines (100 loc) · 3.45 KB
/
setup.py
File metadata and controls
120 lines (100 loc) · 3.45 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
import os
import re
from setuptools import setup
from shutil import copyfile
import subprocess
from sys import platform
rootDir = os.path.dirname(os.path.realpath(__file__))
srcDir = os.path.join(rootDir, "src")
buildDir = os.path.join(rootDir, "cbuild")
clibDir = os.path.join(buildDir, "swig")
nprocs = 1
env_var_nprocs = os.environ.get('NPROCS')
if (env_var_nprocs != None):
nprocs = int(env_var_nprocs)
print('Using {} processes for compilation'.format(nprocs))
if nprocs == 1:
print('For faster compilation by N processes, set environment variable NPROCS=N')
print('For example: NPROCS=4 python3 setup.py install --user')
if not os.path.exists(buildDir):
os.makedirs(buildDir)
os.chdir(buildDir)
if platform == "linux" or platform == "linux2":
print('Detected Linux OS, installing openql ... ')
cmd = 'cmake ..'
proc = subprocess.Popen(cmd, shell=True)
proc.communicate()
cmd = 'make -j{}'.format(nprocs)
proc = subprocess.Popen(cmd, shell=True)
proc.communicate()
clibname = "_openql.so"
elif platform == "darwin":
print('Detected OSX, installing openql ... ')
os.environ["MACOSX_DEPLOYMENT_TARGET"] = "10.10"
cmd = 'cmake ..'
proc = subprocess.Popen(cmd, shell=True)
proc.communicate()
cmd = 'make -j{}'.format(nprocs)
proc = subprocess.Popen(cmd, shell=True)
proc.communicate()
clibname = "_openql.so"
elif platform == "win32":
print('Detected Windows OS, installing openql ... ')
cmd = 'cmake -G "NMake Makefiles" ..'
proc = subprocess.Popen(cmd, shell=True)
proc.communicate()
# cmd = 'nmake /M/P{}'.format(nprocs)
cmd = 'nmake'
proc = subprocess.Popen(cmd, shell=True)
proc.communicate()
clibname = "_openql.pyd"
else:
print('Unknown/Unsupported OS !!!')
clib = os.path.join(clibDir, clibname)
swigDir = os.path.join(rootDir, "swig", "openql")
clibSwig = os.path.join(swigDir, clibname)
copyfile(clib, clibSwig)
copyfile(os.path.join(clibDir, "openql.py"),
os.path.join(swigDir, "openql.py"))
os.chdir(rootDir)
def get_version(verbose=0):
""" Extract version information from source code """
matcher = re.compile('[\t ]*#define[\t ]+OPENQL_VERSION_STRING[\t ]+"(.*)"')
version = None
try:
with open(os.path.join(srcDir, 'version.h'), 'r') as f:
for ln in f:
m = matcher.match(ln)
if m:
version = m.group(1)
break;
except Exception as E:
print(E)
version = 'none'
if verbose:
print('get_version: %s' % version)
return version
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
try:
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
class bdist_wheel(_bdist_wheel):
def finalize_options(self):
_bdist_wheel.finalize_options(self)
self.root_is_pure = False
except ImportError:
bdist_wheel = None
setup(name='qutechopenql',
version=get_version(),
description='OpenQL Python Package',
long_description=read('README.md'),
author='Nader Khammassi and Imran Ashraf',
author_email='nader.khammassi@gmail.com, iimran.aashraf@gmail.com',
url='https://github.com/QE-Lab/OpenQL',
license=read('LICENSE'),
packages=['openql'],
cmdclass={'bdist_wheel': bdist_wheel},
package_dir={'': 'swig'},
include_package_data=True,
package_data={'openql': [clibSwig]},
zip_safe=False)