ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/WMCORE/setup.py
Revision: 1.26
Committed: Wed Aug 26 10:31:01 2009 UTC (15 years, 8 months ago) by metson
Content type: text/x-python
Branch: MAIN
Changes since 1.25: +18 -2 lines
Log Message:
Add test/python and src/python directories to PYTHONPATH in case they aren't there already.

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 metson 1.25 Finds all the tests modules in test/python/WMCore_t, and runs them.
32 metson 1.21 '''
33     testfiles = [ ]
34 metson 1.26
35     # Add the test and src directory to the python path
36     testspypath = '/'.join([self._dir, 'test/python/'])
37     srcpypath = '/'.join([self._dir, 'src/python/'])
38     oldpypath = os.environ['PYTHONPATH']
39     os.environ['PYTHONPATH'] = ':'.join([oldpypath, testspypath, srcpypath])
40     print os.environ['PYTHONPATH']
41 metson 1.21 # Walk the directory tree
42     for dirpath, dirnames, filenames in os.walk('./test/python/WMCore_t'):
43     # skipping CVS directories and their contents
44     pathelements = dirpath.split('/')
45     if not 'CVS' in pathelements:
46     # to build up a list of file names which contain tests
47     for file in filenames:
48     if file not in ['__init__.py']:
49     if file.endswith('_t.py'):
50     testmodpath = pathelements[3:]
51     testmodpath.append(file.replace('.py',''))
52     testfiles.append('.'.join(testmodpath))
53    
54     testsuite = TestSuite()
55     for test in testfiles:
56     try:
57     testsuite.addTest(TestLoader().loadTestsFromName(test))
58     except Exception, e:
59     print "Could not load %s test - fix it!\n %s" % (test, e)
60     print "Running %s tests" % testsuite.countTestCases()
61    
62     t = TextTestRunner(verbosity = 1)
63     t.run(testsuite)
64 metson 1.26
65     # Reset the python path
66     os.environ['PYTHONPATH'] = oldpypath
67    
68 metson 1.21 class CleanCommand(Command):
69 metson 1.22 """
70     Clean up (delete) compiled files
71     """
72 metson 1.21 user_options = [ ]
73    
74     def initialize_options(self):
75     self._clean_me = [ ]
76     for root, dirs, files in os.walk('.'):
77     for f in files:
78     if f.endswith('.pyc'):
79     self._clean_me.append(pjoin(root, f))
80    
81     def finalize_options(self):
82     pass
83    
84     def run(self):
85     for clean_me in self._clean_me:
86     try:
87     os.unlink(clean_me)
88     except:
89     pass
90    
91 metson 1.23 class LintCommand(Command):
92 metson 1.24 """
93     Lint all files in the src tree
94    
95     TODO: better format the test results, get some global result, make output
96     more buildbot friendly.
97     """
98    
99 metson 1.23 user_options = [ ]
100    
101     def initialize_options(self):
102     self._dir = os.getcwd()
103    
104     def finalize_options(self):
105     pass
106    
107     def run(self):
108     '''
109     Find the code and run lint on it
110     '''
111     files = [ ]
112 metson 1.26
113     srcpypath = '/'.join([self._dir, 'src/python/'])
114     oldpypath = os.environ['PYTHONPATH']
115     os.environ['PYTHONPATH'] = ':'.join([oldpypath, srcpypath])
116    
117 metson 1.23 # Walk the directory tree
118     for dirpath, dirnames, filenames in os.walk('./src/python/'):
119     # skipping CVS directories and their contents
120     pathelements = dirpath.split('/')
121     if not 'CVS' in pathelements:
122     # to build up a list of file names which contain tests
123     for file in filenames:
124     filepath = '/'.join([dirpath, file])
125     files.append(filepath)
126     # run individual tests as follows
127     lint.Run(['--rcfile=standards/.pylintrc', filepath])
128     # Could run a global test as:
129     #input = ['--rcfile=standards/.pylintrc']
130     #input.extend(files)
131     #lint.Run(input)
132 metson 1.26
133     os.environ['PYTHONPATH'] = oldpypath
134 metson 1.23
135 metson 1.22 def getPackages(package_dirs = []):
136     packages = []
137     for dir in package_dirs:
138     for dirpath, dirnames, filenames in os.walk('./%s' % dir):
139     # Exclude things here
140     if dirpath not in ['./src/python/', './src/python/IMProv']:
141     pathelements = dirpath.split('/')
142     if not 'CVS' in pathelements:
143     path = pathelements[3:]
144     packages.append('.'.join(path))
145     return packages
146    
147     package_dir = {'WMCore': 'src/python/WMCore',
148     'WMComponent' : 'src/python/WMComponent',
149     'WMQuality' : 'src/python/WMQuality'}
150    
151     setup (name = 'wmcore',
152     version = '1.0',
153 metson 1.23 cmdclass = { 'test': TestCommand,
154     'clean': CleanCommand,
155     'lint': LintCommand },
156 metson 1.22 package_dir = package_dir,
157     packages = getPackages(package_dir.values()),)
158 fvlingen 1.7