Release 0.6: tagging released revision
[docutils.git] / setup.py
bloba81a2ac72d850e3def524cbbe01d8fa1205a96a4
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, Command
10 from distutils.command.build import build
11 from distutils.command.build_py import build_py
12 from distutils.command.install_data import install_data
13 from distutils.util import convert_path
14 except ImportError:
15 print ('Error: The "distutils" standard module, which is required for the ')
16 print ('installation of Docutils, could not be found. You may need to ')
17 print ('install a package called "python-devel" (or similar) on your ')
18 print ('system using your package manager.')
19 sys.exit(1)
21 try:
22 from distutils.command.build_py import build_py_2to3 as build_py
23 except ImportError:
24 from distutils.command.build_py import build_py
27 class smart_install_data(install_data):
28 # Hack for Python > 2.3.
29 # From <http://wiki.python.org/moin/DistutilsInstallDataScattered>,
30 # by Pete Shinners.
32 def run(self):
33 #need to change self.install_dir to the library dir
34 install_cmd = self.get_finalized_command('install')
35 self.install_dir = getattr(install_cmd, 'install_lib')
36 return install_data.run(self)
38 class build_data(Command):
40 def initialize_options(self):
41 pass
43 def finalize_options(self):
44 pass
46 def run(self):
47 build_py = self.get_finalized_command('build_py')
48 data_files = self.distribution.data_files
49 for f in data_files:
50 dir = convert_path(f[0])
51 dir = os.path.join(build_py.build_lib, dir)
52 self.mkpath(dir)
53 for data in f[1]:
54 data = convert_path(data)
55 self.copy_file(data, dir)
57 # let our build_data run
58 build.sub_commands.append(('build_data', lambda *a: True))
61 def do_setup():
62 kwargs = package_data.copy()
63 extras = get_extras()
64 if extras:
65 kwargs['py_modules'] = extras
66 kwargs['classifiers'] = classifiers
67 # Install data files properly. Note that we use a different
68 # hack for Python 2.2, which does not *always* work, though;
69 # see
70 # <http://article.gmane.org/gmane.text.docutils.user/2867>.
71 # So for Python 2.3+, we prefer this hack.
72 kwargs['cmdclass'] = {'install_data': smart_install_data,
73 'build_py': build_py,
74 'build_data': build_data}
75 dist = setup(**kwargs)
76 return dist
78 s5_theme_files = []
79 for dir in glob.glob('docutils/writers/s5_html/themes/*'):
80 if os.path.isdir(dir):
81 theme_files = glob.glob('%s/*' % dir)
82 s5_theme_files.append((dir, theme_files))
84 package_data = {
85 'name': 'docutils',
86 'description': 'Docutils -- Python Documentation Utilities',
87 'long_description': """\
88 Docutils is a modular system for processing documentation
89 into useful formats, such as HTML, XML, and LaTeX. For
90 input Docutils supports reStructuredText, an easy-to-read,
91 what-you-see-is-what-you-get plaintext markup syntax.""", # wrap at col 60
92 'url': 'http://docutils.sourceforge.net/',
93 'version': '0.6',
94 'author': 'David Goodger',
95 'author_email': 'goodger@python.org',
96 'license': 'public domain, Python, BSD, GPL (see COPYING.txt)',
97 'platforms': 'OS-independent',
98 'package_dir': {'docutils': 'docutils', '': 'extras'},
99 'packages': ['docutils',
100 'docutils.languages',
101 'docutils.parsers',
102 'docutils.parsers.rst',
103 'docutils.parsers.rst.directives',
104 'docutils.parsers.rst.languages',
105 'docutils.readers',
106 'docutils.readers.python',
107 'docutils.transforms',
108 'docutils.writers',
109 'docutils.writers.html4css1',
110 'docutils.writers.pep_html',
111 'docutils.writers.s5_html',
112 'docutils.writers.latex2e',
113 'docutils.writers.newlatex2e',
114 'docutils.writers.odf_odt',
116 'data_files': ([('docutils/parsers/rst/include',
117 glob.glob('docutils/parsers/rst/include/*.txt')),
118 ('docutils/writers/html4css1',
119 ['docutils/writers/html4css1/html4css1.css',
120 'docutils/writers/html4css1/template.txt']),
121 ('docutils/writers/latex2e',
122 ['docutils/writers/latex2e/default.tex',
123 'docutils/writers/latex2e/titlepage.tex',]),
124 ('docutils/writers/newlatex2e',
125 ['docutils/writers/newlatex2e/base.tex']),
126 ('docutils/writers/pep_html',
127 ['docutils/writers/pep_html/pep.css',
128 'docutils/writers/pep_html/template.txt']),
129 ('docutils/writers/s5_html/themes',
130 ['docutils/writers/s5_html/themes/README.txt']),
131 ('docutils/writers/odf_odt',
132 ['docutils/writers/odf_odt/styles.odt']),
134 + s5_theme_files),
135 'scripts' : ['tools/rst2html.py',
136 'tools/rst2s5.py',
137 'tools/rst2latex.py',
138 'tools/rst2newlatex.py',
139 'tools/rst2man.py',
140 'tools/rst2xml.py',
141 'tools/rst2pseudoxml.py',
142 'tools/rstpep2html.py',
143 'tools/rst2odt.py',
144 'tools/rst2odt_prepstyles.py',
146 """Distutils setup parameters."""
148 classifiers = [
149 'Development Status :: 4 - Beta',
150 'Environment :: Console',
151 'Intended Audience :: End Users/Desktop',
152 'Intended Audience :: Other Audience',
153 'Intended Audience :: Developers',
154 'Intended Audience :: System Administrators',
155 'License :: Public Domain',
156 'License :: OSI Approved :: Python Software Foundation License',
157 'License :: OSI Approved :: BSD License',
158 'License :: OSI Approved :: GNU General Public License (GPL)',
159 'Operating System :: OS Independent',
160 'Programming Language :: Python',
161 'Topic :: Documentation',
162 'Topic :: Software Development :: Documentation',
163 'Topic :: Text Processing',
164 'Natural Language :: English', # main/default language, keep first
165 'Natural Language :: Afrikaans',
166 'Natural Language :: Esperanto',
167 'Natural Language :: French',
168 'Natural Language :: German',
169 'Natural Language :: Italian',
170 'Natural Language :: Russian',
171 'Natural Language :: Slovak',
172 'Natural Language :: Spanish',
173 'Natural Language :: Swedish',]
174 """Trove classifiers for the Distutils "register" command;
175 Python 2.3 and up."""
177 extra_modules = [('roman', '1.4', ['toRoman', 'fromRoman',
178 'InvalidRomanNumeralError'])]
179 """Third-party modules to install if they're not already present.
180 List of (module name, minimum __version__ string, [attribute names])."""
182 def get_extras():
183 extras = []
184 for module_name, version, attributes in extra_modules:
185 try:
186 module = __import__(module_name)
187 if version and module.__version__ < version:
188 raise ValueError
189 for attribute in attributes or []:
190 getattr(module, attribute)
191 print ('"%s" module already present; ignoring extras/%s.py.'
192 % (module_name, module_name))
193 except (ImportError, AttributeError, ValueError):
194 extras.append(module_name)
195 return extras
198 if __name__ == '__main__' :
199 do_setup()