chiark / gitweb /
use Babel to compile localizations and include in source tarball
authorHans-Christoph Steiner <hans@eds.org>
Thu, 19 Oct 2017 16:00:04 +0000 (18:00 +0200)
committerHans-Christoph Steiner <hans@eds.org>
Thu, 19 Oct 2017 21:28:13 +0000 (23:28 +0200)
python3-babel was also included in the gitlab-ci docker image:
https://gitlab.com/fdroid/ci-images-server/commit/ffc08dbc1daabfda725de41b712497708213b00e

.travis.yml
setup.cfg
setup.py
tests/complete-ci-tests

index 9d78587c951db9a42d69c471b3fc64ab4f91df39..3dab550ad16be87b6f107995870f1c5e515fb8e4 100644 (file)
@@ -28,6 +28,7 @@ addons:
     - dash
     - pylint
     - pep8
+    - python3-babel
     - python3-dev
     - python3-pip
     - python3-ruamel.yaml
index 1cca664328fb3dd7038346da7fabf07ef61708cd..afaf13e21977e6e378afd59ed27c76c2c2c3df4d 100644 (file)
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,3 +1,37 @@
 
 [aliases]
-release = register sdist upload --sign
+release = register compile_catalog sdist upload --sign
+
+# All this below is for Babel config.  Ideally we would only use
+# Babel, but it is still missing some key features that gettext gives
+# us.  So for now, this Babel setup is just to make it easy for Python
+# people who are used to it.  Babel is missing:
+#
+# * properly tagging various Python formats in the comments
+# * --add-location=file
+# * --join-existing
+# * --sort-output on update
+#
+# So for now the canonical way to update the template and translation
+# files is: `make -C locale`
+
+[extract_messages]
+keywords = _
+charset = UTF-8
+sort_output = true
+no_location = true
+add-comments = true
+output_file = locale/fdroidserver.pot
+msgid-bugs-address = https://gitlab.com/fdroid/fdroidserver/issues
+
+[update_catalog]
+output_dir = locale
+input_file = locale/fdroidserver.pot
+
+[init_catalog]
+input_file = locale/fdroidserver.pot
+output_dir = locale
+
+[compile_catalog]
+domain = fdroidserver
+directory = locale
index 4a68053674044a2989855d7c33c9372f9fab1c4d..03638db02a7c11d878eda6f72355ca95b8646e03 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -2,14 +2,31 @@
 
 from setuptools import setup
 import os
+import re
 import shutil
 import sys
 
-# workaround issue on OSX or --user installs, where sys.prefix is not an installable location
-if os.access(sys.prefix, os.W_OK | os.X_OK):
-    data_prefix = sys.prefix
-else:
-    data_prefix = '.'
+
+def get_data_files():
+    # workaround issue on OSX or --user installs, where sys.prefix is not an installable location
+    if os.access(sys.prefix, os.W_OK | os.X_OK):
+        data_prefix = sys.prefix
+    else:
+        data_prefix = '.'
+
+    data_files = []
+    with open('MANIFEST.in') as fp:
+        data = fp.read()
+
+    data_files.append((data_prefix + '/share/doc/fdroidserver/examples',
+                       ['buildserver/config.buildserver.py', ]
+                       + re.findall(r'include (examples/.*)', data)))
+
+    for f in re.findall(r'include (locale/[a-z][a-z][a-zA-Z_]*/LC_MESSAGES/fdroidserver.mo)', data):
+        d = os.path.join(data_prefix, 'share', os.path.dirname(f))
+        data_files.append((d, [f, ]))
+    return data_files
+
 
 # PyPI accepts reST not Markdown
 if os.path.exists('README.md'):
@@ -37,16 +54,7 @@ setup(name='fdroidserver',
       license='AGPL-3.0',
       packages=['fdroidserver', 'fdroidserver.asynchronousfilereader'],
       scripts=['fdroid', 'fd-commit', 'makebuildserver'],
-      data_files=[
-          (data_prefix + '/share/doc/fdroidserver/examples',
-              ['buildserver/config.buildserver.py',
-               'examples/config.py',
-               'examples/fdroid-icon.png',
-               'examples/makebuildserver.config.py',
-               'examples/opensc-fdroid.cfg',
-               'examples/public-read-only-s3-bucket-policy.json',
-               'examples/template.yml']),
-      ],
+      data_files=get_data_files(),
       python_requires='>=3.4',
       install_requires=[
           'clint',
index bd7e736698ff2a5ef1a4393b22a6cbee3eb32846..1959f858da8f420ca4a861bef2bd3ded881061d0 100755 (executable)
@@ -63,7 +63,10 @@ fi
 #------------------------------------------------------------------------------#
 # test building the source tarball, then installing it
 cd $WORKSPACE
-python3 setup.py sdist
+python3 setup.py compile_catalog sdist
+
+# make sure translation files got compiled and included
+tar tzf dist/fdroidserver-*.tar.gz | grep locale/de/LC_MESSAGES/fdroidserver.mo
 
 rm -rf $WORKSPACE/env
 $pyvenv $WORKSPACE/env
@@ -72,6 +75,9 @@ $pyvenv $WORKSPACE/env
 pip3 install --quiet setuptools==33.1.1
 pip3 install --quiet dist/fdroidserver-*.tar.gz
 
+# make sure translation files were installed
+test -e $WORKSPACE/env/share/locale/de/LC_MESSAGES/fdroidserver.mo
+
 # run tests in new pip+pyvenv install
 fdroid=$WORKSPACE/env/bin/fdroid $WORKSPACE/tests/run-tests $apksource
 
@@ -83,9 +89,12 @@ rm -rf $WORKSPACE/env
 $pyvenv $WORKSPACE/env
 . $WORKSPACE/env/bin/activate
 # workaround https://github.com/pypa/setuptools/issues/937
-pip3 install --quiet setuptools==33.1.1
+pip3 install --quiet setuptools==33.1.1 Babel
 pip3 install --quiet -e $WORKSPACE
-python3 setup.py install
+python3 setup.py compile_catalog install
+
+# make sure translation files were installed
+test -e $WORKSPACE/env/share/locale/de/LC_MESSAGES/fdroidserver.mo
 
 # run tests in new pip+pyvenv install
 fdroid=$WORKSPACE/env/bin/fdroid $WORKSPACE/tests/run-tests $apksource