Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude .venv from Time Machine backups #4599

Merged
merged 16 commits into from
Jun 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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.

16 changes: 15 additions & 1 deletion poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import packaging.tags
import tomlkit
import virtualenv
import xattr

from cleo.io.io import IO
from packaging.tags import Tag
Expand Down Expand Up @@ -1002,7 +1003,20 @@ def build_venv(

args.append(str(path))

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

print("path", str(path))
probablykasper marked this conversation as resolved.
Show resolved Hide resolved
print("args", args)

# Exclude the venv folder from from macOS Time Machine backups
if sys.platform == "darwin":
probablykasper marked this conversation as resolved.
Show resolved Hide resolved
xattr.setxattr(
str(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",
probablykasper marked this conversation as resolved.
Show resolved Hide resolved
)

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 = "^0.9.7"

[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")


def test_venv_backup_exclusion(tmp_dir, manager):
probablykasper marked this conversation as resolved.
Show resolved Hide resolved
venv_path = Path(tmp_dir) / "Virtual Env"

manager.build_venv(str(venv_path))

if sys.platform == "darwin":
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