Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import os
import platform
import plistlib
import re
import shutil
import subprocess
Expand Down Expand Up @@ -1002,7 +1003,19 @@ def build_venv(

args.append(str(path))

return virtualenv.cli_run(args)
cli_result = virtualenv.cli_run(args)

# Exclude the venv folder from from macOS Time Machine backups
if sys.platform == "darwin":
import xattr

xattr.setxattr(
str(path),
"com.apple.metadata:com_apple_backup_excludeItem",
plistlib.dumps("com.apple.backupd", fmt=plistlib.FMT_BINARY),
)

return cli_result

@classmethod
def remove_venv(cls, path: Union[Path, str]) -> None:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ keyring = ">=21.2.0"
entrypoints = "^0.3"
importlib-metadata = {version = "^1.6.0", python = "<3.8"}
dataclasses = {version = "^0.8", python = "~3.6"}
xattr = {version = "^0.9.7", markers = "sys_platform == 'darwin'"}

[tool.poetry.dev-dependencies]
pytest = "^6.2"
Expand Down
15 changes: 15 additions & 0 deletions tests/utils/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import pytest
import tomlkit
import xattr

from cleo.io.null_io import NullIO

Expand Down Expand Up @@ -77,6 +78,20 @@ def test_virtualenvs_with_spaces_in_their_path_work_as_expected(tmp_dir, manager
assert venv.run("python", "-V", shell=True).startswith("Python")


@pytest.mark.skipif(sys.platform != "darwin", reason="requires darwin")
def test_venv_backup_exclusion(tmp_dir, manager):
venv_path = Path(tmp_dir) / "Virtual Env"

manager.build_venv(str(venv_path))

assert (
xattr.getxattr(
str(venv_path), "com.apple.metadata:com_apple_backup_excludeItem"
)
== b"bplist00_\x10\x11com.apple.backupd\x08\x00\x00\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1c"
)


def test_env_commands_with_spaces_in_their_arg_work_as_expected(tmp_dir, manager):
venv_path = Path(tmp_dir) / "Virtual Env"
manager.build_venv(str(venv_path))
Expand Down