Fix ansible-test module_utils analysis.
This commit is contained in:
parent
40dc851f7e
commit
99e657162f
2 changed files with 7 additions and 2 deletions
2
changelogs/fragments/ansible-test-ast-parse-bytes.yml
Normal file
2
changelogs/fragments/ansible-test-ast-parse-bytes.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- "ansible-test - Fix regression introduced in https://github.com/ansible/ansible/pull/67063 which caused module_utils analysis to fail on Python 2.x."
|
|
@ -8,7 +8,7 @@ import os
|
|||
from . import types as t
|
||||
|
||||
from .io import (
|
||||
read_text_file,
|
||||
read_binary_file,
|
||||
)
|
||||
|
||||
from .util import (
|
||||
|
@ -165,7 +165,10 @@ def extract_python_module_utils_imports(path, module_utils):
|
|||
:type module_utils: set[str]
|
||||
:rtype: set[str]
|
||||
"""
|
||||
code = read_text_file(path)
|
||||
# Python code must be read as bytes to avoid a SyntaxError when the source uses comments to declare the file encoding.
|
||||
# See: https://www.python.org/dev/peps/pep-0263
|
||||
# Specifically: If a Unicode string with a coding declaration is passed to compile(), a SyntaxError will be raised.
|
||||
code = read_binary_file(path)
|
||||
|
||||
try:
|
||||
tree = ast.parse(code)
|
||||
|
|
Loading…
Reference in a new issue