Fix ansible-test module_utils analysis.

pull/67902/head
Matt Clay 6 years ago
parent 40dc851f7e
commit 99e657162f

@ -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 . import types as t
from .io import ( from .io import (
read_text_file, read_binary_file,
) )
from .util import ( from .util import (
@ -165,7 +165,10 @@ def extract_python_module_utils_imports(path, module_utils):
:type module_utils: set[str] :type module_utils: set[str]
:rtype: 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: try:
tree = ast.parse(code) tree = ast.parse(code)

Loading…
Cancel
Save