ejwa / gitinspector

:bar_chart: The statistical analysis tool for git repositories
GNU General Public License v3.0
2.36k stars 327 forks source link

Locale related failures on OS X #109

Closed hjorthjort closed 8 years ago

hjorthjort commented 8 years ago

There is a known bug in Python which causes gitinspector to break on many OS X systems. The call locale.getlocale() raises an error of the user has not explicitly set certain environment variables.

This is a known, but unresolved bug in Python.

Example problem

For example, I have the following lines in my .zshrc-file:

# gitinspector fix: provide locale
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

These environment variables are unset by default. But if I set these two environment variables to, everything works nicely.

If I reset them with unset LC_ALL and so forth, I get the following stack trace when running gitinspector:

Traceback (most recent call last):
  File "/usr/local/bin/gitinspector.py", line 25, in <module>
    localization.init()
  File "/usr/local/Cellar/gitinspector/0.4.4/libexec/gitinspector/localization.py", line 54, in init
    lang = locale.getlocale()
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 562, in getlocale
    return _parse_localename(localename)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 475, in _parse_localename
    raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8

As you can see, the call fails internally in Python, and the checks imposed in the file are to no help. Pasted below is the offending line in localization.py in this repo, and some context. As you can see, the checks following it are of no help.

lang = locale.getlocale()

#Fix for non-POSIX-compliant systems (Windows et al.).
if os.getenv('LANG') is None:
    lang = locale.getdefaultlocale()
    ...

Note that the problem is the same for the call locale.getdefaultlocale(). It fails in the same way.

Proposed solution

You could hack around it. There is some interesting approaches in this Stack Overflow thread. Perhaps you could just catch the exception. Or you could include explicit instructions to OS X users to set these environment variables, without which gitinspector fails. Right now, OS X users are left to figure this tricky one out on their own.

adam-waldenberg commented 8 years ago

Hi.

Yes. Known problem. I do not really consider this to be an issue in either Python or gitinspector. It's a misconfiguration in OS X.

Most of the hacks discussed on SO are not really proper solutions. I do not want it to fail silently either. The best solution I can think of is to perhaps spew out the warning about not being able to detect the the locale. This is already in there, but it's not catching that particular exception.

In any case, this has already been discussed in several reports in the issue tracker of gitinspector, most recently in issue #93.

As stated in that issue, I'll look at some "solution" to this when I have time.