26
24
sys.path.insert(0, os.path.abspath("."))
28
26
from distutils.core import setup
29
27
from distutils.spawn import find_executable
30
28
from distutils.command import clean, build
32
# pylint: disable-msg=F0401,E0611
33
# pylint: disable=F0401,E0611
34
from DistUtilsExtra.command import check
36
from contrib import check
38
29
from ubuntuone.storageprotocol.context import ssl_cert_location
78
69
clean.clean.run(self)
81
class StorageProtocolCheck(check.check):
82
"""Class to run some lint checks and tests."""
84
description = "validate code with pylint and unit tests"
86
def __load_unittest(self, relpath):
87
"""Load unit tests from a Python module in the given relative path."""
88
assert relpath.endswith(".py"), (
89
"%s does not appear to be a Python module" % relpath)
90
modpath = relpath.replace(os.path.sep, ".")[:-3]
91
module = __import__(modpath, None, None, [""])
93
# If the module has a 'suite' or 'test_suite' function, use that
95
if hasattr(module, "suite"):
97
elif hasattr(module, "test_suite"):
98
return module.test_suite()
100
return unittest.defaultTestLoader.loadTestsFromModule(module)
102
def __collect_tests(self):
103
"""Return the set of unittests."""
104
suite = unittest.TestSuite()
106
# We don't use the dirs variable, so ignore the warning
107
# pylint: disable-msg=W0612
108
# pylint: disable=W0612
109
for root, dirs, files in os.walk("tests"):
111
path = os.path.join(root, file)
113
if file.endswith(".py") and file.startswith("test_"):
114
suite.addTest(self.__load_unittest(path))
120
check.check.run(self)
122
print "\nrunning tests"
123
from twisted.trial.reporter import TreeReporter
124
from twisted.trial.runner import TrialRunner
126
runner = TrialRunner(reporterFactory=TreeReporter, realTimeErrors=True)
128
result = runner.run(self.__collect_tests())
129
if not result.wasSuccessful():
132
def finalize_options(self):
133
"""Overwrite to use a smarter function for finding files."""
134
# check.check does not define attributes at __init__ time, :(
135
# pylint: disable-msg=W0201
136
# pylint: disable=W0201
137
if self.config_file is None:
138
self.config_file = ""
139
if self.exclude_files is None:
140
self.exclude_files = "[]"
141
if self.lint_files is None:
142
exclude = eval(self.exclude_files)
143
self.lint_files = "[" + self._find_files(exclude) + "]"
145
def _find_files(self, exclude_paths):
146
"""Find all Python files under the current tree.
148
This is very similar to the one in check.check, but smarter to not
149
include excluded files.
152
basedir = os.getcwd()
153
baselen = len(basedir) + 1 # + 1 because of last '/'
154
for root, _, files in os.walk(basedir, topdown=False):
156
filepath = os.path.join(root, f)
157
relative = filepath[baselen:]
158
if relative.endswith(".py"):
159
for path in exclude_paths:
160
if relative.startswith(path):
163
pyfiles.append("'" + filepath + "'")
165
return ",".join(pyfiles)
168
72
setup(name='ubuntuone-storage-protocol',
170
74
packages=['ubuntuone',
171
75
'ubuntuone.storageprotocol'],
172
76
data_files=[(ssl_cert_location,