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