def get_pip_version_for_python_executable(python_executable: str) -> Version: """ Returns pip version for the given python executable. """ str_version = run_python_snippet(python_executable, "import pip;print(pip.__version__)") return Version(str_version)
def get_sys_path_for_python_executable(python_executable: str) -> List[str]: """ Returns sys.path list for the given python executable. """ result = run_python_snippet( python_executable, "import sys;import json;print(json.dumps(sys.path))") paths = json.loads(result) assert isinstance(paths, list) assert all(isinstance(i, str) for i in paths) return [os.path.abspath(path) for path in paths]
def test_run_python_snippet_returns_multilne(): result = run_python_snippet(sys.executable, r'print("MULTILINE\nOUTPUT", end="")') assert result == "MULTILINE\nOUTPUT"