Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore warnings when executing Python scripts #4592

Merged
merged 1 commit into from
Oct 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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