Re: [Distutils] setup.py, data_files and i18n
Hei Erik, Thanks… That does the trick! But there is still an issue regarding where the files will be installed. On Ubuntu, it goes to: /usr/local/share/locale and this does not work because gettext looks at: /usr/share/locale On mac (lion), however, it works. The installed failed go to: /System/Library/Frameworks/Python.framework/Versions/2.7/share/locale/ And gettext looks at: /opt/local/share/locale Even though, python seems to pick up the l10n right. The same does not happen in Linux, unless I force the setup.py to install in /usr path… How can I tell python to look for that directory in particular instead of the default? My concern here is that I should not hard-code this path in the gettext.translation() method, which would then not work for other people with non-standard locations, or on mac, or on Windows… I read about setting up m4 alike strings in python code that would be replaced by distutils upon compilation, but I could not find any reference for that, neither if that is a solution for my problem. Thanks for your help. -- Braga, Bruno www.brunobraga.net (http://www.brunobraga.net/) bruno.braga@gmail.com (mailto:bruno.braga@gmail.com) On Tuesday, 6 March 2012 at 5:35 AM, Erik Bray wrote:
On Thu, Mar 1, 2012 at 11:02 PM, BRAGA, Bruno
wrote: Hi,
I am working on a project written in Python, and I would like to use i18n functionality, but I am having some issues with it, more specifically regarding the .mo files location, and I was hoping someone here could point me in the right direction.
(1) i18n mo files location
Basically, I already know how to translate contents with gettext, but I got stuck with the fact that it, by default, looks at /usr/share/locale/{language} (in Linux), but the setup.py install data_files into /usr/local/share/... unless I forcibly use absolute paths toward the location where the files should be.
(2) install_data.data_files
Also, I am having a problem to install the data_files, because the install_data command is never called. I made it work before, but I don't understand what I am missing that worked before and not now.
Here is the setup.py script: https://github.com/brunobraga/termsaver/blob/master/setup.py
And this is the i18n module I am using as base for localizing all text in the application: https://github.com/brunobraga/termsaver/blob/master/termsaverlib/i18n.py
Here is the output of a clean install:
bruno@development3;~$ sudo python setup.py install --record /tmp/termsaver.install.record.txt [sudo] password for bruno: running install running build running build_py creating build creating build/lib.linux-i686-2.7 creating build/lib.linux-i686-2.7/termsaverlib copying termsaverlib/constants.py -> build/lib.linux-i686-2.7/termsaverlib copying termsaverlib/i18n.py -> build/lib.linux-i686-2.7/termsaverlib copying termsaverlib/common.py -> build/lib.linux-i686-2.7/termsaverlib copying termsaverlib/exception.py -> build/lib.linux-i686-2.7/termsaverlib copying termsaverlib/__init__.py -> build/lib.linux-i686-2.7/termsaverlib creating build/lib.linux-i686-2.7/termsaverlib/screen copying termsaverlib/screen/programmer.py -> build/lib.linux-i686-2.7/termsaverlib/screen copying termsaverlib/screen/rssfeed.py -> build/lib.linux-i686-2.7/termsaverlib/screen copying termsaverlib/screen/rfc.py -> build/lib.linux-i686-2.7/termsaverlib/screen copying termsaverlib/screen/urlfetcher.py -> build/lib.linux-i686-2.7/termsaverlib/screen copying termsaverlib/screen/jokes4all.py -> build/lib.linux-i686-2.7/termsaverlib/screen copying termsaverlib/screen/dot.py -> build/lib.linux-i686-2.7/termsaverlib/screen copying termsaverlib/screen/__init__.py -> build/lib.linux-i686-2.7/termsaverlib/screen copying termsaverlib/screen/asciiartfarts.py -> build/lib.linux-i686-2.7/termsaverlib/screen copying termsaverlib/screen/quotes4all.py -> build/lib.linux-i686-2.7/termsaverlib/screen copying termsaverlib/screen/randtxt.py -> build/lib.linux-i686-2.7/termsaverlib/screen creating build/lib.linux-i686-2.7/termsaverlib/screen/base copying termsaverlib/screen/base/rssfeed.py -> build/lib.linux-i686-2.7/termsaverlib/screen/base copying termsaverlib/screen/base/urlfetcher.py -> build/lib.linux-i686-2.7/termsaverlib/screen/base copying termsaverlib/screen/base/filereader.py -> build/lib.linux-i686-2.7/termsaverlib/screen/base copying termsaverlib/screen/base/__init__.py -> build/lib.linux-i686-2.7/termsaverlib/screen/base creating build/lib.linux-i686-2.7/termsaverlib/screen/helper copying termsaverlib/screen/helper/position.py -> build/lib.linux-i686-2.7/termsaverlib/screen/helper copying termsaverlib/screen/helper/urlfetcher.py -> build/lib.linux-i686-2.7/termsaverlib/screen/helper copying termsaverlib/screen/helper/typing.py -> build/lib.linux-i686-2.7/termsaverlib/screen/helper copying termsaverlib/screen/helper/xmlreader.py -> build/lib.linux-i686-2.7/termsaverlib/screen/helper copying termsaverlib/screen/helper/__init__.py -> build/lib.linux-i686-2.7/termsaverlib/screen/helper running build_scripts creating build/scripts-2.7 copying and adjusting termsaver -> build/scripts-2.7 changing mode of build/scripts-2.7/termsaver from 644 to 755 running build_trans Compiling locale/ja.po Compiling locale/en.po running install_lib creating /usr/local/lib/python2.7/dist-packages/termsaverlib copying build/lib.linux-i686-2.7/termsaverlib/constants.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib creating /usr/local/lib/python2.7/dist-packages/termsaverlib/screen copying build/lib.linux-i686-2.7/termsaverlib/screen/programmer.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib/screen copying build/lib.linux-i686-2.7/termsaverlib/screen/rssfeed.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib/screen copying build/lib.linux-i686-2.7/termsaverlib/screen/rfc.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib/screen copying build/lib.linux-i686-2.7/termsaverlib/screen/urlfetcher.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib/screen copying build/lib.linux-i686-2.7/termsaverlib/screen/jokes4all.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib/screen copying build/lib.linux-i686-2.7/termsaverlib/screen/dot.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib/screen creating /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/base copying build/lib.linux-i686-2.7/termsaverlib/screen/base/rssfeed.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/base copying build/lib.linux-i686-2.7/termsaverlib/screen/base/urlfetcher.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/base copying build/lib.linux-i686-2.7/termsaverlib/screen/base/filereader.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/base copying build/lib.linux-i686-2.7/termsaverlib/screen/base/__init__.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/base copying build/lib.linux-i686-2.7/termsaverlib/screen/__init__.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib/screen copying build/lib.linux-i686-2.7/termsaverlib/screen/asciiartfarts.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib/screen creating /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/helper copying build/lib.linux-i686-2.7/termsaverlib/screen/helper/position.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/helper copying build/lib.linux-i686-2.7/termsaverlib/screen/helper/urlfetcher.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/helper copying build/lib.linux-i686-2.7/termsaverlib/screen/helper/typing.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/helper copying build/lib.linux-i686-2.7/termsaverlib/screen/helper/xmlreader.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/helper copying build/lib.linux-i686-2.7/termsaverlib/screen/helper/__init__.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/helper copying build/lib.linux-i686-2.7/termsaverlib/screen/quotes4all.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib/screen copying build/lib.linux-i686-2.7/termsaverlib/screen/randtxt.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib/screen copying build/lib.linux-i686-2.7/termsaverlib/i18n.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib copying build/lib.linux-i686-2.7/termsaverlib/common.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib copying build/lib.linux-i686-2.7/termsaverlib/exception.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib copying build/lib.linux-i686-2.7/termsaverlib/__init__.py -> /usr/local/lib/python2.7/dist-packages/termsaverlib byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/constants.py to constants.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/programmer.py to programmer.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/rssfeed.py to rssfeed.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/rfc.py to rfc.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/urlfetcher.py to urlfetcher.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/jokes4all.py to jokes4all.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/dot.py to dot.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/base/rssfeed.py to rssfeed.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/base/urlfetcher.py to urlfetcher.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/base/filereader.py to filereader.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/base/__init__.py to __init__.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/__init__.py to __init__.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/asciiartfarts.py to asciiartfarts.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/helper/position.py to position.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/helper/urlfetcher.py to urlfetcher.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/helper/typing.py to typing.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/helper/xmlreader.py to xmlreader.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/helper/__init__.py to __init__.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/quotes4all.py to quotes4all.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/screen/randtxt.py to randtxt.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/i18n.py to i18n.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/common.py to common.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/exception.py to exception.pyc byte-compiling /usr/local/lib/python2.7/dist-packages/termsaverlib/__init__.py to __init__.pyc running install_scripts copying build/scripts-2.7/termsaver -> /usr/local/bin changing mode of /usr/local/bin/termsaver to 755 running install_egg_info Writing /usr/local/lib/python2.7/dist-packages/termsaver-0.1_beta.egg-info writing list of installed files to '/tmp/termsaver.install.record.txt' Thank you for trying termsaver. bruno@development3;~$
Any help is much appreciated. I found very hard to do anything with distutils unless I open the source and see by myself what it can do or not... I was hoping there is a better way.
Thank you in advance,
Unfortunately, the install command won't actually run the install_data command as a sub-command unless a non-empty list was passed to data_files command in setup().
But I don't think your custom InstallData command is particularly necessary. Try removing InstallData and instead do something like this:
data_files = [(os.path.join('share', 'locale', lang[:-3], 'LC_MESSAGES'), [os.path.join('build', 'locale', lang[:-3], 'LC_MESSAGES', 'termsaver.mo')]) for lang in os.listdir('locale')]
and
setup( ... data_files=data_files, ...)
That should do what you're trying to do.
Erik
participants (1)
-
Bruno Braga