-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.py
executable file
·126 lines (100 loc) · 3.85 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
#!/usr/bin/env python2.7
# Copyright 2016 Ifwe Inc.
#
# 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 setup
from setuptools.command.test import test as TestCommand
import sys
import os, os.path
import fnmatch
# Let's add this later
# long_description = open('README.txt').read()
# Get version of project
import tds.version
class PyTest(TestCommand):
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = [self.test_suite]
def run_tests(self):
#import here, cause outside the eggs aren't loaded
import pytest
errno = pytest.main(self.test_args)
if errno != 0:
raise SystemExit("Test failures (errno=%d)", errno)
def discover_packages(base):
'''
Discovers all sub-packages for a base package
Note: does not work with namespaced packages (via pkg_resources or similar)
'''
import importlib
mod = importlib.import_module(base)
mod_fname = mod.__file__
mod_dirname = os.path.normpath(os.path.dirname(mod_fname))
for root, _dirnames, filenames in os.walk(mod_dirname):
for _fname in fnmatch.filter(filenames, '__init__.py'):
yield '.'.join(os.path.relpath(root).split(os.sep))
REQ_BLACKLIST = []
if sys.version_info > (2, 7) or sys.version_info > (3, 2):
REQ_BLACKLIST.extend(['argparse', 'ordereddict'])
def reqfile_read(fname):
with open(fname, 'r') as reqfile:
reqs = reqfile.read()
return filter(None, reqs.strip().splitlines())
def load_requirements(fname):
requirements = []
for req in reqfile_read(fname):
if 'git+' in req:
req = '>='.join(req.rsplit('=')[-1].split('-', 3)[:2])
if any(req.startswith(bl) for bl in REQ_BLACKLIST):
continue
if req.startswith('--'):
continue
requirements.append(req)
return requirements
REQUIREMENTS = {}
REQUIREMENTS['install'] = load_requirements('requirements.txt')
REQUIREMENTS['tests'] = load_requirements('requirements-dev.txt')
def load_github_dependency_links(fname):
dep_links = []
for req in reqfile_read(fname):
if 'git+' in req and 'github' in req: # not exactly precise...
url, ref_egg = req.split('git+', 1)[-1].rsplit('@', 1)
dep_links.append(url + '/tarball/' + ref_egg)
return dep_links
DEPENDENCY_LINKS = load_github_dependency_links('requirements.txt')
DEPENDENCY_LINKS.extend(load_github_dependency_links('requirements-dev.txt'))
setup_args = dict(
name='TDS',
version=tds.version.__version__,
description='Tagged Deployment System',
# long_description = long_description,
author='Kenneth Lareau',
author_email='[email protected]',
license='Apache License, Version 2.0',
packages=list(discover_packages('tds')),
install_requires=REQUIREMENTS['install'],
entry_points={
'console_scripts': [
'tds = tds.scripts.tds_prog:main',
'tds_installer = tds.scripts.tds_installer:daemon_main',
'unvalidated_deploy_check = tds.scripts.unvalidated_deploy_check:main',
'update_deploy_repo = tds.scripts.update_deploy_repo:daemon_main',
]
},
test_suite='tests',
tests_require=REQUIREMENTS['install'] + REQUIREMENTS['tests'],
dependency_links=DEPENDENCY_LINKS,
cmdclass=dict(test=PyTest)
)
if __name__ == '__main__':
setup(**setup_args)