diff --git a/IPython/utils/tests/test_text.py b/IPython/utils/tests/test_text.py index fd2c64f..57171a9 100644 --- a/IPython/utils/tests/test_text.py +++ b/IPython/utils/tests/test_text.py @@ -19,7 +19,11 @@ import random import sys import nose.tools as nt -import path +try: + from pathlib import Path +except ImportError: + # Python 2 backport + from pathlib2 import Path from IPython.utils import text @@ -207,7 +211,7 @@ def test_LSString(): nt.assert_equal(lss.l, ['abc', 'def']) nt.assert_equal(lss.s, 'abc def') lss = text.LSString(os.getcwd()) - nt.assert_is_instance(lss.p[0], path.path) + nt.assert_is_instance(lss.p[0], Path) def test_SList(): sl = text.SList(['a 11', 'b 1', 'a 2']) diff --git a/IPython/utils/text.py b/IPython/utils/text.py index 6766abb..5ed1a84 100644 --- a/IPython/utils/text.py +++ b/IPython/utils/text.py @@ -14,6 +14,11 @@ import re import sys import textwrap from string import Formatter +try: + from pathlib import Path +except ImportError: + # Python 2 backport + from pathlib2 import Path from IPython.testing.skipdoctest import skip_doctest_py3, skip_doctest from IPython.utils import py3compat @@ -64,11 +69,10 @@ class LSString(str): n = nlstr = property(get_nlstr) def get_paths(self): - from path import path try: return self.__paths except AttributeError: - self.__paths = [path(p) for p in self.split('\n') if os.path.exists(p)] + self.__paths = [Path(p) for p in self.split('\n') if os.path.exists(p)] return self.__paths p = paths = property(get_paths) @@ -123,11 +127,10 @@ class SList(list): n = nlstr = property(get_nlstr) def get_paths(self): - from path import path try: return self.__paths except AttributeError: - self.__paths = [path(p) for p in self if os.path.exists(p)] + self.__paths = [Path(p) for p in self if os.path.exists(p)] return self.__paths p = paths = property(get_paths) diff --git a/setup.py b/setup.py index 04e4149..7fae9ef 100755 --- a/setup.py +++ b/setup.py @@ -182,7 +182,7 @@ extras_require = dict( parallel = ['ipyparallel'], qtconsole = ['qtconsole'], doc = ['Sphinx>=1.3'], - test = ['nose>=0.10.1', 'requests', 'testpath', 'pygments', 'path.py'], + test = ['nose>=0.10.1', 'requests', 'testpath', 'pygments'], terminal = [], kernel = ['ipykernel'], nbformat = ['nbformat'], @@ -205,6 +205,7 @@ install_requires = [ # but requires pip >= 6. pip < 6 ignores these. extras_require.update({ + ':python_version == "2.7" or python_version == "3.3"': ['pathlib2'], ':sys_platform != "win32"': ['pexpect'], ':sys_platform == "darwin"': ['appnope'], ':sys_platform == "win32"': ['colorama'],