From 69a7f450535730ba1f19326f2a340836ffa47d6b Mon Sep 17 00:00:00 2001 From: stealthycoin Date: Mon, 24 Oct 2022 14:42:06 -0700 Subject: [PATCH] Fix metadata tests on windows --- backends/build_system/awscli_venv.py | 10 +++++++--- .../build_system/functional/test_aws_cli_venv.py | 7 ++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/backends/build_system/awscli_venv.py b/backends/build_system/awscli_venv.py index 793a284595a8..1816a8ed0b16 100644 --- a/backends/build_system/awscli_venv.py +++ b/backends/build_system/awscli_venv.py @@ -11,6 +11,7 @@ # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. import os +import json import subprocess import site import sys @@ -133,15 +134,18 @@ def _pip_install(self, args, cwd=None): self._utils.run(args, **run_kwargs) def _site_packages(self) -> str: - site_path = ( + # On windows the getsitepackages can return the root venv dir. + # So instead of just taking the first entry, we need to take the + # first entry that contains the string "site-packages" in the path. + site_path = [path for path in json.loads( subprocess.check_output( [ self.python_exe, "-c", - "import site; print(site.getsitepackages()[0])", + "import site, json; print(json.dumps(site.getsitepackages()))", ] ) .decode() .strip() - ) + ) if "site-packages" in path][0] return site_path diff --git a/tests/backends/build_system/functional/test_aws_cli_venv.py b/tests/backends/build_system/functional/test_aws_cli_venv.py index f12e11e208b1..4d946dd1992e 100644 --- a/tests/backends/build_system/functional/test_aws_cli_venv.py +++ b/tests/backends/build_system/functional/test_aws_cli_venv.py @@ -11,6 +11,7 @@ # ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. import contextlib +import json import re import os import sys @@ -87,17 +88,17 @@ def _python_version(self) -> str: return f"python{info[0]}.{info[1]}" def _site_packages_dir(self, venv_path: pathlib.PurePath) -> str: - site_path = ( + site_path = [path for path in json.loads( subprocess.check_output( [ venv_path / BIN_DIRNAME / PYTHON_EXE_NAME, "-c", - "import site; print(site.getsitepackages()[0])", + "import site, json; print(json.dumps(site.getsitepackages()))", ] ) .decode() .strip() - ) + ) if "site-packages" in path][0] return site_path @skip_if_windows("Posix virtualenv")