Invoke: Config loading and locale bug

Created on 23 Aug 2016  路  6Comments  路  Source: pyinvoke/invoke

The way config.py checks for existence of config files works only for English speakers. Try the following after installing the relevant locale:

import locale
from invoke import task

locale.setlocale(locale.LC_ALL, 'fr_FR.utf8')

@task
def test(ctx):
    pass

Then inv test crashes with FileNotFoundError: [Errno 2] Aucun fichier ou dossier de ce type: '/etc/invoke.yaml' and its French error message.

Bug

All 6 comments

I think you have used an invalid locale name.
Please try to use locale name:

locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')

To view a list of valid locales:

$ locale -a | grep fr
fr_BE
fr_BE.ISO8859-1
fr_BE.ISO8859-15
fr_BE.UTF-8
fr_CA
fr_CA.ISO8859-1
fr_CA.ISO8859-15
fr_CA.UTF-8
fr_CH
fr_CH.ISO8859-1
fr_CH.ISO8859-15
fr_CH.UTF-8
fr_FR
fr_FR.ISO8859-1
fr_FR.ISO8859-15
fr_FR.UTF-8

Thank you for your comment. I think I would have noticed if setting locale this way didn't work in all my python programs. Let's see:

$ locale -a | grep fr
fr_BE.utf8
fr_CA.utf8
fr_CH.utf8
fr_FR.utf8
fr_LU.utf8

Interesting but irrelevant to invoke I'm afraid.

@PatrickMassot did you try any other locale such as "en_US.utf8"?

Please include the full trace message before the "FileNotFoundError" you have encountered.

Full trace is

Traceback (most recent call last):
  File "/usr/local/bin/inv", line 11, in <module>
    sys.exit(program.run())
  File "/usr/local/lib/python3.5/dist-packages/invoke/program.py", line 270, in run
    self.execute()
  File "/usr/local/lib/python3.5/dist-packages/invoke/program.py", line 380, in execute
    executor = self.executor_class(self.collection, self.config, self.core)
  File "/usr/local/lib/python3.5/dist-packages/invoke/program.py", line 246, in config
    env_prefix=self.env_prefix,
  File "/usr/local/lib/python3.5/dist-packages/invoke/config.py", line 360, in __init__
    self.load_files()
  File "/usr/local/lib/python3.5/dist-packages/invoke/config.py", line 448, in load_files
    self._load_file(prefix='system')
  File "/usr/local/lib/python3.5/dist-packages/invoke/config.py", line 492, in _load_file
    setattr(self, data, loader(filepath))
  File "/usr/local/lib/python3.5/dist-packages/invoke/config.py", line 563, in _load_yaml
    with open(path) as fd:
FileNotFoundError: [Errno 2] Aucun fichier ou dossier de ce type: '/etc/invoke.yaml'

I realize it was maybe unclear but the link in my first message points to the line that obviously causes this bug: if "No such file" in e.strerror:. It's a rather obviously american way of handling exceptions ;-)

I don't have an easy way to test this on my end, but @cybiere mentioned to me in an email about #653 that errno testing should be cross-platform compatible re: Unix, macOS, Windows. Fears about that angle are, IIRC, why the original implementation had to settle for string comparison - that's never something we _like_ doing. Je suis d茅sol茅.

653 is getting merged now (will be out in Invoke 1.3, today) and hopefully it will improve this without breaking any English speakers' systems in turn!

That's in master now. 馃帀

Was this page helpful?
0 / 5 - 0 ratings