Skip to content

Commit

Permalink
Merge branch 'main' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat authored Nov 26, 2024
2 parents 9927f59 + be19526 commit 14e9288
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
with:
fetch-depth: 0
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v3
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "pyproject.toml"
Expand Down Expand Up @@ -132,7 +132,7 @@ jobs:
with:
fetch-depth: 0
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v3
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "pyproject.toml"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
with:
fetch-depth: 0
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v3
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "pyproject.toml"
Expand Down
1 change: 1 addition & 0 deletions docs/changelog/2801.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
no longer forcibly echo off during windows batch activation
1 change: 1 addition & 0 deletions docs/changelog/2803.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
write CACHEDIR.TAG file on creation - by "user:`neilramsay`
4 changes: 4 additions & 0 deletions docs/changelog/2804.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Upgrade embedded wheels:

* setuptools to ``75.6.0`` from ``75.5.0``
* wheel to ``0.45.1`` from ``0.45.0``
6 changes: 2 additions & 4 deletions src/virtualenv/activation/batch/activate.bat
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
@REM This file is UTF-8 encoded, so we need to update the current code page while executing it
@echo off
@for /f "tokens=2 delims=:." %%a in ('"%SystemRoot%\System32\chcp.com"') do (
@set _OLD_CODEPAGE=%%a
)
@for /f "tokens=2 delims=:." %%a in ('"%SystemRoot%\System32\chcp.com"') do @set _OLD_CODEPAGE=%%a

@if defined _OLD_CODEPAGE (
"%SystemRoot%\System32\chcp.com" 65001 > nul
)
Expand Down
22 changes: 22 additions & 0 deletions src/virtualenv/create/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import os
import sys
import textwrap
from abc import ABC, abstractmethod
from argparse import ArgumentTypeError
from ast import literal_eval
Expand Down Expand Up @@ -156,10 +157,31 @@ def run(self):
logging.debug("delete %s", self.dest)
safe_delete(self.dest)
self.create()
self.add_cachedir_tag()
self.set_pyenv_cfg()
if not self.no_vcs_ignore:
self.setup_ignore_vcs()

def add_cachedir_tag(self):
"""
Add a Cache Directory Tag file "CACHEDIR.TAG".
The CACHEDIR.TAG file is used by various tools to mark
a directory as cache, so that it can be handled differently.
Some backup tools look for this file to exclude the directory.
See https://bford.info/cachedir/ for more details.
"""
cachedir_tag_file = self.dest / "CACHEDIR.TAG"
if not cachedir_tag_file.exists():
cachedir_tag_text = textwrap.dedent("""
Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by Python virtualenv.
# For information about cache directory tags, see:
# http://www.brynosaurus.com/cachedir/
""").strip()
cachedir_tag_file.write_text(cachedir_tag_text, encoding="utf-8")

def set_pyenv_cfg(self):
self.pyenv_cfg.content = OrderedDict()
self.pyenv_cfg["home"] = os.path.dirname(os.path.abspath(self.interpreter.system_executable))
Expand Down
26 changes: 13 additions & 13 deletions src/virtualenv/seed/wheels/embed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,37 @@
"3.8": {
"pip": "pip-24.3.1-py3-none-any.whl",
"setuptools": "setuptools-75.3.0-py3-none-any.whl",
"wheel": "wheel-0.45.0-py3-none-any.whl",
"wheel": "wheel-0.45.1-py3-none-any.whl",
},
"3.9": {
"pip": "pip-24.3.1-py3-none-any.whl",
"setuptools": "setuptools-75.5.0-py3-none-any.whl",
"wheel": "wheel-0.45.0-py3-none-any.whl",
"setuptools": "setuptools-75.6.0-py3-none-any.whl",
"wheel": "wheel-0.45.1-py3-none-any.whl",
},
"3.10": {
"pip": "pip-24.3.1-py3-none-any.whl",
"setuptools": "setuptools-75.5.0-py3-none-any.whl",
"wheel": "wheel-0.45.0-py3-none-any.whl",
"setuptools": "setuptools-75.6.0-py3-none-any.whl",
"wheel": "wheel-0.45.1-py3-none-any.whl",
},
"3.11": {
"pip": "pip-24.3.1-py3-none-any.whl",
"setuptools": "setuptools-75.5.0-py3-none-any.whl",
"wheel": "wheel-0.45.0-py3-none-any.whl",
"setuptools": "setuptools-75.6.0-py3-none-any.whl",
"wheel": "wheel-0.45.1-py3-none-any.whl",
},
"3.12": {
"pip": "pip-24.3.1-py3-none-any.whl",
"setuptools": "setuptools-75.5.0-py3-none-any.whl",
"wheel": "wheel-0.45.0-py3-none-any.whl",
"setuptools": "setuptools-75.6.0-py3-none-any.whl",
"wheel": "wheel-0.45.1-py3-none-any.whl",
},
"3.13": {
"pip": "pip-24.3.1-py3-none-any.whl",
"setuptools": "setuptools-75.5.0-py3-none-any.whl",
"wheel": "wheel-0.45.0-py3-none-any.whl",
"setuptools": "setuptools-75.6.0-py3-none-any.whl",
"wheel": "wheel-0.45.1-py3-none-any.whl",
},
"3.14": {
"pip": "pip-24.3.1-py3-none-any.whl",
"setuptools": "setuptools-75.5.0-py3-none-any.whl",
"wheel": "wheel-0.45.0-py3-none-any.whl",
"setuptools": "setuptools-75.6.0-py3-none-any.whl",
"wheel": "wheel-0.45.1-py3-none-any.whl",
},
}
MAX = "3.8"
Expand Down
Binary file not shown.
Binary file not shown.
37 changes: 37 additions & 0 deletions tests/integration/test_cachedir_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from __future__ import annotations

