Skip to content

Commit

Permalink
Finding cross-provider dependencies fails when encoding wrong (apache…
Browse files Browse the repository at this point in the history
…#9012)

This forces encoding of read python files to utf-8
  • Loading branch information
potiuk authored May 26, 2020
1 parent 3994030 commit 2a88955
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tests/build_provider_packages_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import io
import json
import os
import sys
Expand Down Expand Up @@ -153,8 +154,12 @@ def get_imports_from_file(file_name: str) -> List[str]:
:param file_name: name of the file
:return: list of import names
"""
with open(file_name) as f:
root = parse(f.read(), file_name)
try:
with io.open(file_name, "rt", encoding="utf-8") as f:
root = parse(f.read(), file_name)
except Exception:
print(f"Error when opening file {file_name}", file=sys.stderr)
raise
visitor = ImportFinder(file_name)
visitor.visit(root)
return visitor.imports
Expand Down Expand Up @@ -243,7 +248,7 @@ def insert_documentation(deps_dict: Dict[str, List[str]], res: List[str]):
print(f"Written provider dependencies to the file {provider_dependencies_file_name}")
print()
if documentation_file_name:
with open(documentation_file_name, "r") as documentation_file:
with io.open(documentation_file_name, "r", encoding="utf-8") as documentation_file:
text = documentation_file.readlines()
replacing = False
result: List[str] = []
Expand All @@ -256,7 +261,7 @@ def insert_documentation(deps_dict: Dict[str, List[str]], res: List[str]):
replacing = False
if not replacing:
result.append(line)
with open(documentation_file_name, "w") as documentation_file:
with io.open(documentation_file_name, "w", encoding="utf-8") as documentation_file:
documentation_file.write("".join(result))
print()
print(f"Written package extras to the file {documentation_file_name}")
Expand Down

0 comments on commit 2a88955

Please sign in to comment.