From 22169d01cfce2f9af2c6db6fd571a3849e8a3a99 Mon Sep 17 00:00:00 2001 From: Ilia Lazarev Date: Fri, 20 Jan 2023 18:39:44 +0300 Subject: [PATCH 1/2] Specify python binary path with minor version (#3507) --- CHANGES.md | 1 + autoload/black.vim | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1450278341b..45e524935a1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -81,6 +81,7 @@ - Move 3.11 CI to normal flow now all dependencies support 3.11 (#3446) - Docker: Add new `latest_prerelease` tag automation to follow latest black alpha release on docker images (#3465) +- Fixed missing python binary path in autoload script for vim (#3508) ### Documentation diff --git a/autoload/black.vim b/autoload/black.vim index 5aec8725bd0..273fb7c51c5 100644 --- a/autoload/black.vim +++ b/autoload/black.vim @@ -34,7 +34,7 @@ FLAGS = [ ] -def _get_python_binary(exec_prefix): +def _get_python_binary(exec_prefix, pyver): try: default = vim.eval("g:pymode_python").strip() except vim.error: @@ -43,7 +43,7 @@ def _get_python_binary(exec_prefix): return default if sys.platform[:3] == "win": return exec_prefix / 'python.exe' - return exec_prefix / 'bin' / 'python3' + return exec_prefix / 'bin' / f'python{pyver[0]}.{pyver[1]}' def _get_pip(venv_path): if sys.platform[:3] == "win": @@ -82,7 +82,7 @@ def _initialize_black_env(upgrade=False): _executable = sys.executable _base_executable = getattr(sys, "_base_executable", _executable) try: - executable = str(_get_python_binary(Path(sys.exec_prefix))) + executable = str(_get_python_binary(Path(sys.exec_prefix), pyver)) sys.executable = executable sys._base_executable = executable print(f'Creating a virtualenv in {virtualenv_path}...') From 54881f251fd96f6d01035fd376f5fe3222df3c5b Mon Sep 17 00:00:00 2001 From: Ilia Lazarev Date: Sun, 19 Mar 2023 00:34:57 +0300 Subject: [PATCH 2/2] Specify Python exec path with minor version if available (#3507) --- autoload/black.vim | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/autoload/black.vim b/autoload/black.vim index 273fb7c51c5..53144450dc3 100644 --- a/autoload/black.vim +++ b/autoload/black.vim @@ -43,7 +43,15 @@ def _get_python_binary(exec_prefix, pyver): return default if sys.platform[:3] == "win": return exec_prefix / 'python.exe' - return exec_prefix / 'bin' / f'python{pyver[0]}.{pyver[1]}' + bin_path = exec_prefix / "bin" + exec_path = (bin_path / f"python{pyver[0]}.{pyver[1]}").resolve() + if exec_path.exists(): + return exec_path + # It is possible that some environments may only have python3 + exec_path = (bin_path / f"python3").resolve() + if exec_path.exists(): + return exec_path + raise ValueError("python executable not found") def _get_pip(venv_path): if sys.platform[:3] == "win":