diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 49052b49d46..358e2bfb68a 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -36,10 +36,12 @@ from poetry.core.utils.helpers import temporary_directory from virtualenv.seed.wheels.embed import get_embed_wheel +from poetry.utils._compat import WINDOWS from poetry.utils._compat import decode from poetry.utils._compat import encode from poetry.utils._compat import list_to_shell_command from poetry.utils._compat import metadata +from poetry.utils.helpers import get_real_windows_path from poetry.utils.helpers import is_dir_writable from poetry.utils.helpers import paths_csv from poetry.utils.helpers import remove_directory @@ -961,7 +963,10 @@ def create_venv( return self.get_system_env() - io.write_line(f"Creating virtualenv {name} in {venv_path!s}") + io.write_line( + f"Creating virtualenv {name} in" + f" {venv_path if not WINDOWS else get_real_windows_path(venv_path)!s}" + ) else: create_venv = False if force: @@ -1013,6 +1018,10 @@ def build_venv( with_setuptools: bool | None = None, prompt: str | None = None, ) -> virtualenv.run.session.Session: + if WINDOWS: + path = get_real_windows_path(Path(path)) + executable = get_real_windows_path(Path(executable)) if executable else None + flags = flags or {} flags["no-pip"] = ( @@ -1154,6 +1163,10 @@ def __init__(self, path: Path, base: Path | None = None) -> None: self._is_mingw = sysconfig.get_platform().startswith("mingw") self._is_conda = bool(os.environ.get("CONDA_DEFAULT_ENV")) + if self._is_windows: + path = get_real_windows_path(path) + base = get_real_windows_path(base) if base else None + if not self._is_windows or self._is_mingw: bin_dir = "bin" else: diff --git a/src/poetry/utils/helpers.py b/src/poetry/utils/helpers.py index 298cd56cf6c..04729f4cb89 100644 --- a/src/poetry/utils/helpers.py +++ b/src/poetry/utils/helpers.py @@ -240,3 +240,20 @@ def get_win_folder(csidl_name: str) -> Path: _get_win_folder = _get_win_folder_from_registry return Path(_get_win_folder(csidl_name)) + + +def get_real_windows_path(path: Path) -> Path: + program_files = get_win_folder("CSIDL_PROGRAM_FILES") + local_appdata = get_win_folder("CSIDL_LOCAL_APPDATA") + + path = Path( + str(path).replace( + str(program_files / "WindowsApps"), + str(local_appdata / "Microsoft/WindowsApps"), + ) + ) + + if path.as_posix().startswith(local_appdata.as_posix()): + path = path.resolve() + + return path