~ubuntuone-control-tower/ubuntuone-storage-protocol/stable-1-6

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Tarmac
  • Author(s): Rodney Dawes
  • Date: 2010-11-16 15:10:48 UTC
  • mfrom: (121.1.4 use-packages)
  • Revision ID: tarmac-20101116151048-b0e20j7lorb4yhe1
Switch to using packaged mocker and ubuntuone-dev-tools
Use pyflakes with u1lint and also run pep8
Fix a lot of pylint/pyflakes/pep8 errors

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import sys
22
22
import subprocess
23
23
 
24
 
import unittest
25
 
 
26
24
sys.path.insert(0, os.path.abspath("."))
27
25
 
28
26
from distutils.core import setup
29
27
from distutils.spawn import find_executable
30
28
from distutils.command import clean, build
31
 
try:
32
 
    # pylint: disable-msg=F0401,E0611
33
 
    # pylint: disable=F0401,E0611
34
 
    from DistUtilsExtra.command import check
35
 
except ImportError:
36
 
    from contrib import check
37
 
 
38
29
from ubuntuone.storageprotocol.context import ssl_cert_location
39
30
 
40
31
 
78
69
        clean.clean.run(self)
79
70
 
80
71
 
81
 
class StorageProtocolCheck(check.check):
82
 
    """Class to run some lint checks and tests."""
83
 
 
84
 
    description = "validate code with pylint and unit tests"
85
 
 
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, [""])
92
 
 
93
 
        # If the module has a 'suite' or 'test_suite' function, use that
94
 
        # to load the tests.
95
 
        if hasattr(module, "suite"):
96
 
            return module.suite()
97
 
        elif hasattr(module, "test_suite"):
98
 
            return module.test_suite()
99
 
        else:
100
 
            return unittest.defaultTestLoader.loadTestsFromModule(module)
101
 
 
102
 
    def __collect_tests(self):
103
 
        """Return the set of unittests."""
104
 
        suite = unittest.TestSuite()
105
 
 
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"):
110
 
            for file in files:
111
 
                path = os.path.join(root, file)
112
 
 
113
 
                if file.endswith(".py") and file.startswith("test_"):
114
 
                    suite.addTest(self.__load_unittest(path))
115
 
 
116
 
        return suite
117
 
 
118
 
    def run(self):
119
 
        """Do the checks."""
120
 
        check.check.run(self)
121
 
 
122
 
        print "\nrunning tests"
123
 
        from twisted.trial.reporter import TreeReporter
124
 
        from twisted.trial.runner import TrialRunner
125
 
 
126
 
        runner = TrialRunner(reporterFactory=TreeReporter, realTimeErrors=True)
127
 
 
128
 
        result = runner.run(self.__collect_tests())
129
 
        if not result.wasSuccessful():
130
 
            sys.exit(1)
131
 
 
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) + "]"
144
 
 
145
 
    def _find_files(self, exclude_paths):
146
 
        """Find all Python files under the current tree.
147
 
 
148
 
        This is very similar to the one in check.check, but smarter to not
149
 
        include excluded files.
150
 
        """
151
 
        pyfiles = []
152
 
        basedir = os.getcwd()
153
 
        baselen = len(basedir) + 1   # + 1 because of last '/'
154
 
        for root, _, files in os.walk(basedir, topdown=False):
155
 
            for f in files:
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):
161
 
                            break
162
 
                    else:
163
 
                        pyfiles.append("'" + filepath + "'")
164
 
        pyfiles.sort()
165
 
        return ",".join(pyfiles)
166
 
 
167
 
 
168
72
setup(name='ubuntuone-storage-protocol',
169
 
      version='1.4.0',
 
73
      version='1.5',
170
74
      packages=['ubuntuone',
171
75
                'ubuntuone.storageprotocol'],
172
76
      data_files=[(ssl_cert_location,
175
79
 
176
80
      cmdclass={
177
81
        'build': StorageProtocolBuild,
178
 
        'clean': StorageProtocolClean,
179
 
        'check': StorageProtocolCheck},
 
82
        'clean': StorageProtocolClean},
180
83
      )