-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
executable file
·148 lines (103 loc) · 4.19 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
#!/usr/bin/env python
import os, sys, subprocess
from setuptools import setup, find_packages, Command
PYPACKAGE = 'lafsgit'
INSTALL_REQUIRES = [
'twisted >= 14.0',
'mock >= 1.0.1',
]
def main(args = sys.argv[1:]):
setup(
name='git-remote-lafs',
description='Push and pull git repositories into transparently laid out tahoe-lafs storage.',
version='0.1.dev0',
author='Nathan Wilcox',
author_email='[email protected]',
license='GPLv3',
url='https://github.com/nejucomo/git-remote-lafs',
packages=find_packages(),
entry_points={
'console_scripts': [
'git-remote-lafs = lafsgit.main:main',
],
},
install_requires=INSTALL_REQUIRES,
cmdclass={
'test': TestWithCoverageAndTrialInAVirtualEnvCommand,
'test_integration': TestIntegrationCommand,
},
)
class VirtualEnvCommandBase (Command):
"""A base command class for setup subcommands to be run within a virtual env."""
TestToolRequirements = [] # Subclasses should override this with tools they require.
user_options = [
]
def __init__(self, dist):
Command.__init__(self, dist)
join = os.path.join
self.basedir = os.path.dirname(os.path.abspath(__file__))
self.pypkg = join(self.basedir, PYPACKAGE)
self.testdir = join(self.basedir, 'build', 'test')
self.venvdir = join(self.testdir, 'venv')
self.bindir = os.path.join(self.venvdir, 'bin')
self.trial = os.path.join(self.bindir, 'trial')
self.pip = os.path.join(self.bindir, 'pip')
self.coverage = os.path.join(self.bindir, 'coverage')
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
self._initialize_virtualenv()
self._install_testing_tools()
# Coverage and trial dump things into cwd, so cd:
os.chdir(self.testdir)
self.run_within_virtualenv()
def _initialize_virtualenv(self):
run('virtualenv', '--no-site-packages', self.venvdir)
def _install_testing_tools(self):
reqspath = os.path.join(self.testdir, 'test-tool-requirements.txt')
with file(reqspath, 'w') as f:
for req in INSTALL_REQUIRES + self.TestToolRequirements:
f.write(req + '\n')
run(self.pip, 'install', '--use-mirrors', '--requirement', reqspath)
class TestWithCoverageAndTrialInAVirtualEnvCommand (VirtualEnvCommandBase):
"""Run unit tests with coverage analysis and reporting in a virtualenv.
Note: A design goal of this is that all generated files (except for
.pyc files) will appear under ./build so that .gitignore can contain
only ./build and *.pyc, and a clean operation is merely 'rm -r ./build'.
"""
description = __doc__
# Internal settings:
TestToolRequirements = [
'coverage == 3.7.1',
]
def run_within_virtualenv(self):
self._update_python_path()
try:
run(self.coverage, 'run', '--branch', '--source', self.pypkg, self.trial, PYPACKAGE)
finally:
run(self.coverage, 'html')
def _update_python_path(self):
if 'PYTHONPATH' in os.environ:
os.environ['PYTHONPATH'] = '{0}:{1}'.format(self.basedir, os.environ['PYTHONPATH'])
else:
os.environ['PYTHONPATH'] = self.basedir
class TestIntegrationCommand (VirtualEnvCommandBase):
"""Run live git with an installed git-remote-lafs on the commandline against a lafs-giab configuration."""
description = __doc__
def run_within_virtualenv(self):
url = 'lafs::foo-not-yet-implemented'
run(self.pip, 'uninstall', '--yes', 'git-remote-lafs')
run(self.pip, 'install', self.basedir)
os.environ['PATH'] = '{0}:{1}'.format(self.bindir, os.environ['PATH'])
run('git', 'push', url, url)
def run(*args):
print 'Running: {0!r}'.format(args)
try:
subprocess.check_call(args, shell=False)
except subprocess.CalledProcessError, e:
print 'Process exited with {0!r} exit status.'.format(e.returncode)
raise
if __name__ == '__main__':
main()