Skip to content

Commit

Permalink
refactor(vox): expand VIRTUALENV_HOME '~'
Browse files Browse the repository at this point in the history
  • Loading branch information
vgerak authored and jnoortheen committed Feb 3, 2023
1 parent 6cf7865 commit a36b51b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
23 changes: 23 additions & 0 deletions news/4608.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* #4608 Expand `'~'` in $VIRTUALENV_HOME when used by vox

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
26 changes: 26 additions & 0 deletions tests/test_vox.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import types
from typing import TYPE_CHECKING
from unittest.mock import ANY, MagicMock

import pytest
from py.path import local
Expand Down Expand Up @@ -170,6 +171,31 @@ def test_vox_flow(xession, vox, record_events, venv_home):
assert record_events.last == ("vox_on_delete", "spam")


@pytest.mark.parametrize(
"env_venv_home",
[
pathlib.Path("~", ".custom_home_dir/"),
pathlib.Path("~root", "venv"),
pathlib.Path(".rel_venv"),
pathlib.Path("/tmp", "abs_venv"),
None,
],
)
def test_venvdir_expand(xession, env_venv_home):
venv_name = "test_xonsh_venv"

if env_venv_home:
xession.env["VIRTUALENV_HOME"] = str(env_venv_home)
expected_dir = str((env_venv_home / venv_name).expanduser())
else:
expected_dir = str(pathlib.Path("~", ".virtualenvs", venv_name).expanduser())
vox = Vox()
vox._create = MagicMock()
vox.create(venv_name)

vox._create.assert_called_with(expected_dir, ANY, False, False, True, prompt=None)


def test_activate_non_vox_venv(xession, vox, record_events, venv_proc, venv_home):
"""
Create a virtual environment using Python's built-in venv module
Expand Down
3 changes: 2 additions & 1 deletion xontrib/voxapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# FIXME: Is there a better way?
from xonsh.events import events
from xonsh.platform import ON_POSIX, ON_WINDOWS
from xonsh.tools import expand_path

events.doc(
"vox_on_create",
Expand Down Expand Up @@ -128,7 +129,7 @@ def __init__(self, force_removals=False):
self.venvdir = os.path.join(home_path, ".virtualenvs")
XSH.env["VIRTUALENV_HOME"] = self.venvdir
else:
self.venvdir = XSH.env["VIRTUALENV_HOME"]
self.venvdir = expand_path(XSH.env["VIRTUALENV_HOME"])
self.force_removals = force_removals
self.sub_dirs = _subdir_names()

Expand Down

0 comments on commit a36b51b

Please sign in to comment.