From 706528c971bfda13bb794318837163bf50efffda Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Mon, 20 Jan 2020 13:49:26 +0100 Subject: [PATCH] Ensure --version works with non-ascii paths Fixes #66617 --- .../fragments/66617-version-unicode-fix.yml | 2 ++ lib/ansible/cli/arguments/option_helpers.py | 21 ++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 changelogs/fragments/66617-version-unicode-fix.yml diff --git a/changelogs/fragments/66617-version-unicode-fix.yml b/changelogs/fragments/66617-version-unicode-fix.yml new file mode 100644 index 00000000000000..c61a2117c6a7d2 --- /dev/null +++ b/changelogs/fragments/66617-version-unicode-fix.yml @@ -0,0 +1,2 @@ +bugfixes: + - Ensure that ``--version`` works with non-ascii paths (https://github.com/ansible/ansible/issues/66617) diff --git a/lib/ansible/cli/arguments/option_helpers.py b/lib/ansible/cli/arguments/option_helpers.py index 945a76011b4ca1..20d8fb62bd2939 100644 --- a/lib/ansible/cli/arguments/option_helpers.py +++ b/lib/ansible/cli/arguments/option_helpers.py @@ -15,7 +15,7 @@ import ansible from ansible import constants as C -from ansible.module_utils._text import to_native +from ansible.module_utils._text import to_native, to_text from ansible.release import __version__ from ansible.utils.path import unfrackpath @@ -164,22 +164,23 @@ def _gitinfo(): def version(prog=None): """ return ansible version """ if prog: - result = " ".join((prog, __version__)) + result = u" ".join((prog, __version__)) else: result = __version__ gitinfo = _gitinfo() if gitinfo: - result = result + " {0}".format(gitinfo) - result += "\n config file = %s" % C.CONFIG_FILE + result = result + u" {0}".format(gitinfo) + result += u"\n config file = %s" % to_text(C.CONFIG_FILE) if C.DEFAULT_MODULE_PATH is None: - cpath = "Default w/o overrides" + cpath = u"Default w/o overrides" else: - cpath = C.DEFAULT_MODULE_PATH - result = result + "\n configured module search path = %s" % cpath - result = result + "\n ansible python module location = %s" % ':'.join(ansible.__path__) - result = result + "\n executable location = %s" % sys.argv[0] - result = result + "\n python version = %s" % ''.join(sys.version.splitlines()) + cpath = u", ".join(C.DEFAULT_MODULE_PATH) + python_module_location = u":".join(map(to_text, ansible.__path__)) + result = result + u"\n configured module search path = %s" % cpath + result = result + u"\n ansible python module location = %s" % python_module_location + result = result + u"\n executable location = %s" % to_text(sys.argv[0]) + result = result + u"\n python version = %s" % ''.join(sys.version.splitlines()) return result