ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/DAS/setup.py
Revision: 1.5
Committed: Tue Mar 30 20:41:56 2010 UTC (15 years, 1 month ago) by valya
Content type: text/x-python
Branch: MAIN
CVS Tags: V04_00_06
Changes since 1.4: +9 -7 lines
Log Message:
Put try/except

File Contents

# User Rev Content
1 valya 1.1 #!/usr/bin/env python
2    
3     import sys
4     import os
5    
6     from ez_setup import use_setuptools
7     use_setuptools()
8     from setuptools import setup, find_packages, Feature
9     from distutils.cmd import Command
10     from distutils.command.build_ext import build_ext
11     from distutils.errors import CCompilerError
12     from distutils.errors import DistutilsPlatformError, DistutilsExecError
13     from distutils.core import Extension
14 valya 1.2 from distutils.command.install import INSTALL_SCHEMES
15 valya 1.4 from subprocess import Popen, PIPE
16 valya 1.1
17     requirements = []
18     try:
19     import xml.etree.cElementTree
20     except ImportError:
21     try:
22     import celementtree
23     except ImportError:
24     requirements.append("celementtree")
25     try:
26     import pymongo
27     except ImportError:
28     requirements.append("pymongo")
29    
30 valya 1.2 required_python_version = '2.6'
31    
32 valya 1.1 if sys.platform == 'win32' and sys.version_info > (2, 6):
33     # 2.6's distutils.msvc9compiler can raise an IOError when failing to
34     # find the compiler
35     build_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError,
36     IOError)
37     else:
38     build_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
39    
40    
41     class custom_build_ext(build_ext):
42     """Allow C extension building to fail.
43     The C extension speeds up DAS, but is not essential.
44     """
45    
46     warning_message = """
47     **************************************************************
48     WARNING: %s could not
49     be compiled. No C extensions are essential for DAS to run,
50     although they do result in significant speed improvements.
51    
52     %s
53     **************************************************************
54     """
55    
56     def run(self):
57     try:
58     build_ext.run(self)
59     except DistutilsPlatformError, e:
60     print e
61     print self.warning_message % ("Extension modules",
62     "There was an issue with your "
63     "platform configuration - see above.")
64    
65     def build_extension(self, ext):
66     try:
67     build_ext.build_extension(self, ext)
68     except build_errors:
69     print self.warning_message % ("The %s extension module" % ext.name,
70     "Above is the ouput showing how "
71     "the compilation failed.")
72    
73     c_ext = Feature(
74     "optional C extension",
75     standard=True,
76 valya 1.3 ext_modules=[Extension('DAS.extensions.das_speed_utils',
77 valya 1.1 include_dirs=['extensions'],
78     sources=['src/python/DAS/extensions/dict_handler.c'])])
79    
80     if "--no_ext" in sys.argv:
81     sys.argv = [x for x in sys.argv if x != "--no_ext"]
82     features = {}
83     else:
84     features = {"c-ext": c_ext}
85    
86 valya 1.5 try:
87     proc1 = Popen(['cvs', 'status', '-v', 'setup.py'], stdout=PIPE)
88     proc2 = Popen(['grep', 'revision'], stdin=proc1.stdout, stdout=PIPE)
89     proc3 = Popen(['grep', '-v', 'Repository'], stdin=proc2.stdout, stdout=PIPE)
90     proc4 = Popen(['grep', '-v', 'Working'], stdin=proc3.stdout, stdout=PIPE)
91     proc5 = Popen(['head', '-1'], stdin=proc4.stdout, stdout=PIPE)
92     version = proc5.communicate()[0].split()[0]
93     except:
94     version = "1.0.0" # need to define it somehow
95 valya 1.2 name = "DAS"
96     description = "CMS Data Aggregation System"
97     readme ="""
98     DAS stands for Data Aggregation System
99     <https://twiki.cern.ch/twiki/bin/viewauth/CMS/DMWMDataAggregationService>
100     """
101     author = "Valentin Kuznetsov",
102     author_email = "vkuznet@gmail.com",
103     scriptfiles = filter(os.path.isfile, ['etc/das.cfg'])
104     url = "https://twiki.cern.ch/twiki/bin/viewauth/CMS/DMWMDataAggregationService",
105     keywords = ["DAS", "Aggregation", "Meta-data"]
106 valya 1.3 package_dir = {'DAS': 'src/python/DAS'}
107 valya 1.2 package_data = {
108 valya 1.3 'src': ['python/DAS/services/maps/*.yml', 'python/DAS/web/css/*.css'],
109 valya 1.2 }
110 valya 1.3 #packages = find_packages('src/python/DAS')
111     packages = find_packages('src/python/')
112 valya 1.2 packages += ['src/css', 'src/js', 'src/templates', 'etc', 'bin', 'test', 'doc']
113     license = "CMS experiment software"
114     classifiers = [
115     "Development Status :: 3 - Production/Beta",
116     "Intended Audience :: Developers",
117     "License :: OSI Approved :: CMS/CERN Software License",
118     "Operating System :: MacOS :: MacOS X",
119     "Operating System :: Microsoft :: Windows",
120     "Operating System :: POSIX",
121     "Programming Language :: Python",
122     "Topic :: Database"
123     ]
124    
125     def main():
126     if sys.version < required_python_version:
127     s = "I'm sorry, but %s %s requires Python %s or later."
128     print s % (name, version, required_python_version)
129     sys.exit(1)
130    
131     # set default location for "data_files" to
132     # platform specific "site-packages" location
133     for scheme in INSTALL_SCHEMES.values():
134     scheme['data'] = scheme['purelib']
135    
136     dist = setup(
137     name = name,
138     version = version,
139     description = description,
140     long_description = readme,
141     keywords = keywords,
142     package_dir = package_dir,
143     packages = packages,
144     package_data = package_data,
145     # data_files = data_files,
146     include_package_data = True,
147     install_requires = requirements,
148     # scripts = scriptfiles,
149     features = features,
150     classifiers = classifiers,
151     cmdclass = {"build_ext": custom_build_ext},
152     author = author,
153     author_email = author_email,
154     url = url,
155     license = license,
156     )
157    
158     if __name__ == "__main__":
159     main()
160