mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
virtualenv: Add activator plugin
Code from https://github.com/pypa/virtualenv/pull/2040
This commit is contained in:
parent
284f794132
commit
dfa713c6fc
3 changed files with 60 additions and 0 deletions
3
setup.py
3
setup.py
|
@ -324,6 +324,7 @@ def main():
|
|||
"xonsh.pytest",
|
||||
"xonsh.lib",
|
||||
"xonsh.webconfig",
|
||||
"xonsh.virtualenv",
|
||||
"xompletions",
|
||||
],
|
||||
package_dir={
|
||||
|
@ -337,6 +338,7 @@ def main():
|
|||
"xonsh": ["*.json", "*.githash"],
|
||||
"xontrib": ["*.xsh"],
|
||||
"xonsh.lib": ["*.xsh"],
|
||||
"xonsh.virtualenv": ["*.xsh"],
|
||||
"xonsh.webconfig": [
|
||||
"*.html",
|
||||
"js/app.min.js",
|
||||
|
@ -356,6 +358,7 @@ def main():
|
|||
"xonshcon = xonsh.pyghooks:XonshConsoleLexer",
|
||||
],
|
||||
"pytest11": ["xonsh = xonsh.pytest.plugin"],
|
||||
"virtualenv.activate": ["xonsh = xonsh.virtualenv:XonshActivator"],
|
||||
"console_scripts": [
|
||||
"xonsh = xonsh.main:main",
|
||||
"xonsh-cat = xonsh.xoreutils.cat:main",
|
||||
|
|
11
xonsh/virtualenv/__init__.py
Normal file
11
xonsh/virtualenv/__init__.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from virtualenv.util.path import Path
|
||||
from virtualenv.activation.via_template import ViaTemplateActivator
|
||||
|
||||
|
||||
class XonshActivator(ViaTemplateActivator):
|
||||
def templates(self):
|
||||
yield Path("activate.xsh")
|
||||
|
||||
@classmethod
|
||||
def supports(cls, interpreter):
|
||||
return interpreter.version_info >= (3, 5)
|
46
xonsh/virtualenv/activate.xsh
Normal file
46
xonsh/virtualenv/activate.xsh
Normal file
|
@ -0,0 +1,46 @@
|
|||
"""Xonsh activate script for virtualenv"""
|
||||
from xonsh.tools import get_sep as _get_sep
|
||||
|
||||
def _deactivate(args):
|
||||
if "pydoc" in aliases:
|
||||
del aliases["pydoc"]
|
||||
|
||||
if ${...}.get("_OLD_VIRTUAL_PATH", ""):
|
||||
$PATH = $_OLD_VIRTUAL_PATH
|
||||
del $_OLD_VIRTUAL_PATH
|
||||
|
||||
if ${...}.get("_OLD_VIRTUAL_PYTHONHOME", ""):
|
||||
$PYTHONHOME = $_OLD_VIRTUAL_PYTHONHOME
|
||||
del $_OLD_VIRTUAL_PYTHONHOME
|
||||
|
||||
if "VIRTUAL_ENV" in ${...}:
|
||||
del $VIRTUAL_ENV
|
||||
|
||||
if "VIRTUAL_ENV_PROMPT" in ${...}:
|
||||
del $VIRTUAL_ENV_PROMPT
|
||||
|
||||
if "nondestructive" not in args:
|
||||
# Self destruct!
|
||||
del aliases["deactivate"]
|
||||
|
||||
|
||||
# unset irrelevant variables
|
||||
_deactivate(["nondestructive"])
|
||||
aliases["deactivate"] = _deactivate
|
||||
|
||||
$VIRTUAL_ENV = r"__VIRTUAL_ENV__"
|
||||
|
||||
$_OLD_VIRTUAL_PATH = $PATH
|
||||
$PATH = $PATH[:]
|
||||
$PATH.add($VIRTUAL_ENV + _get_sep() + "__BIN_NAME__", front=True, replace=True)
|
||||
|
||||
if ${...}.get("PYTHONHOME", ""):
|
||||
# unset PYTHONHOME if set
|
||||
$_OLD_VIRTUAL_PYTHONHOME = $PYTHONHOME
|
||||
del $PYTHONHOME
|
||||
|
||||
$VIRTUAL_ENV_PROMPT = "__VIRTUAL_PROMPT__"
|
||||
if not $VIRTUAL_ENV_PROMPT:
|
||||
del $VIRTUAL_ENV_PROMPT
|
||||
|
||||
aliases["pydoc"] = ["python", "-m", "pydoc"]
|
Loading…
Add table
Reference in a new issue