summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorAdam Turner <9087854+AA-Turner@users.noreply.github.com>2022-04-16 19:35:20 +0100
committerAdam Turner <9087854+AA-Turner@users.noreply.github.com>2022-04-16 20:01:03 +0100
commit1e443bdcb4fafd77c5ca3b91def00857900dceef (patch)
tree221038e8892a7b7669ddd9f92169891e2b2aea5c /setup.py
parent301c7bdf57eee47426c9ad4d96392bff623ee6c3 (diff)
downloadsphinx-git-1e443bdcb4fafd77c5ca3b91def00857900dceef.tar.gz
Move `compile_catalog_plusjs` to `utils/`
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py117
1 files changed, 0 insertions, 117 deletions
diff --git a/setup.py b/setup.py
index ccadd59f4..860aae57e 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,4 @@
-import os
import sys
-from io import StringIO
from setuptools import find_packages, setup
@@ -57,120 +55,6 @@ extras_require = {
],
}
-# Provide a "compile_catalog" command that also creates the translated
-# JavaScript files if Babel is available.
-
-cmdclass = {}
-
-
-class Tee:
- def __init__(self, stream):
- self.stream = stream
- self.buffer = StringIO()
-
- def write(self, s):
- self.stream.write(s)
- self.buffer.write(s)
-
- def flush(self):
- self.stream.flush()
-
-
-try:
- from json import dump
-
- from babel.messages.frontend import compile_catalog
- from babel.messages.pofile import read_po
-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):
- try:
- sys.stderr = Tee(sys.stderr)
- compile_catalog.run(self)
- finally:
- if sys.stderr.buffer.getvalue():
- print("Compiling failed.")
- sys.exit(1)
-
- if isinstance(self.domain, list):
- for domain in self.domain:
- self._run_domain_js(domain)
- else:
- self._run_domain_js(self.domain)
-
- def _run_domain_js(self, domain):
- 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',
- domain + '.po')))
- js_files.append(os.path.join(self.directory, self.locale,
- 'LC_MESSAGES',
- domain + '.js'))
- else:
- for locale in os.listdir(self.directory):
- po_file = os.path.join(self.directory, locale,
- 'LC_MESSAGES',
- 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',
- 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',
- domain + '.js'))
-
- for js_file, (locale, po_file) in zip(js_files, po_files):
- with open(po_file, encoding='utf8') as infile:
- catalog = read_po(infile, locale)
-
- if catalog.fuzzy and not self.use_fuzzy:
- continue
-
- self.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', '.js_t', '.html'))
- for x in message.locations):
- msgid = message.id
- if isinstance(msgid, (list, tuple)):
- msgid = msgid[0]
- jscatalog[msgid] = message.string
-
- with open(js_file, 'wt', encoding='utf8') as outfile:
- outfile.write('Documentation.addTranslations(')
- dump({
- 'messages': jscatalog,
- 'plural_expr': catalog.plural_expr,
- 'locale': str(catalog.locale)
- }, outfile, sort_keys=True, indent=4)
- outfile.write(');')
-
- cmdclass['compile_catalog'] = compile_catalog_plusjs
-
-
setup(
name='Sphinx',
version=sphinx.__version__,
@@ -246,5 +130,4 @@ setup(
python_requires=">=3.6",
install_requires=install_requires,
extras_require=extras_require,
- cmdclass=cmdclass,
)