diff --git a/tests/conftest.py b/tests/conftest.py index caeb0cad..ce4d23ce 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,7 +1,7 @@ import pytest from thefuck import shells from thefuck import conf, const -from thefuck.utils import Path +from thefuck.system import Path shells.shell = shells.Generic() diff --git a/tests/test_corrector.py b/tests/test_corrector.py index 207a5f54..08e4160e 100644 --- a/tests/test_corrector.py +++ b/tests/test_corrector.py @@ -2,7 +2,7 @@ import pytest from thefuck import corrector, const -from thefuck.utils import Path +from thefuck.system import Path from tests.utils import Rule, Command, CorrectedCommand from thefuck.corrector import get_corrected_commands, organize_commands @@ -11,7 +11,7 @@ class TestGetRules(object): @pytest.fixture def glob(self, mocker): results = {} - mocker.patch('thefuck.utils.Path.glob', + mocker.patch('thefuck.system.Path.glob', new_callable=lambda: lambda *_: results.pop('value', [])) return lambda value: results.update({'value': value}) diff --git a/tests/test_types.py b/tests/test_types.py index 3b584373..9cb951ba 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -7,7 +7,7 @@ import pytest from tests.utils import CorrectedCommand, Rule, Command from thefuck import const from thefuck.exceptions import EmptyCommand -from thefuck.utils import Path +from thefuck.system import Path class TestCorrectedCommand(object): diff --git a/thefuck/conf.py b/thefuck/conf.py index b77319a3..a3467b68 100644 --- a/thefuck/conf.py +++ b/thefuck/conf.py @@ -3,7 +3,7 @@ import os import sys from six import text_type from . import const -from .utils import Path +from .system import Path class Settings(dict): diff --git a/thefuck/corrector.py b/thefuck/corrector.py index c1e7d676..42df2ea5 100644 --- a/thefuck/corrector.py +++ b/thefuck/corrector.py @@ -1,6 +1,6 @@ from .conf import settings from .types import Rule -from .utils import Path +from .system import Path from . import logs diff --git a/thefuck/rules/workon_doesnt_exists.py b/thefuck/rules/workon_doesnt_exists.py index 59447656..6c97ce49 100644 --- a/thefuck/rules/workon_doesnt_exists.py +++ b/thefuck/rules/workon_doesnt_exists.py @@ -1,4 +1,5 @@ -from thefuck.utils import for_app, replace_command, eager, memoize, Path +from thefuck.utils import for_app, replace_command, eager, memoize +from thefuck.system import Path @memoize diff --git a/thefuck/system/unix.py b/thefuck/system/unix.py index 4d0b8555..cc6ff570 100644 --- a/thefuck/system/unix.py +++ b/thefuck/system/unix.py @@ -33,3 +33,8 @@ def get_key(): return const.KEY_DOWN return ch + +try: + from pathlib import Path +except ImportError: + from pathlib2 import Path diff --git a/thefuck/system/win32.py b/thefuck/system/win32.py index a8b6c0a4..5e49ff6e 100644 --- a/thefuck/system/win32.py +++ b/thefuck/system/win32.py @@ -25,3 +25,15 @@ def get_key(): encoding = sys.stdout.encoding or os.environ.get('PYTHONIOENCODING', 'utf-8') return ch.decode(encoding) + +try: + from pathlib import Path +except ImportError: + from pathlib2 import Path + + +def _expanduser(self): + return self.__class__(os.path.expanduser(str(self))) + +# pathlib's expanduser fails on windows, see http://bugs.python.org/issue19776 +Path.expanduser = _expanduser diff --git a/thefuck/utils.py b/thefuck/utils.py index c87bdebd..b5680351 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -9,11 +9,8 @@ from decorator import decorator from difflib import get_close_matches from functools import wraps from warnings import warn - -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from .conf import settings +from .system import Path DEVNULL = open(os.devnull, 'w') @@ -81,8 +78,6 @@ def default_settings(params): print(settings.apt) """ - from .conf import settings - def _default_settings(fn, command): for k, w in params.items(): settings.setdefault(k, w)