diff --git a/tests/conftest.py b/tests/conftest.py index 3dc24a29..caeb0cad 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,10 +1,7 @@ -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path import pytest from thefuck import shells from thefuck import conf, const +from thefuck.utils import Path shells.shell = shells.Generic() diff --git a/tests/test_corrector.py b/tests/test_corrector.py index 6c44fdae..207a5f54 100644 --- a/tests/test_corrector.py +++ b/tests/test_corrector.py @@ -1,13 +1,8 @@ # -*- coding: utf-8 -*- import pytest -try: - from pathlib import Path - pathlib_name = 'pathlib' -except ImportError: - from pathlib2 import Path - pathlib_name = 'pathlib2' from thefuck import corrector, const +from thefuck.utils import Path from tests.utils import Rule, Command, CorrectedCommand from thefuck.corrector import get_corrected_commands, organize_commands @@ -16,7 +11,7 @@ class TestGetRules(object): @pytest.fixture def glob(self, mocker): results = {} - mocker.patch(pathlib_name + '.Path.glob', + mocker.patch('thefuck.utils.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 366132e3..3b584373 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -3,14 +3,11 @@ import os from subprocess import PIPE from mock import Mock -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path import pytest from tests.utils import CorrectedCommand, Rule, Command from thefuck import const from thefuck.exceptions import EmptyCommand +from thefuck.utils import Path class TestCorrectedCommand(object): diff --git a/thefuck/conf.py b/thefuck/conf.py index 5ae87d3a..b77319a3 100644 --- a/thefuck/conf.py +++ b/thefuck/conf.py @@ -1,12 +1,9 @@ from imp import load_source import os import sys -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path from six import text_type from . import const +from .utils import Path class Settings(dict): @@ -43,14 +40,13 @@ class Settings(dict): def _get_user_dir_path(self): # for backward compatibility, use `~/.thefuck` if it exists - legacy_user_dir = Path(os.path.expanduser('~/.thefuck')) + legacy_user_dir = Path('~/.thefuck').expanduser() if legacy_user_dir.is_dir(): return legacy_user_dir else: - default_xdg_config_dir = os.path.expanduser("~/.config") - xdg_config_dir = os.getenv("XDG_CONFIG_HOME", default_xdg_config_dir) - return Path(os.path.join(xdg_config_dir, 'thefuck')) + xdg_config_dir = os.getenv("XDG_CONFIG_HOME", "~/.config") + return Path(xdg_config_dir).joinpath('thefuck') def _setup_user_dir(self): """Returns user config dir, create it when it doesn't exist.""" diff --git a/thefuck/corrector.py b/thefuck/corrector.py index 5e65957a..c1e7d676 100644 --- a/thefuck/corrector.py +++ b/thefuck/corrector.py @@ -1,9 +1,6 @@ -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path from .conf import settings from .types import Rule +from .utils import Path from . import logs diff --git a/thefuck/rules/workon_doesnt_exists.py b/thefuck/rules/workon_doesnt_exists.py index e8c4df0d..59447656 100644 --- a/thefuck/rules/workon_doesnt_exists.py +++ b/thefuck/rules/workon_doesnt_exists.py @@ -1,9 +1,4 @@ -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path - -from thefuck.utils import for_app, replace_command, eager, memoize +from thefuck.utils import for_app, replace_command, eager, memoize, Path @memoize diff --git a/thefuck/utils.py b/thefuck/utils.py index f36a5e66..c87bdebd 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -4,16 +4,16 @@ import pkg_resources import re import shelve import six -from .conf import settings from contextlib import closing 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 warnings import warn DEVNULL = open(os.devnull, 'w') @@ -81,6 +81,8 @@ 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)