我怎样才能确保setup.py编译项目PO文件,包括他们时创建一个sdist。这是一个Django应用程序和手动处理,生成MO文件是以下在应用程序的根目录的命令来运行:

django-admin compilemessages

(这意味着会比setup.py更深一层)

我想避免手动每次编译MO文件。我不想将它们存储在库中的。

有帮助吗?

解决方案

from django.core.management.commands.compilemessages import compile_messages

和你setup.py方法运行之前setup然后包括创建的文件用它在你的setup脚本。

其他提示

我的简单的解决方案(从得到了一些Trac的想法):

#!/usr/bin/env python
from setuptools import setup, find_packages
from setuptools.command.install_lib import install_lib as _install_lib
from distutils.command.build import build as _build
from distutils.cmd import Command


class compile_translations(Command):
    description = 'compile message catalogs to MO files via django compilemessages'
    user_options = []

    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

    def run(self):
        import os
        import sys
        from django.core.management.commands.compilemessages import \
            compile_messages
        curdir = os.getcwd()
        os.chdir(os.path.realpath('app_name'))
        compile_messages(stderr=sys.stderr)
        os.chdir(curdir)


class build(_build):
    sub_commands = [('compile_translations', None)] + _build.sub_commands


class install_lib(_install_lib):
    def run(self):
        self.run_command('compile_translations')
        _install_lib.run(self)

setup(name='app',
    packages=find_packages(),
    include_package_data=True,
    setup_requires=['django'],
    ...
    cmdclass={'build': build, 'install_lib': install_lib,
        'compile_translations': compile_translations}
)

这将帮助你编译当你构建蛋po文件或安装包。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top