Skip to content

Bash version detection fails with certain locales #1940

@janLo

Description

@janLo

I have a machine where the system locale is set to de_DE.UTF-8. The output of bash --version here is:

GNU bash, Version 5.1.4(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
Lizenz GPLv3+: GNU GPL Version 3 oder jünger <http://gnu.org/licenses/gpl.html>

Dies ist freie Software. Sie darf verändert und verteilt werden.
Es wird keine Garantie gewährt, soweit das Gesetz es zulässt.

This causes clicks shell completion activation to die with an exception because of the capitalized V in Version:

Traceback (most recent call last):
  File "/home/losinski/.local/bin/template-test", line 8, in <module>
    sys.exit(main())
  File "/home/losinski/.local/lib/python3.9/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/home/losinski/.local/lib/python3.9/site-packages/click/core.py", line 1057, in main
    self._main_shell_completion(extra, prog_name, complete_var)
  File "/home/losinski/.local/lib/python3.9/site-packages/click/core.py", line 1132, in _main_shell_completion
    rv = shell_complete(self, ctx_args, prog_name, complete_var, instruction)
  File "/home/losinski/.local/lib/python3.9/site-packages/click/shell_completion.py", line 45, in shell_complete
    echo(comp.source())
  File "/home/losinski/.local/lib/python3.9/site-packages/click/shell_completion.py", line 324, in source
    self._check_version()
  File "/home/losinski/.local/lib/python3.9/site-packages/click/shell_completion.py", line 319, in _check_version
    raise RuntimeError(
RuntimeError: Couldn't detect Bash version, shell completion is not supported.

A quickfix would be to set LANG=C as environment on the bash --version call here: https://github.com/pallets/click/blob/main/src/click/shell_completion.py#L305. Another option would be

bash -c 'echo ${BASH_VERSION}'
5.1.4(1)-release

Environment:

  • Python version: 3.9.2
  • Click version: 8.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions