Skip to content

Commit

Permalink
generate fish and bash activators on Windows (#1528)
Browse files Browse the repository at this point in the history
Signed-off-by: Bernat Gabor <[email protected]>
  • Loading branch information
gaborbernat authored Jan 31, 2020
1 parent 5f802b0 commit 46c64b2
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 11 deletions.
2 changes: 2 additions & 0 deletions docs/changelog/1527.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Generate ``bash`` and ``fish`` activators on Windows too (as these can be available with git bash, cygwin or mysys2)
- by ``gaborbernat``.
4 changes: 0 additions & 4 deletions src/virtualenv/activation/bash/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@


class BashActivator(ViaTemplateActivator):
@classmethod
def supports(cls, interpreter):
return interpreter.os != "nt"

def templates(self):
yield Path("activate.sh")

Expand Down
4 changes: 0 additions & 4 deletions src/virtualenv/activation/fish/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,3 @@
class FishActivator(ViaTemplateActivator):
def templates(self):
yield Path("activate.fish")

@classmethod
def supports(cls, interpreter):
return interpreter.os != "nt"
4 changes: 4 additions & 0 deletions src/virtualenv/util/subprocess/_win_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import ctypes
import os
import platform
import subprocess
from ctypes import Structure, WinError, byref, c_char_p, c_void_p, c_wchar, c_wchar_p, sizeof, windll
from ctypes.wintypes import BOOL, BYTE, DWORD, HANDLE, LPVOID, LPWSTR, WORD
Expand Down Expand Up @@ -133,7 +134,10 @@ def _execute_child(self, args, executable, preexec_fn, close_fds,
if startupinfo is None:
startupinfo = subprocess.STARTUPINFO()
if not isinstance(args, subprocess.types.StringTypes):
args = [i if isinstance(i, bytes) else i.encode('utf-8') for i in args]
args = subprocess.list2cmdline(args)
if platform.python_implementation() == "CPython":
args = args.decode('utf-8')
startupinfo.dwFlags |= _subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = _subprocess.SW_HIDE
comspec = os.environ.get("COMSPEC", unicode("cmd.exe"))
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/activation/test_activation_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
from virtualenv.discovery.py_info import PythonInfo


@pytest.mark.parametrize("activator_class", [BatchActivator, PowerShellActivator, PythonActivator])
@pytest.mark.parametrize(
"activator_class", [BatchActivator, PowerShellActivator, PythonActivator, BashActivator, FishActivator]
)
def test_activator_support_windows(mocker, activator_class):
activator = activator_class(Namespace(prompt=None))

Expand All @@ -24,7 +26,7 @@ def test_activator_support_windows(mocker, activator_class):
assert activator.supports(interpreter)


@pytest.mark.parametrize("activator_class", [BashActivator, CShellActivator, FishActivator])
@pytest.mark.parametrize("activator_class", [CShellActivator])
def test_activator_no_support_windows(mocker, activator_class):
activator = activator_class(Namespace(prompt=None))

Expand Down
4 changes: 4 additions & 0 deletions tests/unit/activation/test_fish.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from __future__ import absolute_import, unicode_literals

import pytest

from virtualenv.activation import FishActivator
from virtualenv.info import IS_WIN


@pytest.mark.skipif(IS_WIN, reason="we have not setup fish in CI yet")
def test_fish(activation_tester_class, activation_tester):
class Fish(activation_tester_class):
def __init__(self, session):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/discovery/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ def test_discovery_via_path(monkeypatch, case, special_name_dir, caplog):


def test_discovery_via_path_not_found(tmp_path, monkeypatch):
monkeypatch.setenv("PATH", str(tmp_path))
monkeypatch.setenv(str("PATH"), str(tmp_path))
interpreter = get_interpreter(uuid4().hex)
assert interpreter is None

0 comments on commit 46c64b2

Please sign in to comment.