1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-02-22 12:58:33 +00:00

#682: Disable instant mode on Python 2

This commit is contained in:
Vladimir Iakovlev 2017-08-26 13:16:10 +02:00
parent 1132015e60
commit 7a57355e7e
4 changed files with 31 additions and 4 deletions

View File

@ -110,12 +110,12 @@ class TestCommand(object):
Popen = Mock() Popen = Mock()
Popen.return_value.stdout.read.return_value = b'stdout' Popen.return_value.stdout.read.return_value = b'stdout'
Popen.return_value.stderr.read.return_value = b'stderr' Popen.return_value.stderr.read.return_value = b'stderr'
monkeypatch.setattr('thefuck.output.rerun.Popen', Popen) monkeypatch.setattr('thefuck.output_readers.rerun.Popen', Popen)
return Popen return Popen
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def prepare(self, monkeypatch): def prepare(self, monkeypatch):
monkeypatch.setattr('thefuck.output.rerun._wait_output', monkeypatch.setattr('thefuck.output_readers.rerun._wait_output',
lambda *_: True) lambda *_: True)
def test_from_script_calls(self, Popen, settings, os_environ): def test_from_script_calls(self, Popen, settings, os_environ):

View File

@ -3,7 +3,16 @@ from . import read_log, rerun
def get_output(script, expanded): def get_output(script, expanded):
"""Get output of the script.
:param script: Console script.
:type script: str
:param expanded: Console script with expanded aliases.
:type expanded: str
:rtype: (str, str)
"""
if settings.instant_mode: if settings.instant_mode:
return read_log.get_output(script, expanded) return read_log.get_output(script)
else: else:
return rerun.get_output(script, expanded) return rerun.get_output(script, expanded)

View File

@ -5,6 +5,7 @@ try:
except ImportError: except ImportError:
from backports.shutil_get_terminal_size import get_terminal_size from backports.shutil_get_terminal_size import get_terminal_size
from warnings import warn from warnings import warn
import six
import pyte import pyte
from ..exceptions import ScriptNotInLog from ..exceptions import ScriptNotInLog
from .. import const from .. import const
@ -53,7 +54,17 @@ def _get_output_lines(script, log_file):
return screen.display return screen.display
def get_output(script, _): def get_output(script):
"""Reads script output from log.
:type script: str
:rtype: (str, str)
"""
if six.PY2:
warn('Experimental instant mode is Python 3+ only')
return None, None
if 'THEFUCK_OUTPUT_LOG' not in os.environ: if 'THEFUCK_OUTPUT_LOG' not in os.environ:
warn("Output log isn't specified") warn("Output log isn't specified")
return None, None return None, None

View File

@ -29,6 +29,13 @@ def _wait_output(popen, is_slow):
def get_output(script, expanded): def get_output(script, expanded):
"""Runs the script and obtains stdin/stderr.
:type script: str
:type expanded: str
:rtype: (str, str)
"""
env = dict(os.environ) env = dict(os.environ)
env.update(settings.env) env.update(settings.env)