Compile translation files on install

Solution based on https://stackoverflow.com/questions/40051076/compile-translation-files-when-calling-setup-py-install
This commit is contained in:
FestplattenSchnitzel 2021-09-07 14:37:19 +02:00
parent dccfc2f712
commit 23a4135ccd
No known key found for this signature in database
GPG key ID: 1B4181FC97673B9D
3 changed files with 41 additions and 24 deletions

View file

@ -7,6 +7,8 @@ import re
import subprocess
import sys
from setuptools.command.install import install
class VersionCheckCommand(Command):
"""Make sure git tag and version match before uploading"""
@ -28,6 +30,17 @@ class VersionCheckCommand(Command):
print('Upload using: twine upload --sign dist/fdroidserver-%s.tar.gz' % version)
class InstallWithCompile(install):
def run(self):
from babel.messages.frontend import compile_catalog
compiler = compile_catalog(self.distribution)
option_dict = self.distribution.get_option_dict('compile_catalog')
compiler.domain = [option_dict['domain'][1]]
compiler.directory = option_dict['directory'][1]
compiler.run()
super().run()
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):
@ -43,7 +56,8 @@ def get_data_files():
['buildserver/config.buildserver.yml', ]
+ 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):
for f in re.findall(r'include (locale/[a-z][a-z][a-zA-Z_]*/LC_MESSAGES/fdroidserver\.)po', data):
f += 'mo'
d = os.path.join(data_prefix, 'share', os.path.dirname(f))
data_files.append((d, [f, ]))
return data_files
@ -68,7 +82,10 @@ setup(name='fdroidserver',
},
data_files=get_data_files(),
python_requires='>=3.5',
cmdclass={'versioncheck': VersionCheckCommand},
cmdclass={
'versioncheck': VersionCheckCommand,
'install': InstallWithCompile,
},
setup_requires=[
'babel',
],