Mercurial > babel > mirror
annotate setup.py @ 128:4d22fc662988 trunk
Fake `sys.argv` for CLI tests.
author | cmlenz |
---|---|
date | Mon, 18 Jun 2007 17:13:09 +0000 |
parents | 1984cdac1ddb |
children | bd3b47492396 |
rev | line source |
---|---|
1 | 1 #!/usr/bin/env python |
2 # -*- coding: utf-8 -*- | |
3 # | |
4 # Copyright (C) 2007 Edgewall Software | |
5 # All rights reserved. | |
6 # | |
7 # This software is licensed as described in the file COPYING, which | |
8 # you should have received as part of this distribution. The terms | |
9 # are also available at http://babel.edgewall.org/wiki/License. | |
10 # | |
11 # This software consists of voluntary contributions made by many | |
12 # individuals. For the exact contribution history, see the revision | |
13 # history and logs, available at http://babel.edgewall.org/log/. | |
14 | |
12
e6ba3e878b10
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
1
diff
changeset
|
15 from distutils.cmd import Command |
1 | 16 import doctest |
17 from glob import glob | |
18 import os | |
12
e6ba3e878b10
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
1
diff
changeset
|
19 try: |
e6ba3e878b10
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
1
diff
changeset
|
20 from setuptools import setup |
e6ba3e878b10
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
1
diff
changeset
|
21 except ImportError: |
e6ba3e878b10
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
1
diff
changeset
|
22 from distutils.core import setup |
1 | 23 import sys |
24 | |
25 | |
26 class build_doc(Command): | |
27 description = 'Builds the documentation' | |
98
f5cfd37ec37e
Add `--without-apidocs` switch to `build_doc` command for quicker doc-edit/review cycles.
cmlenz
parents:
57
diff
changeset
|
28 user_options = [ |
116
1984cdac1ddb
Moved doc config into a subdirectory, and added a `--force` option to the `build_doc` command.
cmlenz
parents:
98
diff
changeset
|
29 ('force', None, |
1984cdac1ddb
Moved doc config into a subdirectory, and added a `--force` option to the `build_doc` command.
cmlenz
parents:
98
diff
changeset
|
30 "force regeneration even if no reStructuredText files have changed"), |
98
f5cfd37ec37e
Add `--without-apidocs` switch to `build_doc` command for quicker doc-edit/review cycles.
cmlenz
parents:
57
diff
changeset
|
31 ('without-apidocs', None, |
f5cfd37ec37e
Add `--without-apidocs` switch to `build_doc` command for quicker doc-edit/review cycles.
cmlenz
parents:
57
diff
changeset
|
32 "whether to skip the generation of API documentaton"), |
f5cfd37ec37e
Add `--without-apidocs` switch to `build_doc` command for quicker doc-edit/review cycles.
cmlenz
parents:
57
diff
changeset
|
33 ] |
116
1984cdac1ddb
Moved doc config into a subdirectory, and added a `--force` option to the `build_doc` command.
cmlenz
parents:
98
diff
changeset
|
34 boolean_options = ['force', 'without-apidocs'] |
1 | 35 |
36 def initialize_options(self): | |
116
1984cdac1ddb
Moved doc config into a subdirectory, and added a `--force` option to the `build_doc` command.
cmlenz
parents:
98
diff
changeset
|
37 self.force = False |
98
f5cfd37ec37e
Add `--without-apidocs` switch to `build_doc` command for quicker doc-edit/review cycles.
cmlenz
parents:
57
diff
changeset
|
38 self.without_apidocs = False |
1 | 39 |
40 def finalize_options(self): | |
41 pass | |
42 | |
43 def run(self): | |
44 from docutils.core import publish_cmdline | |
40 | 45 from docutils.nodes import raw |
46 from docutils.parsers import rst | |
47 | |
116
1984cdac1ddb
Moved doc config into a subdirectory, and added a `--force` option to the `build_doc` command.
cmlenz
parents:
98
diff
changeset
|
48 docutils_conf = os.path.join('doc', 'conf', 'docutils.ini') |
1984cdac1ddb
Moved doc config into a subdirectory, and added a `--force` option to the `build_doc` command.
cmlenz
parents:
98
diff
changeset
|
49 epydoc_conf = os.path.join('doc', 'conf', 'epydoc.ini') |
1 | 50 |
40 | 51 try: |
52 from pygments import highlight | |
53 from pygments.lexers import get_lexer_by_name | |
54 from pygments.formatters import HtmlFormatter | |
55 | |
56 def code_block(name, arguments, options, content, lineno, | |
57 content_offset, block_text, state, state_machine): | |
58 lexer = get_lexer_by_name(arguments[0]) | |
59 html = highlight('\n'.join(content), lexer, HtmlFormatter()) | |
60 return [raw('', html, format='html')] | |
61 code_block.arguments = (1, 0, 0) | |
62 code_block.options = {'language' : rst.directives.unchanged} | |
63 code_block.content = 1 | |
64 rst.directives.register_directive('code-block', code_block) | |
65 except ImportError: | |
66 print 'Pygments not installed, syntax highlighting disabled' | |
67 | |
1 | 68 for source in glob('doc/*.txt'): |
69 dest = os.path.splitext(source)[0] + '.html' | |
116
1984cdac1ddb
Moved doc config into a subdirectory, and added a `--force` option to the `build_doc` command.
cmlenz
parents:
98
diff
changeset
|
70 if self.force or not os.path.exists(dest) or \ |
1984cdac1ddb
Moved doc config into a subdirectory, and added a `--force` option to the `build_doc` command.
cmlenz
parents:
98
diff
changeset
|
71 os.path.getmtime(dest) < os.path.getmtime(source): |
1 | 72 print 'building documentation file %s' % dest |
73 publish_cmdline(writer_name='html', | |
74 argv=['--config=%s' % docutils_conf, source, | |
75 dest]) | |
76 | |
98
f5cfd37ec37e
Add `--without-apidocs` switch to `build_doc` command for quicker doc-edit/review cycles.
cmlenz
parents:
57
diff
changeset
|
77 if not self.without_apidocs: |
f5cfd37ec37e
Add `--without-apidocs` switch to `build_doc` command for quicker doc-edit/review cycles.
cmlenz
parents:
57
diff
changeset
|
78 try: |
f5cfd37ec37e
Add `--without-apidocs` switch to `build_doc` command for quicker doc-edit/review cycles.
cmlenz
parents:
57
diff
changeset
|
79 from epydoc import cli |
f5cfd37ec37e
Add `--without-apidocs` switch to `build_doc` command for quicker doc-edit/review cycles.
cmlenz
parents:
57
diff
changeset
|
80 old_argv = sys.argv[1:] |
f5cfd37ec37e
Add `--without-apidocs` switch to `build_doc` command for quicker doc-edit/review cycles.
cmlenz
parents:
57
diff
changeset
|
81 sys.argv[1:] = [ |
f5cfd37ec37e
Add `--without-apidocs` switch to `build_doc` command for quicker doc-edit/review cycles.
cmlenz
parents:
57
diff
changeset
|
82 '--config=%s' % epydoc_conf, |
f5cfd37ec37e
Add `--without-apidocs` switch to `build_doc` command for quicker doc-edit/review cycles.
cmlenz
parents:
57
diff
changeset
|
83 '--no-private', # epydoc bug, not read from config |
f5cfd37ec37e
Add `--without-apidocs` switch to `build_doc` command for quicker doc-edit/review cycles.
cmlenz
parents:
57
diff
changeset
|
84 '--simple-term', |
f5cfd37ec37e
Add `--without-apidocs` switch to `build_doc` command for quicker doc-edit/review cycles.
cmlenz
parents:
57
diff
changeset
|
85 '--verbose' |
f5cfd37ec37e
Add `--without-apidocs` switch to `build_doc` command for quicker doc-edit/review cycles.
cmlenz
parents:
57
diff
changeset
|
86 ] |
f5cfd37ec37e
Add `--without-apidocs` switch to `build_doc` command for quicker doc-edit/review cycles.
cmlenz
parents:
57
diff
changeset
|
87 cli.cli() |
f5cfd37ec37e
Add `--without-apidocs` switch to `build_doc` command for quicker doc-edit/review cycles.
cmlenz
parents:
57
diff
changeset
|
88 sys.argv[1:] = old_argv |
1 | 89 |
98
f5cfd37ec37e
Add `--without-apidocs` switch to `build_doc` command for quicker doc-edit/review cycles.
cmlenz
parents:
57
diff
changeset
|
90 except ImportError: |
f5cfd37ec37e
Add `--without-apidocs` switch to `build_doc` command for quicker doc-edit/review cycles.
cmlenz
parents:
57
diff
changeset
|
91 print 'epydoc not installed, skipping API documentation.' |
1 | 92 |
93 | |
94 class test_doc(Command): | |
95 description = 'Tests the code examples in the documentation' | |
96 user_options = [] | |
97 | |
98 def initialize_options(self): | |
99 pass | |
100 | |
101 def finalize_options(self): | |
102 pass | |
103 | |
104 def run(self): | |
105 for filename in glob('doc/*.txt'): | |
106 print 'testing documentation file %s' % filename | |
107 doctest.testfile(filename, False, optionflags=doctest.ELLIPSIS) | |
108 | |
109 | |
110 setup( | |
111 name = 'Babel', | |
112 version = '0.1', | |
113 description = 'Internationalization utilities', | |
114 long_description = \ | |
115 """A collection of tools for internationalizing Python applications.""", | |
116 author = 'Edgewall Software', | |
117 author_email = 'info@edgewall.org', | |
118 license = 'BSD', | |
119 url = 'http://babel.edgewall.org/', | |
120 download_url = 'http://babel.edgewall.org/wiki/Download', | |
121 zip_safe = False, | |
122 | |
123 classifiers = [ | |
124 'Development Status :: 4 - Beta', | |
125 'Environment :: Web Environment', | |
126 'Intended Audience :: Developers', | |
127 'License :: OSI Approved :: BSD License', | |
128 'Operating System :: OS Independent', | |
129 'Programming Language :: Python', | |
130 'Topic :: Software Development :: Libraries :: Python Modules', | |
131 ], | |
54
7dbcbc3f07e0
Rename the `babel.catalog` package to `babel.messages` for consistency with the other package names.
cmlenz
parents:
52
diff
changeset
|
132 packages = ['babel', 'babel.messages'], |
1 | 133 package_data = {'babel': ['localedata/*.dat']}, |
134 test_suite = 'babel.tests.suite', | |
135 | |
136 entry_points = """ | |
137 [console_scripts] | |
54
7dbcbc3f07e0
Rename the `babel.catalog` package to `babel.messages` for consistency with the other package names.
cmlenz
parents:
52
diff
changeset
|
138 babel = babel.messages.frontend:main |
1 | 139 |
140 [distutils.commands] | |
54
7dbcbc3f07e0
Rename the `babel.catalog` package to `babel.messages` for consistency with the other package names.
cmlenz
parents:
52
diff
changeset
|
141 extract_messages = babel.messages.frontend:extract_messages |
7dbcbc3f07e0
Rename the `babel.catalog` package to `babel.messages` for consistency with the other package names.
cmlenz
parents:
52
diff
changeset
|
142 new_catalog = babel.messages.frontend:new_catalog |
1 | 143 |
49
37bd476dafe4
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
40
diff
changeset
|
144 [distutils.setup_keywords] |
54
7dbcbc3f07e0
Rename the `babel.catalog` package to `babel.messages` for consistency with the other package names.
cmlenz
parents:
52
diff
changeset
|
145 message_extractors = babel.messages.frontend:check_message_extractors |
49
37bd476dafe4
Support a `message_extractors` keyword argument directly in `setup()`. Closes #4.
cmlenz
parents:
40
diff
changeset
|
146 |
1 | 147 [babel.extractors] |
54
7dbcbc3f07e0
Rename the `babel.catalog` package to `babel.messages` for consistency with the other package names.
cmlenz
parents:
52
diff
changeset
|
148 genshi = babel.messages.extract:extract_genshi |
7dbcbc3f07e0
Rename the `babel.catalog` package to `babel.messages` for consistency with the other package names.
cmlenz
parents:
52
diff
changeset
|
149 python = babel.messages.extract:extract_python |
57
d930a3dfbf3d
* The `extract_messages` distutils command now operators on configurable input directories again, instead of the complete current directory. The `input_dirs` default to the package directories.
cmlenz
parents:
54
diff
changeset
|
150 ignore = babel.messages.extract:extract_nothing |
1 | 151 """, |
152 | |
153 cmdclass = {'build_doc': build_doc, 'test_doc': test_doc} | |
154 ) |