mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 20:11:17 +00:00
Minor refactoring
This commit is contained in:
parent
1173f9f59c
commit
b8ce95ad68
@ -41,3 +41,8 @@ def functional(request):
|
|||||||
if request.node.get_marker('functional') \
|
if request.node.get_marker('functional') \
|
||||||
and not request.config.getoption('enable_functional'):
|
and not request.config.getoption('enable_functional'):
|
||||||
pytest.skip('functional tests are disabled')
|
pytest.skip('functional tests are disabled')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def source_root():
|
||||||
|
return Path(__file__).parent.parent.resolve()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from thefuck.main import _get_current_version
|
from thefuck.utils import get_installation_info
|
||||||
|
|
||||||
envs = ((u'bash', 'thefuck/ubuntu-bash', u'''
|
envs = ((u'bash', 'thefuck/ubuntu-bash', u'''
|
||||||
FROM ubuntu:latest
|
FROM ubuntu:latest
|
||||||
@ -18,7 +18,8 @@ def test_installation(spawnu, shell, TIMEOUT, tag, dockerfile):
|
|||||||
proc = spawnu(tag, dockerfile, shell)
|
proc = spawnu(tag, dockerfile, shell)
|
||||||
proc.sendline(u'cat /src/install.sh | sh - && $0')
|
proc.sendline(u'cat /src/install.sh | sh - && $0')
|
||||||
proc.sendline(u'thefuck --version')
|
proc.sendline(u'thefuck --version')
|
||||||
assert proc.expect([TIMEOUT, u'thefuck {}'.format(_get_current_version())],
|
version = get_installation_info().version
|
||||||
|
assert proc.expect([TIMEOUT, u'thefuck {}'.format(version)],
|
||||||
timeout=600)
|
timeout=600)
|
||||||
proc.sendline(u'fuck')
|
proc.sendline(u'fuck')
|
||||||
assert proc.expect([TIMEOUT, u'No fucks given'])
|
assert proc.expect([TIMEOUT, u'No fucks given'])
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
from tests.utils import root
|
def test_readme(source_root):
|
||||||
|
with source_root.joinpath('README.md').open() as f:
|
||||||
|
|
||||||
def test_readme():
|
|
||||||
with root.joinpath('README.md').open() as f:
|
|
||||||
readme = f.read()
|
readme = f.read()
|
||||||
|
|
||||||
bundled = root \
|
bundled = source_root.joinpath('thefuck') \
|
||||||
.joinpath('thefuck') \
|
|
||||||
.joinpath('rules') \
|
.joinpath('rules') \
|
||||||
.glob('*.py')
|
.glob('*.py')
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
from pathlib import Path
|
|
||||||
from thefuck import types
|
from thefuck import types
|
||||||
from thefuck.conf import DEFAULT_PRIORITY
|
from thefuck.conf import DEFAULT_PRIORITY
|
||||||
|
|
||||||
@ -24,6 +23,3 @@ class CorrectedCommand(types.CorrectedCommand):
|
|||||||
def __init__(self, script='', side_effect=None, priority=DEFAULT_PRIORITY):
|
def __init__(self, script='', side_effect=None, priority=DEFAULT_PRIORITY):
|
||||||
super(CorrectedCommand, self).__init__(
|
super(CorrectedCommand, self).__init__(
|
||||||
script, side_effect, priority)
|
script, side_effect, priority)
|
||||||
|
|
||||||
|
|
||||||
root = Path(__file__).parent.parent.resolve()
|
|
||||||
|
@ -1,2 +1,6 @@
|
|||||||
class EmptyCommand(Exception):
|
class EmptyCommand(Exception):
|
||||||
"""Raises when empty command passed to `thefuck`."""
|
"""Raised when empty command passed to `thefuck`."""
|
||||||
|
|
||||||
|
|
||||||
|
class NoRuleMatched(Exception):
|
||||||
|
"""Raised when no rule matched for some command."""
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from warnings import warn
|
from warnings import warn
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
import pkg_resources
|
|
||||||
import sys
|
import sys
|
||||||
import colorama
|
import colorama
|
||||||
from . import logs, types, shells
|
from . import logs, types, shells
|
||||||
from .conf import settings
|
from .conf import settings
|
||||||
from .corrector import get_corrected_commands
|
from .corrector import get_corrected_commands
|
||||||
from .exceptions import EmptyCommand
|
from .exceptions import EmptyCommand
|
||||||
|
from .utils import get_installation_info
|
||||||
from .ui import select_command
|
from .ui import select_command
|
||||||
|
|
||||||
|
|
||||||
def fix_command():
|
def fix_command():
|
||||||
|
"""Fixes previous command. Used when `thefuck` called without arguments."""
|
||||||
colorama.init()
|
colorama.init()
|
||||||
settings.init()
|
settings.init()
|
||||||
with logs.debug_time('Total'):
|
with logs.debug_time('Total'):
|
||||||
@ -29,11 +30,8 @@ def fix_command():
|
|||||||
selected_command.run(command)
|
selected_command.run(command)
|
||||||
|
|
||||||
|
|
||||||
def _get_current_version():
|
|
||||||
return pkg_resources.require('thefuck')[0].version
|
|
||||||
|
|
||||||
|
|
||||||
def print_alias(entry_point=True):
|
def print_alias(entry_point=True):
|
||||||
|
"""Prints alias for current shell."""
|
||||||
if entry_point:
|
if entry_point:
|
||||||
warn('`thefuck-alias` is deprecated, use `thefuck --alias` instead.')
|
warn('`thefuck-alias` is deprecated, use `thefuck --alias` instead.')
|
||||||
position = 1
|
position = 1
|
||||||
@ -59,9 +57,10 @@ def how_to_configure_alias():
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = ArgumentParser(prog='thefuck')
|
parser = ArgumentParser(prog='thefuck')
|
||||||
|
version = get_installation_info().version
|
||||||
parser.add_argument('-v', '--version',
|
parser.add_argument('-v', '--version',
|
||||||
action='version',
|
action='version',
|
||||||
version='%(prog)s {}'.format(_get_current_version()))
|
version='%(prog)s {}'.format(version))
|
||||||
parser.add_argument('-a', '--alias',
|
parser.add_argument('-a', '--alias',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='[custom-alias-name] prints alias for current shell')
|
help='[custom-alias-name] prints alias for current shell')
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
from .conf import settings
|
from .conf import settings
|
||||||
|
from .exceptions import NoRuleMatched
|
||||||
from . import logs
|
from . import logs
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -54,7 +55,10 @@ class CommandSelector(object):
|
|||||||
|
|
||||||
def __init__(self, commands):
|
def __init__(self, commands):
|
||||||
self._commands_gen = commands
|
self._commands_gen = commands
|
||||||
|
try:
|
||||||
self._commands = [next(self._commands_gen)]
|
self._commands = [next(self._commands_gen)]
|
||||||
|
except StopIteration:
|
||||||
|
raise NoRuleMatched
|
||||||
self._realised = False
|
self._realised = False
|
||||||
self._index = 0
|
self._index = 0
|
||||||
|
|
||||||
@ -86,7 +90,7 @@ def select_command(corrected_commands):
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
selector = CommandSelector(corrected_commands)
|
selector = CommandSelector(corrected_commands)
|
||||||
except StopIteration:
|
except NoRuleMatched:
|
||||||
logs.failed('No fucks given')
|
logs.failed('No fucks given')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import shelve
|
|||||||
from warnings import warn
|
from warnings import warn
|
||||||
from decorator import decorator
|
from decorator import decorator
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
import tempfile
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import pickle
|
import pickle
|
||||||
@ -99,8 +98,7 @@ def get_all_executables():
|
|||||||
return fallback
|
return fallback
|
||||||
|
|
||||||
tf_alias = thefuck_alias()
|
tf_alias = thefuck_alias()
|
||||||
tf_entry_points = pkg_resources.require('thefuck')[0]\
|
tf_entry_points = get_installation_info().get_entry_map()\
|
||||||
.get_entry_map()\
|
|
||||||
.get('console_scripts', {})\
|
.get('console_scripts', {})\
|
||||||
.keys()
|
.keys()
|
||||||
bins = [exe.name
|
bins = [exe.name
|
||||||
@ -224,3 +222,7 @@ def compatibility_call(fn, *args):
|
|||||||
.format(fn.__name__, fn.__module__))
|
.format(fn.__name__, fn.__module__))
|
||||||
args += (settings,)
|
args += (settings,)
|
||||||
return fn(*args)
|
return fn(*args)
|
||||||
|
|
||||||
|
|
||||||
|
def get_installation_info():
|
||||||
|
return pkg_resources.require('thefuck')[0]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user