Skip to content

Commit

Permalink
Merge pull request #4592 from python-poetry/fix/avoid-python-scripts-…
Browse files Browse the repository at this point in the history
…errors-on-python-3.10

Ignore warnings when executing Python scripts
  • Loading branch information
sdispater committed Oct 4, 2021
2 parents 23f005b + cae7ed1 commit ee79089
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(".")])

Expand Down Expand Up @@ -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)]

Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit ee79089

Please sign in to comment.