From a1f54bd2d0cb170cc6e20cabf8edec697b3c9cc0 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Tue, 22 Jun 2021 22:19:21 +0200 Subject: [PATCH] Update antsibull/docs_parsing/ansible_doc.py Co-authored-by: Toshio Kuratomi --- antsibull/docs_parsing/ansible_doc.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/antsibull/docs_parsing/ansible_doc.py b/antsibull/docs_parsing/ansible_doc.py index 0e9b191cc..eeabfc798 100644 --- a/antsibull/docs_parsing/ansible_doc.py +++ b/antsibull/docs_parsing/ansible_doc.py @@ -208,19 +208,10 @@ def get_collection_metadata(venv: t.Union['VenvRunner', 'FakeVenvRunner'], def get_ansible_core_version(venv: t.Union['VenvRunner', 'FakeVenvRunner'], env: t.Dict[str, str], ) -> PypiVer: - venv_ansible = venv.get_command('ansible') - ansible_version_cmd = venv_ansible('--version', _env=env) - output = ansible_version_cmd.stdout.decode('utf-8', errors='surrogateescape') - first_line = output.splitlines()[0] - # `ansible 2.10.0` - m = re.match(r'^ansible ([^[ ]+)', first_line) - if m: - return PypiVer(m.group(1)) - # `ansible [core 2.12.0.dev0] (devel cd8e3a2208) last updated 2021/05/19 08:35:55 (GMT +200)` - m = re.match(r'^ansible \[[^]]+ ([^]]+)\]', first_line) - if m: - return PypiVer(m.group(1)) - raise ParsingError(f'Cannot interpret first line of ansible --version output: "{first_line}"') + venv_python = venv.get_command('python') + ansible_version_cmd = venv_python('-c', 'import ansible.release; print(ansible.release.__version__)', _env=env) + output = ansible_version_cmd.stdout.decode('utf-8', errors='surrogateescape').strip() + return PypiVer(output) async def get_ansible_plugin_info(venv: t.Union['VenvRunner', 'FakeVenvRunner'],