##// END OF EJS Templates
MAINT: deprecate append_to_syspath
Matthias Bussonnier -
Show More
@@ -0,0 +1,7 b''
1 from IPython.utils.syspathcontext import appended_to_syspath
2 import pytest
3
4
5 def test_append_deprecated():
6 with pytest.warns(DeprecationWarning):
7 appended_to_syspath(".")
@@ -1,62 +1,71 b''
1 # encoding: utf-8
1 # encoding: utf-8
2 """
2 """
3 Context managers for adding things to sys.path temporarily.
3 Context managers for adding things to sys.path temporarily.
4
4
5 Authors:
5 Authors:
6
6
7 * Brian Granger
7 * Brian Granger
8 """
8 """
9
9
10 #-----------------------------------------------------------------------------
10 #-----------------------------------------------------------------------------
11 # Copyright (C) 2008-2011 The IPython Development Team
11 # Copyright (C) 2008-2011 The IPython Development Team
12 #
12 #
13 # Distributed under the terms of the BSD License. The full license is in
13 # Distributed under the terms of the BSD License. The full license is in
14 # the file COPYING, distributed as part of this software.
14 # the file COPYING, distributed as part of this software.
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16
16
17 import sys
17 import sys
18 import warnings
18
19
19
20
20 class appended_to_syspath(object):
21 class appended_to_syspath(object):
21 """A context for appending a directory to sys.path for a second."""
22 """
23 Deprecated since IPython 8.1, no replacements.
24
25 A context for appending a directory to sys.path for a second."""
22
26
23 def __init__(self, dir):
27 def __init__(self, dir):
28 warnings.warn(
29 "`appended_to_syspath` is deprecated since IPython 8.1, and has no replacements",
30 DeprecationWarning,
31 stacklevel=2,
32 )
24 self.dir = dir
33 self.dir = dir
25
34
26 def __enter__(self):
35 def __enter__(self):
27 if self.dir not in sys.path:
36 if self.dir not in sys.path:
28 sys.path.append(self.dir)
37 sys.path.append(self.dir)
29 self.added = True
38 self.added = True
30 else:
39 else:
31 self.added = False
40 self.added = False
32
41
33 def __exit__(self, type, value, traceback):
42 def __exit__(self, type, value, traceback):
34 if self.added:
43 if self.added:
35 try:
44 try:
36 sys.path.remove(self.dir)
45 sys.path.remove(self.dir)
37 except ValueError:
46 except ValueError:
38 pass
47 pass
39 # Returning False causes any exceptions to be re-raised.
48 # Returning False causes any exceptions to be re-raised.
40 return False
49 return False
41
50
42 class prepended_to_syspath(object):
51 class prepended_to_syspath(object):
43 """A context for prepending a directory to sys.path for a second."""
52 """A context for prepending a directory to sys.path for a second."""
44
53
45 def __init__(self, dir):
54 def __init__(self, dir):
46 self.dir = dir
55 self.dir = dir
47
56
48 def __enter__(self):
57 def __enter__(self):
49 if self.dir not in sys.path:
58 if self.dir not in sys.path:
50 sys.path.insert(0,self.dir)
59 sys.path.insert(0,self.dir)
51 self.added = True
60 self.added = True
52 else:
61 else:
53 self.added = False
62 self.added = False
54
63
55 def __exit__(self, type, value, traceback):
64 def __exit__(self, type, value, traceback):
56 if self.added:
65 if self.added:
57 try:
66 try:
58 sys.path.remove(self.dir)
67 sys.path.remove(self.dir)
59 except ValueError:
68 except ValueError:
60 pass
69 pass
61 # Returning False causes any exceptions to be re-raised.
70 # Returning False causes any exceptions to be re-raised.
62 return False
71 return False
@@ -1,40 +1,43 b''
1 # encoding: utf-8
1 # encoding: utf-8
2 """
2 """
3 Utilities for version comparison
3 Utilities for version comparison
4
4
5 It is a bit ridiculous that we need these.
5 It is a bit ridiculous that we need these.
6 """
6 """
7
7
8 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2013 The IPython Development Team
9 # Copyright (C) 2013 The IPython Development Team
10 #
10 #
11 # Distributed under the terms of the BSD License. The full license is in
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 from warnings import warn
15 from warnings import warn
16
16
17 warn("The `IPython.utils.version` module has been deprecated since IPython 8.0.")
17 warn(
18 "The `IPython.utils.version` module has been deprecated since IPython 8.0.",
19 DeprecationWarning,
20 )
18
21
19
22
20 def check_version(v, check):
23 def check_version(v, check):
21 """check version string v >= check
24 """check version string v >= check
22
25
23 If dev/prerelease tags result in TypeError for string-number comparison,
26 If dev/prerelease tags result in TypeError for string-number comparison,
24 it is assumed that the dependency is satisfied.
27 it is assumed that the dependency is satisfied.
25 Users on dev branches are responsible for keeping their own packages up to date.
28 Users on dev branches are responsible for keeping their own packages up to date.
26 """
29 """
27 warn(
30 warn(
28 "`check_version` function is deprecated as of IPython 8.0"
31 "`check_version` function is deprecated as of IPython 8.0"
29 "and will be removed in future versions.",
32 "and will be removed in future versions.",
30 DeprecationWarning,
33 DeprecationWarning,
31 stacklevel=2,
34 stacklevel=2,
32 )
35 )
33
36
34 from distutils.version import LooseVersion
37 from distutils.version import LooseVersion
35
38
36 try:
39 try:
37 return LooseVersion(v) >= LooseVersion(check)
40 return LooseVersion(v) >= LooseVersion(check)
38 except TypeError:
41 except TypeError:
39 return True
42 return True
40
43
General Comments 0
You need to be logged in to leave comments. Login now