forked from HQSquantumsimulations/PyQuEST-cffi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
147 lines (129 loc) · 5.58 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
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
"""Setup for PyQuest-cffi"""
# Copyright 2019 HQS Quantum Simulations GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from setuptools import find_packages, setup, Extension
from setuptools.command.build_ext import build_ext
from setuptools.command import build_py
import subprocess
import os
path = os.path.dirname(os.path.abspath(__file__))
class CustomExtension(Extension):
"""Custom Extension class"""
def __init__(self, name, sourcedir=''):
"""Initialise custom extension"""
Extension.__init__(self, name, sources=[])
self.sourcedir = os.path.abspath(sourcedir)
class CustomBuild(build_ext):
"""Custom C builder"""
def run(self) -> None:
"""Run custom build function"""
try:
subprocess.run(['make', '--version'], check=True)
except OSError:
raise RuntimeError(
"Make must be installed to build the following extensions: "
+ ", ".join(e.name for e in self.extensions))
try:
subprocess.run(['wget', '--version'], check=True)
except OSError:
raise RuntimeError(
"Wget must be installed to build the following extensions: "
+ ", ".join(e.name for e in self.extensions))
try:
subprocess.run(['tar', '--version'], check=True)
except OSError:
raise RuntimeError(
"Tar must be installed to build the following extensions: "
+ ", ".join(e.name for e in self.extensions))
for ext in self.extensions:
self.build_extension(ext)
def build_extension(self, ext: Extension) -> None:
"""Build extension"""
if not ext.name == 'questlib':
pass
else:
old_path = os.getcwd()
# os.path.dirname(os.path.abspath(sys.argv[0]))
print('__file__', __file__)
src_path = os.path.dirname(os.path.realpath(__file__))
print('src_path', src_path)
os.chdir(src_path)
QuEST_release_link = 'https://github.com/QuEST-Kit/QuEST/archive/v3.1.1.tar.gz'
if not os.path.exists(os.path.join(src_path, 'QuEST')):
print('quest_path', os.path.join(src_path, 'QuEST/'))
os.makedirs(os.path.join(src_path, 'QuEST/'))
subprocess.run(['wget',
QuEST_release_link,
'-O',
os.path.join(src_path, 'QuEST.tar.gz')],
check=True)
subprocess.run(['tar',
'-xzvf',
os.path.join(src_path, 'QuEST.tar.gz'),
'-C',
os.path.join(src_path, 'QuEST/'),
'--strip-components=1'],
check=True)
os.chdir(os.path.join(src_path, 'pyquest_cffi/questlib/'))
subprocess.run(['make'], check=True)
#subprocess.run(['python', 'build_quest.py'], check=True)
from build_quest import build_quest_so
build_quest_so()
os.chdir(old_path)
class BuildPyCommand(build_py.build_py):
"""Custom build command."""
def run(self):
"""Run python build"""
self.run_command('build_ext')
build_py.build_py.run(self)
def setup_packages():
"""Setup method"""
with open(os.path.join(path,'README.md')) as file:
readme = file.read()
with open(os.path.join('LICENSE')) as file:
License = file.read()
install_requires = [
'cffi',
'numpy',
'pytest',
]
packages = find_packages(exclude=('docs'))
setup_args = {'name': 'pyquest_cffi',
'description': (
'Provides: Interactive python interface'
+ ' to QuEST quantum simulation toolkit;'
+ ' Compile functionality, create, build and import'
+ ' valid QuEST source code from python'),
'version': '3.1.1',
'long_description': readme,
'packages': packages,
# 'package_dir': {'': 'pyquest_cffi'},
'author': 'HQS Quantum Simulations: Sebastian Zanker, Nicolas Vogt',
'author_email': 'info@quantumsimulations.de',
'url': '',
'download_url': '',
'license': License,
'install_requires': install_requires,
'setup_requires': ['cffi'],
#'include_package_data': True,
'package_data': {'pyquest_cffi': ['questlib/*', 'questlib/*.so']},
'data_files': [("", ["LICENSE", "pyquest_cffi/questlib/makefile"])],
# add custom build_ext command
'cmdclass': {'build_ext': CustomBuild,
'build_py': BuildPyCommand},
'zip_safe': False,
'ext_modules': [CustomExtension('questlib')],
}
setup(**setup_args)
setup_packages()