Edgewall Software

Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#7877 closed defect (fixed)

KeyError: 'tracext/hg/../locale'

Reported by: adoleo@… Owned by: Christian Boos
Priority: high Milestone: not applicable
Component: plugin/mercurial Version: 0.12dev
Severity: major Keywords: mercurial
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:


Good evening! I switched to Mercurial from SVN over the weekend, and tonight I set about the task of updating Trac to support my new multirepo environment. After checking out the latest Trac-multirepo and TracMercurial versions from SVN, installing them, and restarting Apache2, I am greeted by the KeyError reproduced in the summary line above.

I think the problem is at line 173 of backend.py:

locale_dir = pkg_resources.resource_filename(name, '../locale')

I don't seem to have a tracext/locale directory anywhere. Let me know if I can provide more info.

Trac Version: 0.12multirepos-r7684-py2.5 TracMercurial Version:

Platform: Ubuntu 8.10-server amd64


Attachments (0)

Change History (7)

comment:1 by Christian Boos, 14 years ago

Milestone: not applicable
Priority: normalhigh

Ah yes, forgot to include this in the package_data. In the meantime you can use the plugin in development mode, i.e. from the checkout you do python setup.py develop.

comment:2 by Christian Boos, 14 years ago

Here's the modified setup.py file

#!/usr/bin/env python

from setuptools import setup, find_packages

extra = {}

    import babel
    extra['message_extractors'] = {
        'tracext': [
            ('**.py',                'python', None),
except ImportError:
TracMercurial = 'http://trac.edgewall.org/wiki/TracMercurial'

      install_requires='Trac >=0.12dev',
      description='Mercurial plugin for Trac 0.12',
      keywords='trac scm plugin mercurial hg',
      author='Christian Boos',
      This plugin for Trac 0.12 provides support for the Mercurial SCM.

      '''Actually, to take full benefit of this version of the plugin,
      the http://trac.edgewall.org/browser/sandbox/multirepos branch is
      See %s for more details.
      """ % TracMercurial,
      packages=['tracext', 'tracext.hg'],
          '': ['COPYING', 'README'],
          'tracext': ['locale/*.*', 'locale/*/LC_MESSAGES/*.*'],
      entry_points={'trac.plugins': 'hg = tracext.hg.backend'},

This produces an .egg which contains the translation files. When installed as unzipped, it works fine. But when installed as zipped, despite the zip_safe=False, it doesn't get unzipped automatically and therefore one still get the KeyError.

As I'm no setuptools expert, maybe someone could point me to what I missed? I have other zipped eggs which correctly get unzipped automatically (e.g. the sandbox/spam-filter-captcha one).

comment:3 by adoleo@…, 14 years ago

Wow, thanks for the quick response! Installing the plugin in development mode did the trick for now - thanks for the tip! I'm not very experienced in setuptools, so I'm not sure why it isn't unzipping, either. I'll play around with it tomorrow night, and if I figure out anything I'll let you know. Thanks again!

comment:4 by adoleo@…, 14 years ago

Now that I'm able to use it, I wanted to let you know that the multirepo feature is FANTASTIC! Great work!

comment:5 by Christian Boos, 13 years ago

Status: newassigned

zip_safe issue understood: the .egg file only gets unzipped when a file needed to be accessed. The problem here was that when using the following resource access:

pkg_resources.resource_filename(__name__, '../locale')

the file was not found, as explained by Jorge Vargas in googlegroups:Trac-dev:830e3ccd1f371ae6.

When changing that to 'tracext', 'locale', it worked. Now I should probably move locale below tracext/hg.

The actual setting of the zip_safe flag doesn't seem to matter (first, it's autodetected, second, even if set to True and the egg contains EGG-INGO/zip-safe flag, the locale files get extracted in a tracmercurial…egg-tmp/locale folder in the PYTHON_EGG_CACHE).

What should also be checked is whether the similar call to resource_filename(__name__, '../locale') in trac/util/translation.py will actually work when Trac is installed as an .egg or not.

comment:6 by Christian Boos, 13 years ago

Resolution: fixed
Status: assignedclosed

Fixed in r7901 and r7902.

Actually __name__ seems to work in pkg_resources.resource_filename, it's just the relative "../locale" part which didn't.

in reply to:  5 comment:7 by Christian Boos, 13 years ago

What should also be checked is whether the similar call to resource_filename(__name__, '../locale') in trac/util/translation.py will actually work when Trac is installed as an .egg or not.

Same problem for Trac itself, see #8062.

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos to the specified user.

Add Comment

E-mail address and name can be saved in the Preferences .
Note: See TracTickets for help on using tickets.