-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsetup.py
170 lines (144 loc) · 6.06 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env python
# -*- Python -*-
# -*- coding: utf-8 -*-
"""rtctree
Copyright (C) 2009-2015
Geoffrey Biggs
RT-Synthesis Research Group
Intelligent Systems Research Institute,
National Institute of Advanced Industrial Science and Technology (AIST),
Japan
All rights reserved.
Licensed under the GNU Lesser General Public License version 3.
http://www.gnu.org/licenses/lgpl-3.0.en.html
rtctree install script.
"""
from distutils.command.build import build
from distutils.command.install import install
from distutils.core import Command
from distutils import errors
from distutils import log
import os
import os.path
import setuptools
import shutil
import subprocess
class BuildIDL(Command):
description = 'generate Python stubs from the IDL files'
user_options = [
('omniidl=', 'o', 'omniidl compiler executable'),
('stubs-dir=', 's', 'directory to generate stubs in'),
('idl-dir=', 'i', 'directory to place IDL files in'),
]
def initialize_options(self):
self.omniidl = None
self.stubs_dir = None
self.idl_dir = None
self.build_lib = None
def finalize_options(self):
if not self.omniidl:
self.omniidl = 'omniidl'
if not self.stubs_dir:
self.set_undefined_options('build', ('build_base', 'stubs_dir'))
self.stubs_dir = os.path.join(self.stubs_dir, 'stubs')
if not self.idl_dir:
self.set_undefined_options('build', ('build_base', 'idl_dir'))
self.idl_dir = os.path.join(self.idl_dir, 'idl')
self.idl_src_dir = os.path.join(os.getcwd(), 'idl')
self.set_undefined_options('build', ('build_lib', 'build_lib'))
def compile_one_idl(self, idl_f):
outdir_param = '-C' + self.stubs_dir
pkg_param = '-Wbpackage=rtctree.rtc'
idl_path_param = '-Iidl'
p = subprocess.Popen([self.omniidl, '-bpython', idl_path_param,
outdir_param, pkg_param, idl_f],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()
if p.returncode != 0:
raise errors.DistutilsExecError(
'Failed to compile IDL file {}\nStdout:\n{}\n---\nStderr:\n'
'{}'.format(idl_f, stdout, stderr))
def compile_idl(self):
log.info('Generating Python stubs from IDL files')
self.mkpath(self.stubs_dir)
idl_files = [os.path.join(self.idl_src_dir, f)
for f in os.listdir(self.idl_src_dir)
if os.path.splitext(f)[1] == '.idl']
for f in idl_files:
self.compile_one_idl(f)
def move_stubs(self):
stub_dest = os.path.join(self.build_lib, 'rtctree', 'rtc')
log.info('Moving stubs to package directory {}'.format(stub_dest))
self.copy_tree(os.path.join(self.stubs_dir, 'rtctree', 'rtc'),
stub_dest)
def copy_idl(self):
log.info('Copying IDL files')
self.mkpath(self.idl_dir)
idl_files = [os.path.join(self.idl_src_dir, f)
for f in os.listdir(self.idl_src_dir)
if os.path.splitext(f)[1] == '.idl']
for f in idl_files:
shutil.copy(f, self.idl_dir)
def run(self):
self.compile_idl()
self.move_stubs()
self.copy_idl()
class InstallIDL(Command):
description = 'install the Python stubs generated from IDL files'
user_options = [
('install-dir=', 'd', 'directory to install stubs to'),
('build-dir=', 'b', 'build directory (where to install from'),
('force', 'f', 'force installation (overwrite existing files)'),
('skip-build', None, 'skip the build steps'),
]
boolean_options = ['force', 'skip-build']
def initialize_options(self):
self.install_dir = None
self.install_dir = None
self.build_dir = None
self.force = None
self.skip_build = None
def finalize_options(self):
self.set_undefined_options('build', ('build_base', 'build_dir'))
self.set_undefined_options('install', ('install_lib', 'install_dir'),
('force', 'force'),
('skip_build', 'skip_build'))
def run(self):
if not self.skip_build:
self.run_command('build_idl')
# Copy the IDL files to rtctree/data/idl
self.outfiles = self.copy_tree(
os.path.join(self.build_dir, 'idl'),
os.path.join(self.install_dir, 'rtctree', 'data', 'idl'))
def get_outputs(self):
return self.outfiles or []
build.sub_commands.append(('build_idl', None))
install.sub_commands.append(('install_idl', None))
setuptools.setup(name='rtctree',
version='4.2.0',
description='API for interacting with running RT Components '
'and managing RTM-based systems.',
long_description='API for interacting with running RT '
'Components and managing RTM-based systems.',
author='Geoffrey Biggs',
author_email='[email protected]',
url='http://github.com/gbiggs/rtctree',
license='LGPL3',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU Lesser General Public '
'License v3 (LGPLv3)',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.7',
'Topic :: Software Development',
],
packages=setuptools.find_packages(),
include_package_data=True,
cmdclass={
'build_idl': BuildIDL, 'install_idl': InstallIDL
},
zip_safe=True
)
# vim: set expandtab tabstop=8 shiftwidth=4 softtabstop=4 textwidth=79