import shutil
import subprocess
import sys

import pytest

from virtualenv import cli_run


@pytest.fixture(scope="session")
def tar_test_env(tmp_path_factory):
base_path = tmp_path_factory.mktemp("tar-cachedir-test")
cli_run(["--activators", "", "--without-pip", str(base_path / ".venv")])
yield base_path
shutil.rmtree(str(base_path))


def compatible_is_tar_present() -> bool:
try:
tar_result = subprocess.run(args=["tar", "--help"], capture_output=True, encoding="utf-8")
return tar_result.stdout.find("--exclude-caches") > -1
except FileNotFoundError:
return False


@pytest.mark.skipif(sys.platform == "win32", reason="Windows does not have tar")
@pytest.mark.skipif(not compatible_is_tar_present(), reason="Compatible tar is not installed")
def test_cachedir_tag_ignored_by_tag(tar_test_env): # noqa: ARG001
tar_result = subprocess.run(
args=["tar", "--create", "--file", "/dev/null", "--exclude-caches", "--verbose", ".venv"],
capture_output=True,
encoding="utf-8",
)
assert tar_result.stdout == ".venv/\n.venv/CACHEDIR.TAG\n"
assert tar_result.stderr == "tar: .venv/: contains a cache directory tag CACHEDIR.TAG; contents not dumped\n"
47 changes: 47 additions & 0 deletions tests/unit/activation/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,50 @@ def print_prompt(self):
return 'echo "%PROMPT%"'

activation_tester(Batch)


@pytest.mark.usefixtures("activation_python")
def test_batch_output(activation_tester_class, activation_tester, tmp_path):
version_script = tmp_path / "version.bat"
version_script.write_text("ver", encoding="utf-8")

class Batch(activation_tester_class):
def __init__(self, session) -> None:
super().__init__(BatchActivator, session, None, "activate.bat", "bat")
self._version_cmd = [str(version_script)]
self._invoke_script = []
self.deactivate = "call deactivate"
self.activate_cmd = "call"
self.pydoc_call = f"call {self.pydoc_call}"
self.unix_line_ending = False

def _get_test_lines(self, activate_script):
"""
Build intermediary script which will be then called.
In the script just activate environment, call echo to get current
echo setting, and then deactivate. This ensures that echo setting
is preserved and no unwanted output appears.
"""
intermediary_script_path = str(tmp_path / "intermediary.bat")
activate_script_quoted = self.quote(str(activate_script))
return [
"@echo on",
f"@echo @call {activate_script_quoted} > {intermediary_script_path}",
f"@echo @echo >> {intermediary_script_path}",
f"@echo @deactivate >> {intermediary_script_path}",
f"@call {intermediary_script_path}",
]

def assert_output(self, out, raw, tmp_path): # noqa: ARG002
assert out[0] == "ECHO is on.", raw

def quote(self, s):
if '"' in s or " " in s:
text = s.replace('"', r"\"")
return f'"{text}"'
return s

def print_prompt(self):
return 'echo "%PROMPT%"'

activation_tester(Batch)
29 changes: 29 additions & 0 deletions tests/unit/create/test_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import stat
import subprocess
import sys
import textwrap
import zipfile
from collections import OrderedDict
from itertools import product
Expand Down Expand Up @@ -223,6 +224,34 @@ def list_to_str(iterable):
assert git_ignore.splitlines() == [comment, "*"]


def test_create_cachedir_tag(tmp_path):
cachedir_tag_file = tmp_path / "CACHEDIR.TAG"
cli_run([str(tmp_path), "--without-pip", "--activators", ""])
assert (
cachedir_tag_file.read_text(encoding="utf-8")
== textwrap.dedent("""
Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by Python virtualenv.
# For information about cache directory tags, see:
# http://www.brynosaurus.com/cachedir/
""").strip()
)


def test_create_cachedir_tag_exists(tmp_path):
cachedir_tag_file = tmp_path / "CACHEDIR.TAG"
cachedir_tag_file.write_text("magic", encoding="utf-8")
cli_run([str(tmp_path), "--without-pip", "--activators", ""])
assert cachedir_tag_file.read_text(encoding="utf-8") == "magic"


def test_create_cachedir_tag_exists_override(tmp_path):
cachedir_tag_file = tmp_path / "CACHEDIR.TAG"
cachedir_tag_file.write_text("magic", encoding="utf-8")
cli_run([str(tmp_path), "--without-pip", "--activators", ""])
assert cachedir_tag_file.read_text(encoding="utf-8") == "magic"


def test_create_vcs_ignore_exists(tmp_path):
git_ignore = tmp_path / ".gitignore"
git_ignore.write_text("magic", encoding="utf-8")
Expand Down

0 comments on commit 14e9288

Please sign in to comment.