This repository has been archived by the owner on Jun 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
setup.py
140 lines (121 loc) · 4.7 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
from setuptools import setup
from distutils.command.build import build
from distutils.command.build_py import build_py
import os
import sys
import imp
import argparse
with open('README.rst') as readme_file:
README = readme_file.read()
def get_version():
ver_file = None
try:
ver_file, pathname, description = imp.find_module('__version__', ['src/wstool'])
vermod = imp.load_module('__version__', ver_file, pathname, description)
version = vermod.version
return version
finally:
if ver_file is not None:
ver_file.close()
def _resolve_prefix(prefix, type):
# install to outside of system if OS X to avoid issues caused by
# System Integrity Protection on El Caption
# issue: https://github.com/vcstools/wstool/issues/81
osx_system_prefix = '/System/Library/Frameworks/Python.framework/Versions'
if type == 'man':
if prefix == '/usr':
return '/usr/share'
if sys.prefix.startswith(osx_system_prefix):
return '/usr/local/share'
elif type == 'bash_comp':
if prefix == '/usr':
return '/'
if sys.prefix.startswith(osx_system_prefix):
return '/usr/local'
elif type == 'zsh_comp':
if sys.prefix.startswith(osx_system_prefix):
return '/usr/local'
else:
raise ValueError('not supported type')
return prefix
def get_data_files(prefix):
data_files = []
bash_comp_dest = os.path.join(_resolve_prefix(prefix, 'bash_comp'),
'etc/bash_completion.d')
data_files.append((bash_comp_dest, ['completion/wstool-completion.bash']))
zsh_comp_dest = os.path.join(_resolve_prefix(prefix, 'zsh_comp'),
'share/zsh/site-functions')
data_files.append((zsh_comp_dest, ['completion/_wstool',
'completion/wstool-completion.bash']))
return data_files
parser = argparse.ArgumentParser()
parser.add_argument('--prefix', default=None,
help='prefix to install data files')
opts, _ = parser.parse_known_args(sys.argv)
prefix = sys.prefix if opts.prefix == None else opts.prefix
data_files = get_data_files(prefix)
# At present setuptools has no methods to resolve dependencies at build time,
# so we need to check if sphinx is installed.
# See: https://github.com/pypa/pip/issues/2381
try:
from sphinx.setup_command import BuildDoc
HAVE_SPHINX = True
except:
HAVE_SPHINX = False
if HAVE_SPHINX:
class WstoolBuildMan(BuildDoc):
def initialize_options(self):
BuildDoc.initialize_options(self)
self.builder = 'man'
class WstoolBuild(build):
"""Run additional commands before build command"""
def run(self):
self.run_command('build_man')
build.run(self)
class WstoolBuildPy(build_py):
"""Run additional commands before build_py command"""
def run(self):
self.run_command('build_man')
build_py.run(self)
cmdclass = dict(
build=WstoolBuild,
build_py=WstoolBuildPy,
build_man=WstoolBuildMan,
)
man_dest = os.path.join(_resolve_prefix(prefix, 'man'), 'man/man1')
data_files.append((man_dest, ['build/sphinx/man/wstool.1']))
else:
cmdclass = {}
with open(os.path.join(os.path.dirname(__file__), 'requirements.txt')) as requirements:
install_requires = requirements.read().splitlines()
with open(os.path.join(os.path.dirname(__file__), 'requirements-test.txt')) as requirements:
test_required = requirements.read().splitlines()
setup(name='wstool',
version=get_version(),
packages=['wstool'],
package_dir={'': 'src'},
data_files=data_files,
cmdclass=cmdclass,
# rosinstall dependency to be kept in order not to break ros hydro install instructions
install_requires=install_requires,
# extras_require allow pip install .[test]
extras_require={
'test': test_required
},
# tests_require automatically installed when running python setup.py test
tests_require=test_required,
scripts=["scripts/wstool"],
author="Tully Foote",
author_email="[email protected]",
url="http://wiki.ros.org/wstool",
keywords=["ROS"],
classifiers=["Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
"Development Status :: 7 - Inactive",
"License :: OSI Approved :: BSD License",
"Topic :: Software Development :: Version Control"
],
description="workspace multi-SCM commands",
long_description=README,
license="BSD")