diff --git a/setup.py b/setup.py index 6a62ff59..05d24ccb 100755 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ elif (3, 0) < version < (3, 3): VERSION = '3.9' install_requires = ['psutil', 'colorama', 'six', 'decorator'] -extras_require = {':python_version<"3.4"': ['pathlib'], +extras_require = {':python_version<"3.4"': ['pathlib2'], ":sys_platform=='win32'": ['win_unicode_console']} setup(name='thefuck', diff --git a/tests/conftest.py b/tests/conftest.py index c089af71..3dc24a29 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,7 @@ -from pathlib import Path +try: + from pathlib import Path +except ImportError: + from pathlib2 import Path import pytest from thefuck import shells from thefuck import conf, const diff --git a/tests/test_corrector.py b/tests/test_corrector.py index 164f61ff..6c44fdae 100644 --- a/tests/test_corrector.py +++ b/tests/test_corrector.py @@ -1,7 +1,12 @@ # -*- coding: utf-8 -*- import pytest -from pathlib import Path +try: + from pathlib import Path + pathlib_name = 'pathlib' +except ImportError: + from pathlib2 import Path + pathlib_name = 'pathlib2' from thefuck import corrector, const from tests.utils import Rule, Command, CorrectedCommand from thefuck.corrector import get_corrected_commands, organize_commands @@ -11,7 +16,7 @@ class TestGetRules(object): @pytest.fixture def glob(self, mocker): results = {} - mocker.patch('pathlib.Path.glob', + mocker.patch(pathlib_name + '.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 2909412e..366132e3 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -3,7 +3,10 @@ import os from subprocess import PIPE from mock import Mock -from pathlib import Path +try: + from pathlib import Path +except ImportError: + from pathlib2 import Path import pytest from tests.utils import CorrectedCommand, Rule, Command from thefuck import const diff --git a/thefuck/conf.py b/thefuck/conf.py index 8e1a2a94..755d3ff9 100644 --- a/thefuck/conf.py +++ b/thefuck/conf.py @@ -1,7 +1,10 @@ from imp import load_source import os import sys -from pathlib import Path +try: + from pathlib import Path +except ImportError: + from pathlib2 import Path from six import text_type from . import const diff --git a/thefuck/corrector.py b/thefuck/corrector.py index f08c7a74..5e65957a 100644 --- a/thefuck/corrector.py +++ b/thefuck/corrector.py @@ -1,4 +1,7 @@ -from pathlib import Path +try: + from pathlib import Path +except ImportError: + from pathlib2 import Path from .conf import settings from .types import Rule from . import logs diff --git a/thefuck/utils.py b/thefuck/utils.py index 1f9a4021..c5f12c68 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -10,7 +10,10 @@ from decorator import decorator from difflib import get_close_matches from functools import wraps from inspect import getargspec -from pathlib import Path +try: + from pathlib import Path +except ImportError: + from pathlib2 import Path from warnings import warn DEVNULL = open(os.devnull, 'w')