-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_dev.py
More file actions
201 lines (166 loc) · 7.51 KB
/
Copy pathsetup_dev.py
File metadata and controls
201 lines (166 loc) · 7.51 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
"""
Mantid PyVDrive
===============
A PyQt-based version of the PyVDrive program
based on Mantid (http://www.mantidproject.org).
"""
from __future__ import print_function
import os
from setuptools.command.build_py import build_py as _build_py
from setuptools import find_packages, setup
from subprocess import check_call
import sys
from py4circle import __project_url__, __version__
# ==============================================================================
# Constants
# ==============================================================================
NAME = 'py4circle'
THIS_DIR = os.path.dirname(__file__)
# ==============================================================================
# Package requirements helper
# ==============================================================================
def read_requirements_from_file(filepath):
'''Read a list of requirements from the given file and split into a
list of strings. It is assumed that the file is a flat
list with one requirement per line.
:param filepath: Path to the file to read
:return: A list of strings containing the requirements
'''
with open(filepath, 'rU') as req_file:
return req_file.readlines()
def get_data_files():
"""Return data_files in a platform dependent manner"""
if sys.platform.startswith('linux'):
data_files = [('share/applications', ['scripts/Lava.desktop']),
('share/pixmaps', ['resources/images/Lava_logo.png'])]
else:
data_files = []
return data_files
# ==============================================================================
# Custom distutils build & install commands
# ==============================================================================
class build_py(_build_py):
description = "build pure python + qt related resources (.uic and .qrc and .pyc)"
user_options = _build_py.user_options + [
('inplace', 'i', "build inplace and not to build directory")
]
boolean_options = _build_py.boolean_options + ['inplace']
PACKAGE = NAME
def initialize_options(self):
_build_py.initialize_options(self)
self.inplace = False
def finalize_options(self):
_build_py.finalize_options(self)
self.distribution.packages.append(NAME)
def compile_src(self, src, dest):
compiler = self.get_compiler(src)
if not compiler:
return
dir = os.path.dirname(dest)
self.mkpath(dir)
sys.stdout.write("compiling %s -> %s\n" % (src, dest))
try:
compiler(src, dest)
except Exception as e:
sys.stderr.write('[Error] {}\n'.format(str(e)))
def run(self):
from distutils.dep_util import newer
for dirpath, _, filenames in os.walk(self.get_package_dir(self.PACKAGE)):
package = dirpath.split(os.sep)
for filename in filenames:
src_file, module_file = self.get_inout(package, dirpath, filename)
if newer(src_file, module_file):
self.compile_src(src_file, module_file)
_build_py.run(self)
def get_outputs(self, include_bytecode=1):
'''Return the list of outputs that would be generated
if this command were run
'''
outputs = _build_py.get_outputs(self, include_bytecode)
for dirpath, _, filenames in os.walk(self.get_package_dir(self.PACKAGE)):
package = dirpath.split(os.sep)
for filename in filenames:
_, module_file = self.get_inout(package, dirpath, filename)
outputs.append(module_file)
if include_bytecode:
if self.compile:
outputs.append(module_file + "c")
if self.optimize > 0:
outputs.append(module_file + "o")
return outputs
def get_inout(self, package, dirpath, filename):
src_file = os.path.join(dirpath, filename)
module_name = self.get_module_name(filename)
if self.inplace:
if self.is_compilation_required(src_file):
module_file = os.path.join(dirpath, module_name) + '.py'
else:
module_file = src_file
else:
module_file = self.get_module_outfile(self.build_lib, package, module_name)
return src_file, module_file
def is_compilation_required(self, source_file):
'''Is something above a simply copy required'''
return self.get_compiler(source_file) is not None
@staticmethod
def compile_ui(ui_file, py_file):
from PyQt5 import uic
with open(py_file, 'w') as fp:
uic.compileUi(ui_file, fp)
@staticmethod
def compile_qrc(qrc_file, py_file):
check_call(['pyrcc4', qrc_file, '-o', py_file])
def get_compiler(self, source_file):
name = 'compile_' + source_file.rsplit(os.extsep, 1)[-1]
return getattr(self, name, None)
@staticmethod
def get_module_name(src_filename):
name, ext = os.path.splitext(src_filename)
return {'.qrc': '%s_rc', '.ui': '%s_ui'}.get(ext, '%s') % name
# ==============================================================================
# Setup arguments
# ==============================================================================
setup_args = dict(name=NAME,
version=__version__,
description='Visualise and slice data from Mantid',
author='The Mantid Project',
author_email='mantid-help@mantidproject.org',
url=__project_url__,
keywords=['PyQt5'],
packages=find_packages(exclude=["misc"]),
data_files=get_data_files(),
# Fool setup.py to running the tests on a built copy (this feels like a hack)
use_2to3=True,
# Install this as a directory
zip_safe=False,
classifiers=['Operating System :: MacOS',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 2.7',
'Development Status :: 4 - Beta',
'Topic :: Scientific/Engineering'],
cmdclass={'build_py': build_py})
# ==============================================================================
# Setuptools deps
# ==============================================================================
# Running setup command requires the following dependencies
setup_args['setup_requires'] = read_requirements_from_file(os.path.join(THIS_DIR, 'setup-requirements.txt'))
# User installation requires the following dependencies
# PyQt5 cannot be installed from pip so they cannot be added here
install_requires = setup_args['install_requires'] = \
read_requirements_from_file(os.path.join(THIS_DIR, 'install-requirements.txt'))
# Testing requires
setup_args['tests_require'] = read_requirements_from_file(os.path.join(THIS_DIR, 'test-requirements.txt')) \
+ install_requires
# Startup scripts - these use the mantidpython wrappers so we cannot
# go through the entry_points mechanism
scripts = ['scripts/four']
# if os.name == 'nt':
# scripts.append('scripts/mslice.bat')
# else:
# scripts.append('scripts/mslice')
setup_args['scripts'] = scripts
# ==============================================================================
# Main setup
# ==============================================================================
setup(**setup_args)