Python 2.5 compatibility: dynamic exception matching
[docutils.git] / setup.py
blob903e586829d684e85aeb10e7ea2668d1a8291c4a
1 #!/usr/bin/env python
2 # $Id$
3 # Copyright: This file has been placed in the public domain.
5 import sys
6 import os
7 import glob
8 try:
9 from distutils.core import setup
10 from distutils.command.build_py import build_py
11 except ImportError:
12 print 'Error: The "distutils" standard module, which is required for the '
13 print 'installation of Docutils, could not be found. You may need to '
14 print 'install a package called "python-devel" (or similar) on your '
15 print 'system using your package manager.'
16 sys.exit(1)
18 # From <http://groups.google.de/groups?as_umsgid=f70e3538.0404141327.6cea58ca@posting.google.com>.
19 from distutils.command.install import INSTALL_SCHEMES
20 for scheme in INSTALL_SCHEMES.values():
21 scheme['data'] = scheme['purelib']
24 def do_setup():
25 kwargs = package_data.copy()
26 extras = get_extras()
27 if extras:
28 kwargs['py_modules'] = extras
29 if sys.hexversion >= 0x02030000: # Python 2.3
30 kwargs['classifiers'] = classifiers
31 else:
32 kwargs['cmdclass'] = {'build_py': dual_build_py}
33 dist = setup(**kwargs)
34 return dist
36 s5_theme_files = []
37 for dir in glob.glob('docutils/writers/s5_html/themes/*'):
38 if os.path.isdir(dir):
39 theme_files = glob.glob('%s/*' % dir)
40 s5_theme_files.append((dir, theme_files))
42 package_data = {
43 'name': 'docutils',
44 'description': 'Docutils -- Python Documentation Utilities',
45 'long_description': """\
46 Docutils is a modular system for processing documentation
47 into useful formats, such as HTML, XML, and LaTeX. For
48 input Docutils supports reStructuredText, an easy-to-read,
49 what-you-see-is-what-you-get plaintext markup syntax.""", # wrap at col 60
50 'url': 'http://docutils.sourceforge.net/',
51 'version': '0.5',
52 'author': 'David Goodger',
53 'author_email': 'goodger@python.org',
54 'license': 'public domain, Python, BSD, GPL (see COPYING.txt)',
55 'platforms': 'OS-independent',
56 'package_dir': {'docutils': 'docutils', '': 'extras'},
57 'packages': ['docutils',
58 'docutils.languages',
59 'docutils.parsers',
60 'docutils.parsers.rst',
61 'docutils.parsers.rst.directives',
62 'docutils.parsers.rst.languages',
63 'docutils.readers',
64 'docutils.readers.python',
65 'docutils.transforms',
66 'docutils.writers',
67 'docutils.writers.html4css1',
68 'docutils.writers.pep_html',
69 'docutils.writers.s5_html',
70 'docutils.writers.latex2e',
71 'docutils.writers.newlatex2e'],
72 'data_files': ([('docutils/parsers/rst/include',
73 glob.glob('docutils/parsers/rst/include/*.txt')),
74 ('docutils/writers/html4css1',
75 ['docutils/writers/html4css1/html4css1.css',
76 'docutils/writers/html4css1/template.txt']),
77 ('docutils/writers/latex2e',
78 ['docutils/writers/latex2e/latex2e.tex']),
79 ('docutils/writers/newlatex2e',
80 ['docutils/writers/newlatex2e/base.tex']),
81 ('docutils/writers/pep_html',
82 ['docutils/writers/pep_html/pep.css',
83 'docutils/writers/pep_html/template.txt']),
84 ('docutils/writers/s5_html/themes',
85 ['docutils/writers/s5_html/themes/README.txt']),]
86 + s5_theme_files),
87 'scripts' : ['tools/rst2html.py',
88 'tools/rst2s5.py',
89 'tools/rst2latex.py',
90 'tools/rst2newlatex.py',
91 'tools/rst2xml.py',
92 'tools/rst2pseudoxml.py'],}
93 """Distutils setup parameters."""
95 classifiers = [
96 'Development Status :: 3 - Alpha',
97 'Environment :: Console',
98 'Intended Audience :: End Users/Desktop',
99 'Intended Audience :: Other Audience',
100 'Intended Audience :: Developers',
101 'Intended Audience :: System Administrators',
102 'License :: Public Domain',
103 'License :: OSI Approved :: Python Software Foundation License',
104 'License :: OSI Approved :: BSD License',
105 'License :: OSI Approved :: GNU General Public License (GPL)',
106 'Operating System :: OS Independent',
107 'Programming Language :: Python',
108 'Topic :: Documentation',
109 'Topic :: Software Development :: Documentation',
110 'Topic :: Text Processing',
111 'Natural Language :: English', # main/default language, keep first
112 'Natural Language :: Afrikaans',
113 'Natural Language :: Esperanto',
114 'Natural Language :: French',
115 'Natural Language :: German',
116 'Natural Language :: Italian',
117 'Natural Language :: Russian',
118 'Natural Language :: Slovak',
119 'Natural Language :: Spanish',
120 'Natural Language :: Swedish',]
121 """Trove classifiers for the Distutils "register" command;
122 Python 2.3 and up."""
124 extra_modules = [('optparse', '1.4.1', None),
125 ('textwrap', None, None),
126 ('roman', '1.4', ['toRoman', 'fromRoman',
127 'InvalidRomanNumeralError'])]
128 """Third-party modules to install if they're not already present.
129 List of (module name, minimum __version__ string, [attribute names])."""
131 def get_extras():
132 extras = []
133 for module_name, version, attributes in extra_modules:
134 try:
135 module = __import__(module_name)
136 if version and module.__version__ < version:
137 raise ValueError
138 for attribute in attributes or []:
139 getattr(module, attribute)
140 print ('"%s" module already present; ignoring extras/%s.py.'
141 % (module_name, module_name))
142 except (ImportError, AttributeError, ValueError):
143 extras.append(module_name)
144 return extras
147 class dual_build_py(build_py):
150 This class allows the distribution of both packages *and* modules with one
151 call to `distutils.core.setup()` (necessary for pre-2.3 Python). Thanks
152 to Thomas Heller.
155 def run(self):
156 if not self.py_modules and not self.packages:
157 return
158 if self.py_modules:
159 self.build_modules()
160 if self.packages:
161 self.build_packages()
162 self.byte_compile(self.get_outputs(include_bytecode=0))
165 if __name__ == '__main__' :
166 do_setup()