latex2e writer : Move usepackage hyperref after stylesheet inclusion.
[docutils.git] / setup.py
blobab4b23d5be7f32dc70f1bd08c638ff9a74cb1add
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 from distutils.command.install_data import install_data
12 except ImportError:
13 print 'Error: The "distutils" standard module, which is required for the '
14 print 'installation of Docutils, could not be found. You may need to '
15 print 'install a package called "python-devel" (or similar) on your '
16 print 'system using your package manager.'
17 sys.exit(1)
19 if sys.hexversion < 0x02030000:
20 # Hack for Python < 2.3.
21 # From <http://groups.google.de/groups?as_umsgid=f70e3538.0404141327.6cea58ca@posting.google.com>.
22 from distutils.command.install import INSTALL_SCHEMES
23 for scheme in INSTALL_SCHEMES.values():
24 scheme['data'] = scheme['purelib']
27 class smart_install_data(install_data):
29 # Hack for Python > 2.3.
30 # From <http://wiki.python.org/moin/DistutilsInstallDataScattered>,
31 # by Pete Shinners.
33 def run(self):
34 #need to change self.install_dir to the library dir
35 install_cmd = self.get_finalized_command('install')
36 self.install_dir = getattr(install_cmd, 'install_lib')
37 return install_data.run(self)
40 def do_setup():
41 kwargs = package_data.copy()
42 extras = get_extras()
43 if extras:
44 kwargs['py_modules'] = extras
45 if sys.hexversion >= 0x02030000: # Python 2.3
46 kwargs['classifiers'] = classifiers
47 # Install data files properly. Note that we use a different
48 # hack for Python 2.2, which does not *always* work, though;
49 # see
50 # <http://article.gmane.org/gmane.text.docutils.user/2867>.
51 # So for Python 2.3+, we prefer this hack.
52 kwargs['cmdclass'] = {'install_data': smart_install_data}
53 else:
54 # Install data files properly. (Another hack for Python 2.2
55 # is at the top of this file.)
56 kwargs['cmdclass'] = {'build_py': dual_build_py}
57 dist = setup(**kwargs)
58 return dist
60 s5_theme_files = []
61 for dir in glob.glob('docutils/writers/s5_html/themes/*'):
62 if os.path.isdir(dir):
63 theme_files = glob.glob('%s/*' % dir)
64 s5_theme_files.append((dir, theme_files))
66 package_data = {
67 'name': 'docutils',
68 'description': 'Docutils -- Python Documentation Utilities',
69 'long_description': """\
70 Docutils is a modular system for processing documentation
71 into useful formats, such as HTML, XML, and LaTeX. For
72 input Docutils supports reStructuredText, an easy-to-read,
73 what-you-see-is-what-you-get plaintext markup syntax.""", # wrap at col 60
74 'url': 'http://docutils.sourceforge.net/',
75 'version': '0.5',
76 'author': 'David Goodger',
77 'author_email': 'goodger@python.org',
78 'license': 'public domain, Python, BSD, GPL (see COPYING.txt)',
79 'platforms': 'OS-independent',
80 'package_dir': {'docutils': 'docutils', '': 'extras'},
81 'packages': ['docutils',
82 'docutils.languages',
83 'docutils.parsers',
84 'docutils.parsers.rst',
85 'docutils.parsers.rst.directives',
86 'docutils.parsers.rst.languages',
87 'docutils.readers',
88 'docutils.readers.python',
89 'docutils.transforms',
90 'docutils.writers',
91 'docutils.writers.html4css1',
92 'docutils.writers.pep_html',
93 'docutils.writers.s5_html',
94 'docutils.writers.latex2e',
95 'docutils.writers.newlatex2e'],
96 'data_files': ([('docutils/parsers/rst/include',
97 glob.glob('docutils/parsers/rst/include/*.txt')),
98 ('docutils/writers/html4css1',
99 ['docutils/writers/html4css1/html4css1.css',
100 'docutils/writers/html4css1/template.txt']),
101 ('docutils/writers/latex2e',
102 ['docutils/writers/latex2e/latex2e.tex']),
103 ('docutils/writers/newlatex2e',
104 ['docutils/writers/newlatex2e/base.tex']),
105 ('docutils/writers/pep_html',
106 ['docutils/writers/pep_html/pep.css',
107 'docutils/writers/pep_html/template.txt']),
108 ('docutils/writers/s5_html/themes',
109 ['docutils/writers/s5_html/themes/README.txt']),]
110 + s5_theme_files),
111 'scripts' : ['tools/rst2html.py',
112 'tools/rst2s5.py',
113 'tools/rst2latex.py',
114 'tools/rst2newlatex.py',
115 'tools/rst2xml.py',
116 'tools/rst2pseudoxml.py',
117 'tools/rstpep2html.py',
119 """Distutils setup parameters."""
121 classifiers = [
122 'Development Status :: 3 - Alpha',
123 'Environment :: Console',
124 'Intended Audience :: End Users/Desktop',
125 'Intended Audience :: Other Audience',
126 'Intended Audience :: Developers',
127 'Intended Audience :: System Administrators',
128 'License :: Public Domain',
129 'License :: OSI Approved :: Python Software Foundation License',
130 'License :: OSI Approved :: BSD License',
131 'License :: OSI Approved :: GNU General Public License (GPL)',
132 'Operating System :: OS Independent',
133 'Programming Language :: Python',
134 'Topic :: Documentation',
135 'Topic :: Software Development :: Documentation',
136 'Topic :: Text Processing',
137 'Natural Language :: English', # main/default language, keep first
138 'Natural Language :: Afrikaans',
139 'Natural Language :: Esperanto',
140 'Natural Language :: French',
141 'Natural Language :: German',
142 'Natural Language :: Italian',
143 'Natural Language :: Russian',
144 'Natural Language :: Slovak',
145 'Natural Language :: Spanish',
146 'Natural Language :: Swedish',]
147 """Trove classifiers for the Distutils "register" command;
148 Python 2.3 and up."""
150 extra_modules = [('optparse', '1.4.1', None),
151 ('textwrap', None, None),
152 ('roman', '1.4', ['toRoman', 'fromRoman',
153 'InvalidRomanNumeralError'])]
154 """Third-party modules to install if they're not already present.
155 List of (module name, minimum __version__ string, [attribute names])."""
157 def get_extras():
158 extras = []
159 for module_name, version, attributes in extra_modules:
160 try:
161 module = __import__(module_name)
162 if version and module.__version__ < version:
163 raise ValueError
164 for attribute in attributes or []:
165 getattr(module, attribute)
166 print ('"%s" module already present; ignoring extras/%s.py.'
167 % (module_name, module_name))
168 except (ImportError, AttributeError, ValueError):
169 extras.append(module_name)
170 return extras
173 class dual_build_py(build_py):
176 This class allows the distribution of both packages *and* modules with one
177 call to `distutils.core.setup()` (necessary for pre-2.3 Python). Thanks
178 to Thomas Heller.
181 def run(self):
182 if not self.py_modules and not self.packages:
183 return
184 if self.py_modules:
185 self.build_modules()
186 if self.packages:
187 self.build_packages()
188 self.byte_compile(self.get_outputs(include_bytecode=0))
191 if __name__ == '__main__' :
192 do_setup()