diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 589e80052db..d9270cf276d 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 @@ -960,7 +962,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: @@ -1012,6 +1017,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) + executable = get_real_windows_path(executable) if executable else None + flags = flags or {} flags["no-pip"] = ( @@ -1153,6 +1162,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 42a7c61610b..ec6009d2dd4 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: return Path(_get_win_folder(csidl_name)) raise RuntimeError("Method can only be called on Windows.") + + +def get_real_windows_path(path: str | 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