Skip to content

Commit

Permalink
fix: fix venv paths redirected by Python from MS Store
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer committed Jul 3, 2022
1 parent 17d8c29 commit 3766a98
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -961,7 +963,10 @@ def create_venv(

return self.get_system_env()

io.write_line(f"Creating virtualenv <c1>{name}</> in {venv_path!s}")
io.write_line(
f"Creating virtualenv <c1>{name}</> in"
f" {venv_path if not WINDOWS else get_real_windows_path(venv_path)!s}"
)
else:
create_venv = False
if force:
Expand Down Expand Up @@ -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"] = (
Expand Down Expand Up @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions src/poetry/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: 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

0 comments on commit 3766a98

Please sign in to comment.