A new role neither based on some old nor with class.
[docutils.git] / setup.py
blob8f61a06e8238051245d325548f025c40d0811862
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@users.sourceforge.net',
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/latex2e',
77 ['docutils/writers/latex2e/latex2e.tex']),
78 ('docutils/writers/newlatex2e',
79 ['docutils/writers/newlatex2e/base.tex']),
80 ('docutils/writers/pep_html',
81 ['docutils/writers/pep_html/pep.css',
82 'docutils/writers/pep_html/template.txt']),
83 ('docutils/writers/s5_html/themes',
84 ['docutils/writers/s5_html/themes/README.txt']),]
85 + s5_theme_files),
86 'scripts' : ['tools/rst2html.py',
87 'tools/rst2s5.py',
88 'tools/rst2latex.py',
89 'tools/rst2newlatex.py',
90 'tools/rst2xml.py',
91 'tools/rst2pseudoxml.py'],}
92 """Distutils setup parameters."""
94 classifiers = [
95 'Development Status :: 3 - Alpha',
96 'Environment :: Console',
97 'Intended Audience :: End Users/Desktop',
98 'Intended Audience :: Other Audience',
99 'Intended Audience :: Developers',
100 'Intended Audience :: System Administrators',
101 'License :: Public Domain',
102 'License :: OSI Approved :: Python Software Foundation License',
103 'License :: OSI Approved :: BSD License',
104 'License :: OSI Approved :: GNU General Public License (GPL)',
105 'Operating System :: OS Independent',
106 'Programming Language :: Python',
107 'Topic :: Documentation',
108 'Topic :: Software Development :: Documentation',
109 'Topic :: Text Processing',
110 'Natural Language :: English', # main/default language, keep first
111 'Natural Language :: Afrikaans',
112 'Natural Language :: Esperanto',
113 'Natural Language :: French',
114 'Natural Language :: German',
115 'Natural Language :: Italian',
116 'Natural Language :: Russian',
117 'Natural Language :: Slovak',
118 'Natural Language :: Spanish',
119 'Natural Language :: Swedish',]
120 """Trove classifiers for the Distutils "register" command;
121 Python 2.3 and up."""
123 extra_modules = [('optparse', '1.4.1', None),
124 ('textwrap', None, None),
125 ('roman', '1.4', ['toRoman', 'fromRoman',
126 'InvalidRomanNumeralError'])]
127 """Third-party modules to install if they're not already present.
128 List of (module name, minimum __version__ string, [attribute names])."""
130 def get_extras():
131 extras = []
132 for module_name, version, attributes in extra_modules:
133 try:
134 module = __import__(module_name)
135 if version and module.__version__ < version:
136 raise ValueError
137 for attribute in attributes or []:
138 getattr(module, attribute)
139 print ('"%s" module already present; ignoring extras/%s.py.'
140 % (module_name, module_name))
141 except (ImportError, AttributeError, ValueError):
142 extras.append(module_name)
143 return extras
146 class dual_build_py(build_py):
149 This class allows the distribution of both packages *and* modules with one
150 call to `distutils.core.setup()` (necessary for pre-2.3 Python). Thanks
151 to Thomas Heller.
154 def run(self):
155 if not self.py_modules and not self.packages:
156 return
157 if self.py_modules:
158 self.build_modules()
159 if self.packages:
160 self.build_packages()
161 self.byte_compile(self.get_outputs(include_bytecode=0))
164 if __name__ == '__main__' :
165 do_setup()