Skip to content

Commit ee79089

Browse files
authored
Merge pull request #4592 from python-poetry/fix/avoid-python-scripts-errors-on-python-3.10
Ignore warnings when executing Python scripts
2 parents 23f005b + cae7ed1 commit ee79089

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

poetry/utils/env.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,9 @@ def run_pip(self, *args, **kwargs):
11471147
cmd = pip + list(args)
11481148
return self._run(cmd, **kwargs)
11491149

1150+
def run_python_script(self, content, **kwargs): # type: (str, Any) -> str
1151+
return self.run(self._executable, "-W", "ignore", "-", input_=content, **kwargs)
1152+
11501153
def _run(self, cmd, **kwargs):
11511154
"""
11521155
Run a command inside the Python environment.
@@ -1357,18 +1360,16 @@ def __init__(self, path, base=None): # type: (Path, Optional[Path]) -> None
13571360
# In this case we need to get sys.base_prefix
13581361
# from inside the virtualenv.
13591362
if base is None:
1360-
self._base = Path(
1361-
self.run(self._executable, "-", input_=GET_BASE_PREFIX).strip()
1362-
)
1363+
self._base = Path(self.run_python_script(GET_BASE_PREFIX).strip())
13631364

13641365
@property
13651366
def sys_path(self): # type: () -> List[str]
1366-
output = self.run(self._executable, "-", input_=GET_SYS_PATH)
1367+
output = self.run_python_script(GET_SYS_PATH)
13671368

13681369
return json.loads(output)
13691370

13701371
def get_version_info(self): # type: () -> Tuple[int]
1371-
output = self.run(self._executable, "-", input_=GET_PYTHON_VERSION)
1372+
output = self.run_python_script(GET_PYTHON_VERSION)
13721373

13731374
return tuple([int(s) for s in output.strip().split(".")])
13741375

@@ -1406,7 +1407,7 @@ def get_supported_tags(self): # type: () -> List[Tag]
14061407
"""
14071408
)
14081409

1409-
output = self.run(self._executable, "-", input_=script)
1410+
output = self.run_python_script(script)
14101411

14111412
return [Tag(*t) for t in json.loads(output)]
14121413

@@ -1424,7 +1425,7 @@ def get_pip_version(self): # type: () -> Version
14241425
return Version.parse(m.group(1))
14251426

14261427
def get_paths(self): # type: () -> Dict[str, str]
1427-
output = self.run(self._executable, "-", input_=GET_PATHS)
1428+
output = self.run_python_script(GET_PATHS)
14281429

14291430
return json.loads(output)
14301431

@@ -1542,7 +1543,7 @@ def find_executables(self): # type: () -> None
15421543
self._pip_executable = pip_executable
15431544

15441545
def get_paths(self): # type: () -> Dict[str, str]
1545-
output = self.run(self._executable, "-", input_=GET_PATHS_FOR_GENERIC_ENVS)
1546+
output = self.run_python_script(GET_PATHS_FOR_GENERIC_ENVS)
15461547

15471548
return json.loads(output)
15481549

0 commit comments

Comments
 (0)