From: Hans-Christoph Steiner Date: Thu, 19 Oct 2017 16:00:04 +0000 (+0200) Subject: use Babel to compile localizations and include in source tarball X-Git-Tag: 0.9~50^2~5 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=fdroidserver.git;a=commitdiff_plain;h=49bd5a6462c8928b913ba445a18e6d276a7451bb use Babel to compile localizations and include in source tarball python3-babel was also included in the gitlab-ci docker image: https://gitlab.com/fdroid/ci-images-server/commit/ffc08dbc1daabfda725de41b712497708213b00e --- diff --git a/.travis.yml b/.travis.yml index 9d78587c..3dab550a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,7 @@ addons: - dash - pylint - pep8 + - python3-babel - python3-dev - python3-pip - python3-ruamel.yaml diff --git a/setup.cfg b/setup.cfg index 1cca6643..afaf13e2 100644 --- 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 diff --git a/setup.py b/setup.py index 4a680536..03638db0 100644 --- 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', diff --git a/tests/complete-ci-tests b/tests/complete-ci-tests index bd7e7366..1959f858 100755 --- a/tests/complete-ci-tests +++ b/tests/complete-ci-tests @@ -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