Clear up and document patch [ 120 ].
[docutils.git] / setup.py
blob2da25655c6ceba272efa9fa79e5da0b7ef2aa52b
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 if sys.version_info >= (3,):
13 from distutils.command.build_py import build_py_2to3
14 from distutils.util import copydir_run_2to3
15 from distutils.command.install_data import install_data
16 from distutils.util import convert_path
17 from distutils import log
18 except ImportError:
19 print ('Error: The "distutils" standard module, which is required for the ')
20 print ('installation of Docutils, could not be found. You may need to ')
21 print ('install a package called "python-devel" (or similar) on your ')
22 print ('system using your package manager.')
23 sys.exit(1)
26 if sys.version_info >= (3,):
27 # copy-convert auxiliary python sources
28 class copy_build_py_2to3(build_py_2to3):
29 """Copy/convert Python source files in given directories recursively.
31 Build py3k versions of the modules and packages.
32 Also copy 'test/' suite and run 2to3 on *.py files.
33 """
34 manifest_in = """\
35 exclude *.pyc *~ .DS_Store
36 recursive-exclude * *.pyc *~ .DS_Store
37 recursive-exclude functional/output *
38 include functional/output/README.txt
39 prune .svn
40 prune */.svn
41 prune */*/.svn
42 prune */*/*/.svn
43 prune */*/*/*/.svn
44 prune */*/*/*/*/.svn
45 """
46 def run(self):
47 build_py_2to3.run(self)
48 print("copy/convert test suite")
49 loglevel = log.set_threshold(log.ERROR)
50 copydir_run_2to3('test', 'test3', template=self.manifest_in)
51 log.set_threshold(loglevel)
54 class smart_install_data(install_data):
55 # From <http://wiki.python.org/moin/DistutilsInstallDataScattered>,
56 # by Pete Shinners.
58 def run(self):
59 #need to change self.install_dir to the library dir
60 install_cmd = self.get_finalized_command('install')
61 self.install_dir = getattr(install_cmd, 'install_lib')
62 return install_data.run(self)
64 class build_data(Command):
66 def initialize_options(self):
67 pass
69 def finalize_options(self):
70 pass
72 def run(self):
73 build_py = self.get_finalized_command('build_py')
74 data_files = self.distribution.data_files
75 for f in data_files:
76 dir = convert_path(f[0])
77 dir = os.path.join(build_py.build_lib, dir)
78 self.mkpath(dir)
79 for data in f[1]:
80 data = convert_path(data)
81 self.copy_file(data, dir)
83 # let our build_data run
84 build.sub_commands.append(('build_data', lambda *a: True))
87 def do_setup():
88 kwargs = package_data.copy()
89 kwargs['classifiers'] = classifiers
90 # Install data files properly.
91 kwargs['cmdclass'] = {'build_data': build_data,
92 'install_data': smart_install_data}
93 # Auto-convert source code for Python 3
94 if sys.version_info >= (3,):
95 kwargs['cmdclass']['build_py'] = copy_build_py_2to3
96 else:
97 kwargs['cmdclass']['build_py'] = build_py
98 dist = setup(**kwargs)
99 return dist
101 s5_theme_files = []
102 for dir in glob.glob('docutils/writers/s5_html/themes/*'):
103 if os.path.isdir(dir):
104 theme_files = glob.glob('%s/*' % dir)
105 s5_theme_files.append((dir, theme_files))
107 package_data = {
108 'name': 'docutils',
109 'description': 'Docutils -- Python Documentation Utilities',
110 'long_description': """\
111 Docutils is a modular system for processing documentation
112 into useful formats, such as HTML, XML, and LaTeX. For
113 input Docutils supports reStructuredText, an easy-to-read,
114 what-you-see-is-what-you-get plaintext markup syntax.""", # wrap at col 60
115 'url': 'http://docutils.sourceforge.net/',
116 'version': '0.13',
117 'author': 'David Goodger',
118 'author_email': 'goodger@python.org',
119 'maintainer': 'docutils-develop list',
120 'maintainer_email': 'docutils-develop@lists.sourceforge.net',
121 'license': 'public domain, Python, 2-Clause BSD, GPL 3 (see COPYING.txt)',
122 'platforms': 'OS-independent',
123 'package_dir': {'docutils': 'docutils',
124 'docutils.tools': 'tools'},
125 'packages': ['docutils',
126 'docutils.languages',
127 'docutils.parsers',
128 'docutils.parsers.rst',
129 'docutils.parsers.rst.directives',
130 'docutils.parsers.rst.languages',
131 'docutils.readers',
132 # 'docutils.readers.python', # in the sandbox since 0.8
133 'docutils.transforms',
134 'docutils.utils',
135 'docutils.utils.math',
136 'docutils.writers',
137 'docutils.writers.html4css1',
138 'docutils.writers.html_plain',
139 # 'docutils.writers.xhtml11', # moved to the sandbox
140 'docutils.writers.pep_html',
141 'docutils.writers.s5_html',
142 'docutils.writers.latex2e',
143 # 'docutils.writers.newlatex2e', # in the sandbox since 0.8
144 'docutils.writers.xetex',
145 'docutils.writers.odf_odt',
147 'data_files': ([('docutils/parsers/rst/include',
148 glob.glob('docutils/parsers/rst/include/*.txt')),
149 ('docutils/writers/html_plain',
150 ['docutils/writers/html_plain/minimal.css',
151 'docutils/writers/html_plain/plain.css',
152 'docutils/writers/html_plain/math.css',
153 'docutils/writers/html_plain/template.txt']),
154 ('docutils/writers/html4css1',
155 ['docutils/writers/html4css1/html4css1.css',
156 'docutils/writers/html4css1/template.txt']),
157 ('docutils/writers/latex2e',
158 ['docutils/writers/latex2e/default.tex',
159 'docutils/writers/latex2e/titlepage.tex',
160 'docutils/writers/latex2e/xelatex.tex',]),
161 ('docutils/writers/pep_html',
162 ['docutils/writers/pep_html/pep.css',
163 'docutils/writers/pep_html/template.txt']),
164 ('docutils/writers/s5_html/themes',
165 ['docutils/writers/s5_html/themes/README.txt']),
166 ('docutils/writers/odf_odt',
167 ['docutils/writers/odf_odt/styles.odt']),
169 + s5_theme_files),
170 'scripts' : ['tools/rst2html.py',
171 'tools/rst2html5.py',
172 'tools/rst2s5.py',
173 'tools/rst2latex.py',
174 'tools/rst2xetex.py',
175 'tools/rst2man.py',
176 'tools/rst2xml.py',
177 'tools/rst2pseudoxml.py',
178 'tools/rstpep2html.py',
179 'tools/rst2odt.py',
180 'tools/rst2odt_prepstyles.py',
182 """Distutils setup parameters."""
184 classifiers = [
185 'Development Status :: 4 - Beta',
186 'Environment :: Console',
187 'Intended Audience :: End Users/Desktop',
188 'Intended Audience :: Other Audience',
189 'Intended Audience :: Developers',
190 'Intended Audience :: System Administrators',
191 'License :: Public Domain',
192 'License :: OSI Approved :: Python Software Foundation License',
193 'License :: OSI Approved :: BSD License',
194 'License :: OSI Approved :: GNU General Public License (GPL)',
195 'Operating System :: OS Independent',
196 'Programming Language :: Python :: 2.4',
197 'Programming Language :: Python :: 2.5',
198 'Programming Language :: Python :: 2.6',
199 'Programming Language :: Python :: 2.7',
200 'Programming Language :: Python :: 3',
201 'Topic :: Documentation',
202 'Topic :: Software Development :: Documentation',
203 'Topic :: Text Processing',
204 'Natural Language :: English', # main/default language, keep first
205 'Natural Language :: Afrikaans',
206 'Natural Language :: Catalan',
207 'Natural Language :: Chinese (Simplified)',
208 'Natural Language :: Chinese (Traditional)',
209 'Natural Language :: Czech',
210 'Natural Language :: Dutch',
211 'Natural Language :: Esperanto',
212 'Natural Language :: Finnish',
213 'Natural Language :: French',
214 'Natural Language :: Galician',
215 'Natural Language :: German',
216 'Natural Language :: Italian',
217 'Natural Language :: Japanese',
218 'Natural Language :: Polish',
219 'Natural Language :: Portuguese (Brazilian)',
220 'Natural Language :: Russian',
221 'Natural Language :: Slovak',
222 'Natural Language :: Spanish',
223 'Natural Language :: Swedish',
225 # BUG pypi did not like fllowing languages
226 # 'Natural Language :: Lithuanian',
227 """Trove classifiers for the Distutils "register" command."""
229 if __name__ == '__main__' :
230 do_setup()