mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-31 02:01:13 +00:00
Add python 2 support
This commit is contained in:
parent
282217fd02
commit
2eb777a5bb
@ -1,6 +1,8 @@
|
|||||||
language: python
|
language: python
|
||||||
python:
|
python:
|
||||||
- "3.4"
|
- "3.4"
|
||||||
|
- "3.3"
|
||||||
|
- "2.7"
|
||||||
install:
|
install:
|
||||||
- python setup.py develop
|
- python setup.py develop
|
||||||
- pip install -r requirements.txt
|
- pip install -r requirements.txt
|
||||||
|
@ -52,7 +52,7 @@ Did you mean this?
|
|||||||
Install `The Fuck`:
|
Install `The Fuck`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo pip3 install thefuck
|
sudo pip install thefuck
|
||||||
```
|
```
|
||||||
|
|
||||||
And add to `.bashrc` or `.zshrc`:
|
And add to `.bashrc` or `.zshrc`:
|
||||||
@ -66,8 +66,8 @@ alias fuck='$(thefuck $(fc -ln -1))'
|
|||||||
Install `The Fuck` for development:
|
Install `The Fuck` for development:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip3 install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
python3 setup.py develop
|
python setup.py develop
|
||||||
```
|
```
|
||||||
|
|
||||||
Run tests:
|
Run tests:
|
||||||
|
@ -1 +1,2 @@
|
|||||||
pytest
|
pytest
|
||||||
|
mock
|
||||||
|
1
setup.py
1
setup.py
@ -11,5 +11,6 @@ setup(name='thefuck',
|
|||||||
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
|
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
|
install_requires=['pathlib'],
|
||||||
entry_points={'console_scripts': [
|
entry_points={'console_scripts': [
|
||||||
'thefuck = thefuck.main:main']})
|
'thefuck = thefuck.main:main']})
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from unittest.mock import patch, Mock
|
|
||||||
import pytest
|
|
||||||
from subprocess import PIPE
|
from subprocess import PIPE
|
||||||
|
from mock import patch, Mock
|
||||||
|
import pytest
|
||||||
from thefuck.rules.no_command import match, get_new_command
|
from thefuck.rules.no_command import match, get_new_command
|
||||||
from thefuck.main import Command
|
from thefuck.main import Command
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from unittest.mock import patch, Mock
|
|
||||||
from subprocess import PIPE
|
from subprocess import PIPE
|
||||||
from pathlib import PosixPath, Path
|
from pathlib import PosixPath, Path
|
||||||
|
from mock import patch, Mock
|
||||||
from thefuck import main
|
from thefuck import main
|
||||||
|
|
||||||
|
|
||||||
|
0
thefuck/__init__.py
Normal file
0
thefuck/__init__.py
Normal file
@ -10,7 +10,7 @@ Command = namedtuple('Command', ('script', 'stdout', 'stderr'))
|
|||||||
Rule = namedtuple('Rule', ('match', 'get_new_command'))
|
Rule = namedtuple('Rule', ('match', 'get_new_command'))
|
||||||
|
|
||||||
|
|
||||||
def setup_user_dir() -> Path:
|
def setup_user_dir():
|
||||||
"""Returns user config dir, create it when it doesn't exists."""
|
"""Returns user config dir, create it when it doesn't exists."""
|
||||||
user_dir = Path(expanduser('~/.thefuck'))
|
user_dir = Path(expanduser('~/.thefuck'))
|
||||||
if not user_dir.is_dir():
|
if not user_dir.is_dir():
|
||||||
@ -20,7 +20,7 @@ def setup_user_dir() -> Path:
|
|||||||
return user_dir
|
return user_dir
|
||||||
|
|
||||||
|
|
||||||
def get_settings(user_dir: Path):
|
def get_settings(user_dir):
|
||||||
"""Returns prepared settings module."""
|
"""Returns prepared settings module."""
|
||||||
settings = load_source('settings',
|
settings = load_source('settings',
|
||||||
str(user_dir.joinpath('settings.py')))
|
str(user_dir.joinpath('settings.py')))
|
||||||
@ -29,7 +29,7 @@ def get_settings(user_dir: Path):
|
|||||||
return settings
|
return settings
|
||||||
|
|
||||||
|
|
||||||
def is_rule_enabled(settings, rule: Path) -> bool:
|
def is_rule_enabled(settings, rule):
|
||||||
"""Returns `True` when rule mentioned in `rules` or `rules`
|
"""Returns `True` when rule mentioned in `rules` or `rules`
|
||||||
isn't defined.
|
isn't defined.
|
||||||
|
|
||||||
@ -37,23 +37,23 @@ def is_rule_enabled(settings, rule: Path) -> bool:
|
|||||||
return settings.rules is None or rule.name[:-3] in settings.rules
|
return settings.rules is None or rule.name[:-3] in settings.rules
|
||||||
|
|
||||||
|
|
||||||
def load_rule(rule: Path) -> Rule:
|
def load_rule(rule):
|
||||||
"""Imports rule module and returns it."""
|
"""Imports rule module and returns it."""
|
||||||
rule_module = load_source(rule.name[:-3], str(rule))
|
rule_module = load_source(rule.name[:-3], str(rule))
|
||||||
return Rule(rule_module.match, rule_module.get_new_command)
|
return Rule(rule_module.match, rule_module.get_new_command)
|
||||||
|
|
||||||
|
|
||||||
def get_rules(user_dir: Path, settings) -> [Rule]:
|
def get_rules(user_dir, settings):
|
||||||
"""Returns all enabled rules."""
|
"""Returns all enabled rules."""
|
||||||
bundled = Path(__file__).parent\
|
bundled = Path(__file__).parent\
|
||||||
.joinpath('rules')\
|
.joinpath('rules')\
|
||||||
.glob('*.py')
|
.glob('*.py')
|
||||||
user = user_dir.joinpath('rules').glob('*.py')
|
user = user_dir.joinpath('rules').glob('*.py')
|
||||||
return [load_rule(rule) for rule in list(bundled) + list(user)
|
return [load_rule(rule) for rule in list(bundled) + list(user)
|
||||||
if is_rule_enabled(settings, rule)]
|
if rule.name != '__init__.py' and is_rule_enabled(settings, rule)]
|
||||||
|
|
||||||
|
|
||||||
def get_command(args: [str]) -> Command:
|
def get_command(args):
|
||||||
"""Creates command from `args` and executes it."""
|
"""Creates command from `args` and executes it."""
|
||||||
script = ' '.join(args[1:])
|
script = ' '.join(args[1:])
|
||||||
result = Popen(script, shell=True, stdout=PIPE, stderr=PIPE)
|
result = Popen(script, shell=True, stdout=PIPE, stderr=PIPE)
|
||||||
@ -61,14 +61,14 @@ def get_command(args: [str]) -> Command:
|
|||||||
result.stderr.read().decode())
|
result.stderr.read().decode())
|
||||||
|
|
||||||
|
|
||||||
def get_matched_rule(command: Command, rules: [Rule], settings) -> Rule:
|
def get_matched_rule(command, rules, settings):
|
||||||
"""Returns first matched rule for command."""
|
"""Returns first matched rule for command."""
|
||||||
for rule in rules:
|
for rule in rules:
|
||||||
if rule.match(command, settings):
|
if rule.match(command, settings):
|
||||||
return rule
|
return rule
|
||||||
|
|
||||||
|
|
||||||
def run_rule(rule: Rule, command: Command, settings):
|
def run_rule(rule, command, settings):
|
||||||
"""Runs command from rule for passed command."""
|
"""Runs command from rule for passed command."""
|
||||||
new_command = rule.get_new_command(command, settings)
|
new_command = rule.get_new_command(command, settings)
|
||||||
print(new_command)
|
print(new_command)
|
||||||
|
0
thefuck/rules/__init__.py
Normal file
0
thefuck/rules/__init__.py
Normal file
Loading…
x
Reference in New Issue
Block a user