mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
Apply abspath() to the env_dir, and add a test to verify.
This commit is contained in:
parent
3e79a958c7
commit
16edba8fe8
2 changed files with 45 additions and 3 deletions
|
@ -1,9 +1,10 @@
|
||||||
"""Vox tests"""
|
"""Vox tests"""
|
||||||
|
|
||||||
import builtins
|
|
||||||
import stat
|
import stat
|
||||||
import os
|
import os
|
||||||
|
import subprocess as sp
|
||||||
import pytest
|
import pytest
|
||||||
|
import sys
|
||||||
from xontrib.voxapi import Vox
|
from xontrib.voxapi import Vox
|
||||||
|
|
||||||
from tools import skip_if_on_conda, skip_if_on_msys
|
from tools import skip_if_on_conda, skip_if_on_msys
|
||||||
|
@ -80,6 +81,47 @@ def test_activate(xonsh_builtins, tmpdir):
|
||||||
assert last_event == ("deactivate", "spam")
|
assert last_event == ("deactivate", "spam")
|
||||||
|
|
||||||
|
|
||||||
|
@skip_if_on_msys
|
||||||
|
@skip_if_on_conda
|
||||||
|
def test_activate_non_vox_venv(xonsh_builtins, tmpdir):
|
||||||
|
"""
|
||||||
|
Create a virtual environment using Python's built-in venv module
|
||||||
|
(not in VIRTUALENV_HOME) and verify that vox can activate it correctly.
|
||||||
|
"""
|
||||||
|
xonsh_builtins.__xonsh__.env.setdefault("PATH", [])
|
||||||
|
|
||||||
|
last_event = None
|
||||||
|
|
||||||
|
@xonsh_builtins.events.vox_on_activate
|
||||||
|
def activate(name, **_):
|
||||||
|
nonlocal last_event
|
||||||
|
last_event = "activate", name
|
||||||
|
|
||||||
|
@xonsh_builtins.events.vox_on_deactivate
|
||||||
|
def deactivate(name, **_):
|
||||||
|
nonlocal last_event
|
||||||
|
last_event = "deactivate", name
|
||||||
|
|
||||||
|
with tmpdir.as_cwd():
|
||||||
|
venv_dirname = 'venv'
|
||||||
|
sp.run([sys.executable, '-m', 'venv', venv_dirname])
|
||||||
|
vox = Vox()
|
||||||
|
vox.activate(venv_dirname)
|
||||||
|
vxv = vox[venv_dirname]
|
||||||
|
|
||||||
|
env = xonsh_builtins.__xonsh__.env
|
||||||
|
assert os.path.isabs(vxv.bin)
|
||||||
|
assert env["PATH"][0] == vxv.bin
|
||||||
|
assert os.path.isabs(vxv.env)
|
||||||
|
assert env["VIRTUAL_ENV"] == vxv.env
|
||||||
|
assert last_event == ("activate", venv_dirname)
|
||||||
|
|
||||||
|
vox.deactivate()
|
||||||
|
assert not env["PATH"]
|
||||||
|
assert "VIRTUAL_ENV" not in env
|
||||||
|
assert last_event == ("deactivate", tmpdir.join(venv_dirname))
|
||||||
|
|
||||||
|
|
||||||
@skip_if_on_msys
|
@skip_if_on_msys
|
||||||
@skip_if_on_conda
|
@skip_if_on_conda
|
||||||
def test_path(xonsh_builtins, tmpdir):
|
def test_path(xonsh_builtins, tmpdir):
|
||||||
|
|
|
@ -88,7 +88,7 @@ def _mkvenv(env_dir):
|
||||||
|
|
||||||
This only cares about the platform. No filesystem calls are made.
|
This only cares about the platform. No filesystem calls are made.
|
||||||
"""
|
"""
|
||||||
env_dir = os.path.normpath(env_dir)
|
env_dir = os.path.abspath(env_dir)
|
||||||
if ON_WINDOWS:
|
if ON_WINDOWS:
|
||||||
binname = os.path.join(env_dir, "Scripts")
|
binname = os.path.join(env_dir, "Scripts")
|
||||||
incpath = os.path.join(env_dir, "Include")
|
incpath = os.path.join(env_dir, "Include")
|
||||||
|
@ -358,7 +358,7 @@ class Vox(collections.abc.Mapping):
|
||||||
self.deactivate()
|
self.deactivate()
|
||||||
|
|
||||||
type(self).oldvars = {"PATH": list(env["PATH"])}
|
type(self).oldvars = {"PATH": list(env["PATH"])}
|
||||||
env["PATH"].insert(0, os.path.abspath(ve.bin))
|
env["PATH"].insert(0, ve.bin)
|
||||||
env["VIRTUAL_ENV"] = ve.env
|
env["VIRTUAL_ENV"] = ve.env
|
||||||
if "PYTHONHOME" in env:
|
if "PYTHONHOME" in env:
|
||||||
type(self).oldvars["PYTHONHOME"] = env.pop("PYTHONHOME")
|
type(self).oldvars["PYTHONHOME"] = env.pop("PYTHONHOME")
|
||||||
|
|
Loading…
Add table
Reference in a new issue