ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/WMCORE/setup.py
Revision: 1.24
Committed: Tue Aug 25 16:06:04 2009 UTC (15 years, 8 months ago) by metson
Content type: text/x-python
Branch: MAIN
Changes since 1.23: +7 -0 lines
Log Message:
Add some docs and a todo

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