ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/WMCORE/setup.py
Revision: 1.33
Committed: Thu Sep 10 10:11:03 2009 UTC (15 years, 7 months ago) by metson
Content type: text/x-python
Branch: MAIN
Changes since 1.32: +4 -2 lines
Log Message:
Trying to get some easier to read ouptut from the lint...

File Contents

# User Rev Content
1 fvlingen 1.1 #!/usr/bin/env python
2 metson 1.21 from distutils.core import setup, Command
3     from unittest import TextTestRunner, TestLoader, TestSuite
4     from glob import glob
5     from os.path import splitext, basename, join as pjoin, walk
6 metson 1.30 import os, sys
7 sfoulkes 1.29 try:
8     from pylint import lint
9 metson 1.33 PyLinter
10 sfoulkes 1.29 except:
11     pass
12 fvlingen 1.1
13 metson 1.22 """
14     Build, clean and test the WMCore package.
15     """
16    
17 metson 1.21 class TestCommand(Command):
18 metson 1.22 """
19     Handle setup.py test with this class - walk through the directory structure
20     and build up a list of tests, then build a test suite and execute it.
21    
22     TODO: Pull database URL's from environment, and skip tests where database
23     URL is not present (e.g. for a slave without Oracle connection)
24     """
25 metson 1.21 user_options = [ ]
26    
27     def initialize_options(self):
28     self._dir = os.getcwd()
29    
30     def finalize_options(self):
31     pass
32    
33     def run(self):
34     '''
35 metson 1.25 Finds all the tests modules in test/python/WMCore_t, and runs them.
36 metson 1.21 '''
37     testfiles = [ ]
38 metson 1.26
39     # Add the test and src directory to the python path
40     testspypath = '/'.join([self._dir, 'test/python/'])
41     srcpypath = '/'.join([self._dir, 'src/python/'])
42 metson 1.30 sys.path.append(testspypath)
43     sys.path.append(srcpypath)
44    
45 metson 1.21 # Walk the directory tree
46     for dirpath, dirnames, filenames in os.walk('./test/python/WMCore_t'):
47     # skipping CVS directories and their contents
48     pathelements = dirpath.split('/')
49     if not 'CVS' in pathelements:
50     # to build up a list of file names which contain tests
51     for file in filenames:
52     if file not in ['__init__.py']:
53     if file.endswith('_t.py'):
54     testmodpath = pathelements[3:]
55     testmodpath.append(file.replace('.py',''))
56     testfiles.append('.'.join(testmodpath))
57    
58     testsuite = TestSuite()
59     for test in testfiles:
60     try:
61     testsuite.addTest(TestLoader().loadTestsFromName(test))
62     except Exception, e:
63     print "Could not load %s test - fix it!\n %s" % (test, e)
64     print "Running %s tests" % testsuite.countTestCases()
65    
66     t = TextTestRunner(verbosity = 1)
67 metson 1.32 result = t.run(testsuite)
68     if not result.wasSuccessful():
69     sys.exit("Tests unsuccessful. There were %s failures and %s errors"\
70     % (len(result.failures), len(result.errors)))
71    
72 metson 1.26
73 metson 1.21 class CleanCommand(Command):
74 metson 1.22 """
75     Clean up (delete) compiled files
76     """
77 metson 1.21 user_options = [ ]
78    
79     def initialize_options(self):
80     self._clean_me = [ ]
81     for root, dirs, files in os.walk('.'):
82     for f in files:
83     if f.endswith('.pyc'):
84     self._clean_me.append(pjoin(root, f))
85    
86     def finalize_options(self):
87     pass
88    
89     def run(self):
90     for clean_me in self._clean_me:
91     try:
92     os.unlink(clean_me)
93     except:
94     pass
95    
96 metson 1.23 class LintCommand(Command):
97 metson 1.24 """
98     Lint all files in the src tree
99    
100     TODO: better format the test results, get some global result, make output
101     more buildbot friendly.
102     """
103    
104 metson 1.23 user_options = [ ]
105    
106     def initialize_options(self):
107     self._dir = os.getcwd()
108    
109     def finalize_options(self):
110     pass
111    
112     def run(self):
113     '''
114     Find the code and run lint on it
115     '''
116     files = [ ]
117 metson 1.26
118     srcpypath = '/'.join([self._dir, 'src/python/'])
119 metson 1.30 sys.path.append(srcpypath)
120 metson 1.26
121 metson 1.23 # Walk the directory tree
122     for dirpath, dirnames, filenames in os.walk('./src/python/'):
123     # skipping CVS directories and their contents
124     pathelements = dirpath.split('/')
125 metson 1.33 result = []
126 metson 1.23 if not 'CVS' in pathelements:
127     # to build up a list of file names which contain tests
128     for file in filenames:
129 metson 1.27 if file.endswith('.py'):
130     filepath = '/'.join([dirpath, file])
131     files.append(filepath)
132     # run individual tests as follows
133     try:
134 metson 1.33 score = lint.Run(['--rcfile=standards/.pylintrc',
135 metson 1.28 '--output-format=parseable',
136     filepath])
137 metson 1.33 result.append((file, score))
138 metson 1.27 except Exception, e:
139     print "Couldn't lint %s\n%s %s" % (file, e, type(e))
140 metson 1.23 # Could run a global test as:
141     #input = ['--rcfile=standards/.pylintrc']
142     #input.extend(files)
143 metson 1.32 #lint.Run(input)
144     print result
145 metson 1.23
146 metson 1.22 def getPackages(package_dirs = []):
147     packages = []
148     for dir in package_dirs:
149     for dirpath, dirnames, filenames in os.walk('./%s' % dir):
150     # Exclude things here
151     if dirpath not in ['./src/python/', './src/python/IMProv']:
152     pathelements = dirpath.split('/')
153     if not 'CVS' in pathelements:
154     path = pathelements[3:]
155     packages.append('.'.join(path))
156     return packages
157    
158     package_dir = {'WMCore': 'src/python/WMCore',
159     'WMComponent' : 'src/python/WMComponent',
160     'WMQuality' : 'src/python/WMQuality'}
161    
162     setup (name = 'wmcore',
163     version = '1.0',
164 metson 1.23 cmdclass = { 'test': TestCommand,
165     'clean': CleanCommand,
166     'lint': LintCommand },
167 metson 1.22 package_dir = package_dir,
168     packages = getPackages(package_dir.values()),)
169 fvlingen 1.7