Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config loading and locale bug #384

Closed
PatrickMassot opened this issue Aug 23, 2016 · 6 comments

Comments

@PatrickMassot
Copy link

commented Aug 23, 2016

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.

@indera

This comment has been minimized.

Copy link

commented Aug 23, 2016

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
@PatrickMassot

This comment has been minimized.

Copy link
Author

commented Aug 23, 2016

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.

@indera

This comment has been minimized.

Copy link

commented Aug 23, 2016

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

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

@PatrickMassot

This comment has been minimized.

Copy link
Author

commented Aug 23, 2016

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 ;-)

indera added a commit to indera/invoke that referenced this issue Aug 23, 2016

@bitprophet bitprophet added the Bug label Aug 25, 2016

@bitprophet bitprophet added this to the Next bugfix milestone Aug 1, 2019

@bitprophet

This comment has been minimized.

Copy link
Member

commented Aug 6, 2019

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!

@bitprophet

This comment has been minimized.

Copy link
Member

commented Aug 6, 2019

That's in master now. 🎉

@bitprophet bitprophet closed this Aug 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.