Skip to content

Commit

Permalink
fix(packages): use symlinks when creating virtual environments (#1161)
Browse files Browse the repository at this point in the history
Fixes #1159
  • Loading branch information
dairiki committed Aug 29, 2023
1 parent bfce91a commit 26f5eac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lektor/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ def remove_package_from_project(project, name):
return None


if os.name == "nt":
_default_venv_symlinks = False
else:
_default_venv_symlinks = True


class VirtualEnv:
"""A helper for manipulating our private package cache virtual environment.
Expand All @@ -100,7 +106,12 @@ class VirtualEnv:
def __init__(self, path: StrPath):
self.path = Path(path)

def create(self, with_pip: bool = True, upgrade_deps: bool = True) -> None:
def create(
self,
with_pip: bool = True,
upgrade_deps: bool = True,
symlinks: bool = _default_venv_symlinks,
) -> None:
"""(Re-)Create a new virtual environment.
This will remove any existing virtual environment and create a new one.
Expand All @@ -120,7 +131,11 @@ def create(self, with_pip: bool = True, upgrade_deps: bool = True) -> None:
#
# Note that, e.g., pip>=21.3 is required to support PEP660 editable
# installs.
options: Dict[str, Any] = {"clear": True, "with_pip": with_pip}
options: Dict[str, Any] = {
"clear": True,
"with_pip": with_pip,
"symlinks": symlinks,
}
if sys.version_info >= (3, 9):
EnvBuilder(upgrade_deps=upgrade_deps, **options).create(self.path)
else:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ def test_VirtualEnv_addsitedir(nested_venv: VirtualEnv) -> None:
assert proc.returncode == 0


@pytest.mark.skipif(os.name == "nt", reason="Windows")
def test_VirtualEnv_uses_symlinks(nested_venv: VirtualEnv) -> None:
executable = Path(nested_venv.executable)
assert executable.resolve(strict=True).parent != executable.parent


@pytest.mark.requiresinternet
@pytest.mark.slowtest
def test_VirtualEnv_run_pip_install(tmp_path: Path) -> None:
Expand Down

0 comments on commit 26f5eac

Please sign in to comment.