sphinx/setup.py

190 lines
6.8 KiB
Python
Raw Normal View History

2008-02-09 17:09:36 -06:00
# -*- coding: utf-8 -*-
import ez_setup
ez_setup.use_setuptools()
import os
import sys
from setuptools import setup, find_packages
from distutils import log
2008-02-09 17:09:36 -06:00
import sphinx
2008-03-18 14:37:05 -05:00
long_desc = '''
Sphinx is a tool that makes it easy to create intelligent and beautiful
documentation for Python projects (or other documents consisting of
multiple reStructuredText sources), written by Georg Brandl.
2008-03-18 14:37:05 -05:00
It was originally created to translate the new Python documentation,
but has now been cleaned up in the hope that it will be useful to many
other projects.
2008-03-21 10:31:32 -05:00
Sphinx uses reStructuredText as its markup language, and many of its strengths
come from the power and straightforwardness of reStructuredText and its
parsing and translating suite, the Docutils.
2008-03-18 14:37:05 -05:00
Although it is still under constant development, the following features
are already present, work fine and can be seen "in action" in the Python docs:
2008-03-18 14:37:05 -05:00
2008-11-23 12:13:15 -06:00
* Output formats: HTML (including Windows HTML Help), plain text and LaTeX,
2008-03-18 14:37:05 -05:00
for printable PDF versions
* Extensive cross-references: semantic markup and automatic links
for functions, classes, glossary terms and similar pieces of information
* Hierarchical structure: easy definition of a document tree, with automatic
links to siblings, parents and children
* Automatic indices: general index as well as a module index
* Code handling: automatic highlighting using the Pygments highlighter
2008-03-21 10:31:32 -05:00
* Various extensions are available, e.g. for automatic testing of snippets
and inclusion of appropriately formatted docstrings.
2008-03-18 14:37:05 -05:00
'''
2008-11-20 13:05:45 -06:00
requires = ['Pygments>=0.8', 'Jinja2>=2.0', 'docutils>=0.4']
if sys.version_info < (2, 4):
print 'ERROR: Sphinx requires at least Python 2.4 to run.'
sys.exit(1)
if sys.version_info < (2, 5):
# Python 2.4's distutils doesn't automatically install an egg-info,
# so an existing docutils install won't be detected -- in that case,
# remove the dependency from setup.py
try:
import docutils
if int(docutils.__version__[2]) < 4:
raise ValueError('docutils not recent enough')
except:
pass
else:
del requires[-1]
# Provide a "compile_catalog" command that also creates the translated
# JavaScript files if Babel is available.
2008-09-09 16:23:57 -05:00
cmdclass = {}
try:
from babel.messages.pofile import read_po
from babel.messages.frontend import compile_catalog
try:
from simplejson import dump
except ImportError:
from json import dump
except ImportError:
pass
else:
class compile_catalog_plusjs(compile_catalog):
"""
An extended command that writes all message strings that occur in
JavaScript files to a JavaScript file along with the .mo file.
Unfortunately, babel's setup command isn't built very extensible, so
most of the run() code is duplicated here.
"""
def run(self):
compile_catalog.run(self)
po_files = []
js_files = []
if not self.input_file:
if self.locale:
po_files.append((self.locale,
os.path.join(self.directory, self.locale,
'LC_MESSAGES',
self.domain + '.po')))
js_files.append(os.path.join(self.directory, self.locale,
'LC_MESSAGES',
self.domain + '.js'))
else:
for locale in os.listdir(self.directory):
po_file = os.path.join(self.directory, locale,
'LC_MESSAGES',
self.domain + '.po')
if os.path.exists(po_file):
po_files.append((locale, po_file))
js_files.append(os.path.join(self.directory, locale,
'LC_MESSAGES',
self.domain + '.js'))
else:
po_files.append((self.locale, self.input_file))
if self.output_file:
js_files.append(self.output_file)
else:
js_files.append(os.path.join(self.directory, self.locale,
'LC_MESSAGES',
self.domain + '.js'))
for js_file, (locale, po_file) in zip(js_files, po_files):
infile = open(po_file, 'r')
try:
catalog = read_po(infile, locale)
finally:
infile.close()
if catalog.fuzzy and not self.use_fuzzy:
continue
log.info('writing JavaScript strings in catalog %r to %r',
po_file, js_file)
jscatalog = {}
for message in catalog:
if any(x[0].endswith('.js') for x in message.locations):
msgid = message.id
if isinstance(msgid, (list, tuple)):
msgid = msgid[0]
jscatalog[msgid] = message.string
outfile = open(js_file, 'wb')
try:
outfile.write('Documentation.addTranslations(');
dump(dict(
messages=jscatalog,
plural_expr=catalog.plural_expr,
locale=str(catalog.locale)
), outfile)
outfile.write(');')
finally:
outfile.close()
cmdclass['compile_catalog'] = compile_catalog_plusjs
2008-02-09 17:09:36 -06:00
setup(
name='Sphinx',
version=sphinx.__version__,
2008-03-18 14:37:05 -05:00
url='http://sphinx.pocoo.org/',
download_url='http://pypi.python.org/pypi/Sphinx',
2008-02-09 17:09:36 -06:00
license='BSD',
author='Georg Brandl',
author_email='georg@python.org',
description='Python documentation generator',
2008-03-18 14:37:05 -05:00
long_description=long_desc,
2008-02-09 17:09:36 -06:00
zip_safe=False,
2008-03-21 12:20:09 -05:00
classifiers=[
2008-05-06 11:14:21 -05:00
'Development Status :: 4 - Beta',
2008-02-09 17:09:36 -06:00
'Environment :: Console',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Documentation',
'Topic :: Utilities',
],
platforms='any',
packages=find_packages(),
2008-02-09 17:09:36 -06:00
include_package_data=True,
entry_points={
'console_scripts': [
'sphinx-build = sphinx:main',
'sphinx-quickstart = sphinx.quickstart:main'
],
'distutils.commands': [
'build_sphinx = sphinx.setup_command:BuildDoc',
],
2008-02-09 17:09:36 -06:00
},
install_requires=requires,
cmdclass=cmdclass,
2008-02-09 17:09:36 -06:00
)