From cae7ed15aac12b31c5fa6953cd2b1c6d8fcf2a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Eustace?= Date: Mon, 4 Oct 2021 18:49:32 +0200 Subject: [PATCH] Ignore warnings when executing Python scripts --- poetry/utils/env.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/poetry/utils/env.py b/poetry/utils/env.py index ac249370102..b1cff78c215 100644 --- a/poetry/utils/env.py +++ b/poetry/utils/env.py @@ -1147,6 +1147,9 @@ def run_pip(self, *args, **kwargs): cmd = pip + list(args) return self._run(cmd, **kwargs) + def run_python_script(self, content, **kwargs): # type: (str, Any) -> str + return self.run(self._executable, "-W", "ignore", "-", input_=content, **kwargs) + def _run(self, cmd, **kwargs): """ Run a command inside the Python environment. @@ -1357,18 +1360,16 @@ def __init__(self, path, base=None): # type: (Path, Optional[Path]) -> None # In this case we need to get sys.base_prefix # from inside the virtualenv. if base is None: - self._base = Path( - self.run(self._executable, "-", input_=GET_BASE_PREFIX).strip() - ) + self._base = Path(self.run_python_script(GET_BASE_PREFIX).strip()) @property def sys_path(self): # type: () -> List[str] - output = self.run(self._executable, "-", input_=GET_SYS_PATH) + output = self.run_python_script(GET_SYS_PATH) return json.loads(output) def get_version_info(self): # type: () -> Tuple[int] - output = self.run(self._executable, "-", input_=GET_PYTHON_VERSION) + output = self.run_python_script(GET_PYTHON_VERSION) return tuple([int(s) for s in output.strip().split(".")]) @@ -1406,7 +1407,7 @@ def get_supported_tags(self): # type: () -> List[Tag] """ ) - output = self.run(self._executable, "-", input_=script) + output = self.run_python_script(script) return [Tag(*t) for t in json.loads(output)] @@ -1424,7 +1425,7 @@ def get_pip_version(self): # type: () -> Version return Version.parse(m.group(1)) def get_paths(self): # type: () -> Dict[str, str] - output = self.run(self._executable, "-", input_=GET_PATHS) + output = self.run_python_script(GET_PATHS) return json.loads(output) @@ -1542,7 +1543,7 @@ def find_executables(self): # type: () -> None self._pip_executable = pip_executable def get_paths(self): # type: () -> Dict[str, str] - output = self.run(self._executable, "-", input_=GET_PATHS_FOR_GENERIC_ENVS) + output = self.run_python_script(GET_PATHS_FOR_GENERIC_ENVS) return json.loads(output)