This package compiles po files. It contains a zest.releaser entrypoint and a stand-alone command line tool.
You want to release a package that has a
locale, or something else as long as it has a
LC_MESSAGES folder somewhere in it)
with translations in
You want to include the compiled
.mo files in your release as well,
but you do not want to keep those in a revision control system (like git) as they are binary and can be easily recreated.
That is good.
This package helps with that.
.mo files? Add a
When you use
python setup.py sdist to create a source distribution, Python does not automatically include all files.
It might look at the information of the revision control system (RCS), but that may or may not work.
This depends on your RCS, your Python version, setuptools, or extra packages like
Since the compiled
.mo files are best not stored in git (or any other RCS), you need to give a hint on which files to include.
You do this by adding a
Let's say your package has roughly these contents (not all files are shown):
Then you need a
MANIFEST.in file like this:
recursive-include your *
Or with a bigger example:
recursive-include your * recursive-include docs * include * global-exclude *.pyc
I will explain the lines one by one for clarity.
And yes: I (Maurits) now simply go to this page on PyPI if I want to have an example of a proper
So this documentation is now getting slightly larger than strictly needed. :-)
recursive-include your *
- This tells distutils to recursively include all (
*) files and directories within the
yourdirectory. Try it: create a directory structure like the above example with a proper
setup.py, copy the
domain.moas a silly test, run
python setup.py sdistand check that the
.mofile ends up in the created distribution.
recursive-include docs *
- Include files in the
docsdirectory. If this directory does not exist, you will get a warning, so you may want to remove it then, but leaving it there does not hurt.
- Include unrecognized files in the root directory.
Oterwise by default only standard files like
setup.cfgare included. So for example a
CHANGES.txtfile must be explicitly included (here with
- This avoids unnecessarily adding compiled python files in the release.
When these are not there, for example after a fresh checkout, you will get a harmless warning:
no previously-included files matching '*.pyc' found anywhere in distribution.
With this part working, the only thing this
zest.pocompile package needs to do, is to actually find all
.po files and compile them to
It simply looks for directories that are named
LC_MESSAGES and compiles all
.po files found in there.
Command line tool
pip install zest.pocompile you get a command line tool
When you run it, this walks the current directory, finds all po translation files in a properly formed locales directory, and compiles them into
You can also give it a list of directories as arguments instead.
Run it with the
--help option to get some help.
In the above example, if you are in the
your.package directory and run
pocompile it will create this file:
zest.releaser entry point
You do not need zest.releaser for a proper functioning of
But if you use the two together, in combination with a proper
MANIFEST.in file, releasing a source distribution with compiled
.mo files is made easy.
fullrelease) command of
zest.releaser creates a (git or other) tag and checks out this tag.
Then it creates a source distribution (
sdist) and possibly a wheel (
bdist_wheel) and uploads it to PyPI.
zest.pocompile is added to the mix, it compiles the
.po files immediately after checking out the tag.
This is right in time for creating the distributions, which should now contain the
You may want the full release to fail early when
zest.pocompile is not available.
Since version 1.6.0 this is possible by editing the
setup.cfg of the package where you want this, and add the following section:
[zest.releaser] prereleaser.before = zest.pocompile.available
This package has been cobbled together by Maurits van Rees.
The main functions are taken from the
build_mo command of collective.releaser.
- Add tests.