-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·186 lines (153 loc) · 5.27 KB
/
setup.py
File metadata and controls
executable file
·186 lines (153 loc) · 5.27 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/env python3
import os, platform, shutil, sys, subprocess, glob
from distutils.command.bdist import bdist as _bdist
from distutils.command.sdist import sdist as _sdist
from distutils.command.build import build as _build
from distutils.command.clean import clean as _clean
from setuptools.command.egg_info import egg_info as _egg_info
import distutils.cmd
import distutils.log
from setuptools import setup, Extension, find_packages
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
debug = 'DQCSIM_DEBUG' in os.environ
target_dir = os.getcwd() + "/target"
py_target_dir = target_dir + "/python"
include_dir = target_dir + "/include"
output_dir = target_dir + ("/debug" if debug else "/release")
build_dir = py_target_dir + "/build"
dist_dir = py_target_dir + "/dist"
def build_tests():
with open('python/dqcsim_cqasm/test.py', 'w') as f:
f.write("""
# GENERATED FILE!
import unittest
from dqcsim.plugin import *
from dqcsim.host import *
import tempfile
import os
class Tests(unittest.TestCase):
_indentation_error = None
""")
for filename in glob.glob('tests/valid/**/*.qasm', recursive=True):
name = '_'.join(filename.split(os.sep)[2:]).split('.')[0].replace('-', '_')
with open(filename, 'r') as fc:
cqasm = fc.read()
f.write("""
def test_{name}(self):
with tempfile.TemporaryDirectory() as tmpdir:
fname = tmpdir + os.sep + 'test_{name}.cq'
with open(fname, 'w') as f:
f.write({cqasm})
with Simulator(fname, 'null') as sim:
sim.run()
""".format(name=name, cqasm=repr(cqasm)))
for filename in glob.glob('tests/invalid/**/*.qasm', recursive=True):
name = '_'.join(filename.split(os.sep)[2:]).split('.')[0].replace('-', '_')
with open(filename, 'r') as fc:
cqasm = fc.read()
f.write("""
def test_{name}(self):
with tempfile.TemporaryDirectory() as tmpdir:
fname = tmpdir + os.sep + 'test_{name}.cq'
with open(fname, 'w') as f:
f.write({cqasm})
with self.assertRaises(RuntimeError):
with Simulator(fname, 'null') as sim:
sim.run()
""".format(name=name, cqasm=repr(cqasm)))
def read(fname):
with open(os.path.join(os.path.dirname(__file__), fname)) as f:
return f.read()
class clean(_clean):
def run(self):
_clean.run(self)
shutil.rmtree(target_dir)
class build(_build):
def initialize_options(self):
_build.initialize_options(self)
self.build_base = build_dir
def run(self):
from plumbum import local, FG
build_tests()
local['mkdir']("-p", output_dir)
if platform.system() == "Darwin":
# brew install flex bison
local.env["PATH"] = "/usr/local/opt/flex/bin/:/usr/local/opt/bison/bin:" + local.env["PATH"]
# brew install llvm
local.env["CXX"] = "/usr/local/opt/llvm/bin/clang++"
with local.cwd(output_dir):
if debug:
local['cmake']['../..']['-DCMAKE_BUILD_TYPE=Debug'] & FG
else:
local['cmake']['../..'] & FG
local['make']['-j']['4'] & FG
_build.run(self)
class bdist_wheel(_bdist_wheel):
def finalize_options(self):
_bdist_wheel.finalize_options(self)
self.root_is_pure = False
def get_tag(self):
python, abi, plat = _bdist_wheel.get_tag(self)
python, abi = 'py3', 'none'
return python, abi, plat
class bdist(_bdist):
def finalize_options(self):
_bdist.finalize_options(self)
self.dist_dir = dist_dir
class sdist(_sdist):
def finalize_options(self):
_sdist.finalize_options(self)
self.dist_dir = dist_dir
class egg_info(_egg_info):
def initialize_options(self):
_egg_info.initialize_options(self)
self.egg_base = py_target_dir
setup(
name = 'dqcsim-cqasm',
version = '0.0.3',
author = 'Quantum Computer Architectures, Quantum & Computer Engineering, QuTech, Delft University of Technology',
author_email = '',
description = 'A DQCsim frontend for cQASM files',
license = "Apache-2.0",
url = "https://github.com/QE-Lab/dqcsim-cqasm",
project_urls = {
"Source Code": "https://github.com/QE-Lab/dqcsim-cqasm",
},
long_description = read('README.md'),
long_description_content_type = 'text/markdown',
classifiers = [
"License :: OSI Approved :: Apache Software License",
"Operating System :: POSIX :: Linux",
"Programming Language :: C",
"Programming Language :: C++",
"Topic :: Scientific/Engineering"
],
data_files = [
('bin', [
output_dir + '/dqcsfecq',
]),
],
packages = find_packages('python'),
package_dir = {
'': 'python',
},
cmdclass = {
'bdist': bdist,
'bdist_wheel': bdist_wheel,
'build': build,
'clean': clean,
'egg_info': egg_info,
'sdist': sdist,
},
setup_requires = [
'plumbum',
],
install_requires = [
'dqcsim',
],
tests_require = [
'nose',
],
test_suite = 'nose.collector',
zip_safe = False,
)