Fix quoting issue in virtualenv activator (#5700)

* add test case for directory with spaces

* Stop XonshActivator from quoting strings

* add news

* Update fix-virtualenv-quoting.rst

---------

Co-authored-by: Andy Kipp <anki-code@users.noreply.github.com>
This commit is contained in:
Peter Ye 2024-10-03 08:49:05 -04:00 committed by GitHub
parent 31170c2daf
commit 4fc7d59c95
Failed to generate hash of commit
3 changed files with 41 additions and 4 deletions

View file

@ -0,0 +1,23 @@
**Added:**
* <news item>
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* Fixed incorrect quoting behaviour in `activate.xsh` for virtualenv version 20.26.6.
**Security:**
* <news item>

View file

@ -2,12 +2,15 @@ import sys
from pathlib import Path
from subprocess import check_output
import pytest
from xonsh.pytest.tools import ON_WINDOWS
def test_xonsh_activator(tmp_path):
@pytest.mark.parametrize("dir_name", ["venv", "venv with space"])
def test_xonsh_activator(tmp_path, dir_name):
# Create virtualenv
venv_dir = tmp_path / "venv"
venv_dir = tmp_path / dir_name
assert b"XonshActivator" in check_output(
[sys.executable, "-m", "virtualenv", str(venv_dir)]
)
@ -35,7 +38,13 @@ def test_xonsh_activator(tmp_path):
# Activate
venv_python = check_output(
[sys.executable, "-m", "xonsh", "-c", f"source {activate_path}; which python"]
[
sys.executable,
"-m",
"xonsh",
"-c",
f"source r'{activate_path}'; which python",
]
).decode()
assert Path(venv_python).parent == bin_path
@ -46,7 +55,7 @@ def test_xonsh_activator(tmp_path):
"-m",
"xonsh",
"-c",
f"source {activate_path}; deactivate; "
f"source r'{activate_path}'; deactivate; "
"import shutil; shutil.which('python') or shutil.which('python3')",
]
).decode()

View file

@ -5,6 +5,11 @@ class XonshActivator(ViaTemplateActivator):
def templates(self):
yield "activate.xsh"
@staticmethod
def quote(string):
# leave string unchanged since we do quoting in activate.xsh (see #5699)
return string
@classmethod
def supports(cls, interpreter):
return interpreter.version_info >= (3, 5)